From 793ee0531730597e6008c9c0dedabbab7a2bef53 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Wed, 21 Aug 2024 13:46:25 -0300 Subject: [PATCH] fix(core): allow hyphens and underscores on identifiers, closes #9707 (#10700) * fix(core): allow hyphens and underscores on identifiers, closes #9707 * fix build * fix build * lint * move replace * update tao * update tao-macros --- .changes/mobile-identifier.md | 8 ++++++ Cargo.lock | 10 +++---- core/tauri-build/src/lib.rs | 7 +++-- core/tauri-macros/src/mobile.rs | 23 +++------------- core/tauri-runtime-wry/Cargo.toml | 2 +- examples/api/src-tauri/Cargo.lock | 26 +++++++++---------- tooling/cli/Cargo.lock | 4 +-- tooling/cli/Cargo.toml | 2 +- .../mobile/android/android_studio_script.rs | 6 ++++- tooling/cli/src/mobile/android/build.rs | 2 +- tooling/cli/src/mobile/android/dev.rs | 2 +- tooling/cli/src/mobile/init.rs | 6 ++++- tooling/cli/src/mobile/ios/build.rs | 2 +- tooling/cli/src/mobile/ios/dev.rs | 2 +- tooling/cli/src/mobile/ios/xcode_script.rs | 6 ++++- tooling/cli/src/mobile/mod.rs | 12 ++++++--- 16 files changed, 67 insertions(+), 53 deletions(-) create mode 100644 .changes/mobile-identifier.md diff --git a/.changes/mobile-identifier.md b/.changes/mobile-identifier.md new file mode 100644 index 000000000..9e8dbf301 --- /dev/null +++ b/.changes/mobile-identifier.md @@ -0,0 +1,8 @@ +--- +"tauri-cli": patch:bug +"tauri-build": patch:bug +"@tauri-apps/cli": patch:bug +"tauri-runtime-wry": patch:bug +--- + +Allow hyphens and underscores on app identifiers. diff --git a/Cargo.lock b/Cargo.lock index c91439cc5..3f4f5c334 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3735,9 +3735,9 @@ dependencies = [ [[package]] name = "tao" -version = "0.29.0" +version = "0.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6775bcf3c1da33f848ede9cff5883ed1e45a29f66533ce42ad06c93ae514ed59" +checksum = "d3a97abbc7d6cfd0720da3e06fcb1cf2ac87cbfdb5bbbce103a1279a211c4d81" dependencies = [ "bitflags 2.5.0", "cocoa 0.26.0", @@ -3774,13 +3774,13 @@ dependencies = [ [[package]] name = "tao-macros" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec114582505d158b669b136e6851f85840c109819d77c42bb7c0709f727d18c2" +checksum = "f4e16beb8b2ac17db28eab8bca40e62dbfbb34c0fcdc6d9826b11b7b5d047dfd" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.74", ] [[package]] diff --git a/core/tauri-build/src/lib.rs b/core/tauri-build/src/lib.rs index 57b63b0f3..8bfef91d9 100644 --- a/core/tauri-build/src/lib.rs +++ b/core/tauri-build/src/lib.rs @@ -476,9 +476,12 @@ pub fn try_build(attributes: Attributes) -> Result<()> { let mut android_package_prefix = String::new(); for (i, w) in s.enumerate() { if i == last { - println!("cargo:rustc-env=TAURI_ANDROID_PACKAGE_NAME_APP_NAME={w}"); + println!( + "cargo:rustc-env=TAURI_ANDROID_PACKAGE_NAME_APP_NAME={}", + w.replace('-', "_") + ); } else { - android_package_prefix.push_str(w); + android_package_prefix.push_str(&w.replace(['_', '-'], "_1")); android_package_prefix.push('_'); } } diff --git a/core/tauri-macros/src/mobile.rs b/core/tauri-macros/src/mobile.rs index 09e9af1f0..9ec2b6d94 100644 --- a/core/tauri-macros/src/mobile.rs +++ b/core/tauri-macros/src/mobile.rs @@ -8,15 +8,10 @@ use quote::{format_ident, quote}; use std::env::var; use syn::{parse_macro_input, spanned::Spanned, ItemFn}; -fn get_env_var String>( - name: &str, - replacer: R, - error: &mut Option, - function: &ItemFn, -) -> TokenStream2 { +fn get_env_var(name: &str, error: &mut Option, function: &ItemFn) -> TokenStream2 { match var(name) { Ok(value) => { - let ident = format_ident!("{}", replacer(value)); + let ident = format_ident!("{value}"); quote!(#ident) } Err(_) => { @@ -37,18 +32,8 @@ pub fn entry_point(_attributes: TokenStream, item: TokenStream) -> TokenStream { let function_name = &function.sig.ident; let mut error = None; - let domain = get_env_var( - "TAURI_ANDROID_PACKAGE_NAME_PREFIX", - |r| r, - &mut error, - &function, - ); - let app_name = get_env_var( - "TAURI_ANDROID_PACKAGE_NAME_APP_NAME", - |r| r.replace('-', "_"), - &mut error, - &function, - ); + let domain = get_env_var("TAURI_ANDROID_PACKAGE_NAME_PREFIX", &mut error, &function); + let app_name = get_env_var("TAURI_ANDROID_PACKAGE_NAME_APP_NAME", &mut error, &function); if let Some(e) = error { quote!(#e).into() diff --git a/core/tauri-runtime-wry/Cargo.toml b/core/tauri-runtime-wry/Cargo.toml index 335b02f4b..db39f9314 100644 --- a/core/tauri-runtime-wry/Cargo.toml +++ b/core/tauri-runtime-wry/Cargo.toml @@ -18,7 +18,7 @@ rustdoc-args = [ "--cfg", "docsrs" ] [dependencies] wry = { version = "0.42", default-features = false, features = [ "drag-drop", "protocol", "os-webview" ] } -tao = { version = "0.29", default-features = false, features = [ "rwh_06" ] } +tao = { version = "0.29.1", default-features = false, features = [ "rwh_06" ] } tauri-runtime = { version = "2.0.0-rc.5", path = "../tauri-runtime" } tauri-utils = { version = "2.0.0-rc.5", path = "../tauri-utils" } raw-window-handle = "0.6" diff --git a/examples/api/src-tauri/Cargo.lock b/examples/api/src-tauri/Cargo.lock index 8273f8e98..5bc00e998 100644 --- a/examples/api/src-tauri/Cargo.lock +++ b/examples/api/src-tauri/Cargo.lock @@ -3165,9 +3165,9 @@ dependencies = [ [[package]] name = "tao" -version = "0.29.0" +version = "0.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6775bcf3c1da33f848ede9cff5883ed1e45a29f66533ce42ad06c93ae514ed59" +checksum = "d3a97abbc7d6cfd0720da3e06fcb1cf2ac87cbfdb5bbbce103a1279a211c4d81" dependencies = [ "bitflags 2.5.0", "cocoa 0.26.0", @@ -3204,13 +3204,13 @@ dependencies = [ [[package]] name = "tao-macros" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec114582505d158b669b136e6851f85840c109819d77c42bb7c0709f727d18c2" +checksum = "f4e16beb8b2ac17db28eab8bca40e62dbfbb34c0fcdc6d9826b11b7b5d047dfd" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.63", ] [[package]] @@ -3221,7 +3221,7 @@ checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f" [[package]] name = "tauri" -version = "2.0.0-rc.4" +version = "2.0.0-rc.5" dependencies = [ "anyhow", "bytes", @@ -3271,7 +3271,7 @@ dependencies = [ [[package]] name = "tauri-build" -version = "2.0.0-rc.4" +version = "2.0.0-rc.5" dependencies = [ "anyhow", "cargo_toml", @@ -3293,7 +3293,7 @@ dependencies = [ [[package]] name = "tauri-codegen" -version = "2.0.0-rc.4" +version = "2.0.0-rc.5" dependencies = [ "base64 0.22.1", "brotli", @@ -3318,7 +3318,7 @@ dependencies = [ [[package]] name = "tauri-macros" -version = "2.0.0-rc.4" +version = "2.0.0-rc.5" dependencies = [ "heck 0.5.0", "proc-macro2", @@ -3330,7 +3330,7 @@ dependencies = [ [[package]] name = "tauri-plugin" -version = "2.0.0-rc.4" +version = "2.0.0-rc.5" dependencies = [ "anyhow", "glob", @@ -3356,7 +3356,7 @@ dependencies = [ [[package]] name = "tauri-runtime" -version = "2.0.0-rc.4" +version = "2.0.0-rc.5" dependencies = [ "dpi", "gtk", @@ -3373,7 +3373,7 @@ dependencies = [ [[package]] name = "tauri-runtime-wry" -version = "2.0.0-rc.4" +version = "2.0.0-rc.5" dependencies = [ "cocoa 0.26.0", "gtk", @@ -3395,7 +3395,7 @@ dependencies = [ [[package]] name = "tauri-utils" -version = "2.0.0-rc.4" +version = "2.0.0-rc.5" dependencies = [ "aes-gcm", "brotli", diff --git a/tooling/cli/Cargo.lock b/tooling/cli/Cargo.lock index 6a75a643f..1165247f5 100644 --- a/tooling/cli/Cargo.lock +++ b/tooling/cli/Cargo.lock @@ -557,9 +557,9 @@ dependencies = [ [[package]] name = "cargo-mobile2" -version = "0.13.4" +version = "0.13.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8dd9a8451eeeb998885ec3acb08b9bd32353ccd119b18db5ae6ddc41814fc03" +checksum = "76bd9e694230d442d680f8e578b4f252c67adbfd74cc1dd1caa9e1f1767114dc" dependencies = [ "colored", "core-foundation 0.10.0", diff --git a/tooling/cli/Cargo.toml b/tooling/cli/Cargo.toml index c2c7d50c1..417d771e9 100644 --- a/tooling/cli/Cargo.toml +++ b/tooling/cli/Cargo.toml @@ -39,7 +39,7 @@ name = "cargo-tauri" path = "src/main.rs" [dependencies] -cargo-mobile2 = { version = "0.13.4", default-features = false } +cargo-mobile2 = { version = "0.13.5", default-features = false } jsonrpsee = { version = "0.24", features = [ "server" ] } jsonrpsee-core = "0.24" jsonrpsee-client-transport = { version = "0.24", features = [ "ws" ] } diff --git a/tooling/cli/src/mobile/android/android_studio_script.rs b/tooling/cli/src/mobile/android/android_studio_script.rs index 407a78d96..08e8ae2dd 100644 --- a/tooling/cli/src/mobile/android/android_studio_script.rs +++ b/tooling/cli/src/mobile/android/android_studio_script.rs @@ -52,7 +52,11 @@ pub fn command(options: Options) -> Result<()> { let tauri_config_ = tauri_config_guard.as_ref().unwrap(); let cli_options = read_options(&tauri_config_.identifier); let (config, metadata) = get_config( - &get_app(tauri_config_, &AppInterface::new(tauri_config_, None)?), + &get_app( + MobileTarget::Android, + tauri_config_, + &AppInterface::new(tauri_config_, None)?, + ), tauri_config_, None, &cli_options, diff --git a/tooling/cli/src/mobile/android/build.rs b/tooling/cli/src/mobile/android/build.rs index 557f4e1a8..7ae09c23d 100644 --- a/tooling/cli/src/mobile/android/build.rs +++ b/tooling/cli/src/mobile/android/build.rs @@ -114,7 +114,7 @@ pub fn command(options: Options, noise_level: NoiseLevel) -> Result<()> { let interface = AppInterface::new(tauri_config_, build_options.target.clone())?; interface.build_options(&mut Vec::new(), &mut build_options.features, true); - let app = get_app(tauri_config_, &interface); + let app = get_app(MobileTarget::Android, tauri_config_, &interface); let (config, metadata) = get_config( &app, tauri_config_, diff --git a/tooling/cli/src/mobile/android/dev.rs b/tooling/cli/src/mobile/android/dev.rs index 89b666127..ddb2c7069 100644 --- a/tooling/cli/src/mobile/android/dev.rs +++ b/tooling/cli/src/mobile/android/dev.rs @@ -134,7 +134,7 @@ fn run_command(options: Options, noise_level: NoiseLevel) -> Result<()> { let interface = AppInterface::new(tauri_config_, dev_options.target.clone())?; - let app = get_app(tauri_config_, &interface); + let app = get_app(MobileTarget::Android, tauri_config_, &interface); let (config, metadata) = get_config( &app, tauri_config_, diff --git a/tooling/cli/src/mobile/init.rs b/tooling/cli/src/mobile/init.rs index 891aa9162..266bb310b 100644 --- a/tooling/cli/src/mobile/init.rs +++ b/tooling/cli/src/mobile/init.rs @@ -89,7 +89,11 @@ pub fn exec( let tauri_config_guard = tauri_config.lock().unwrap(); let tauri_config_ = tauri_config_guard.as_ref().unwrap(); - let app = get_app(tauri_config_, &AppInterface::new(tauri_config_, None)?); + let app = get_app( + target, + tauri_config_, + &AppInterface::new(tauri_config_, None)?, + ); let (handlebars, mut map) = handlebars(&app); diff --git a/tooling/cli/src/mobile/ios/build.rs b/tooling/cli/src/mobile/ios/build.rs index a90056c91..5da719a75 100644 --- a/tooling/cli/src/mobile/ios/build.rs +++ b/tooling/cli/src/mobile/ios/build.rs @@ -146,7 +146,7 @@ pub fn command(options: Options, noise_level: NoiseLevel) -> Result<()> { let interface = AppInterface::new(tauri_config_, build_options.target.clone())?; interface.build_options(&mut Vec::new(), &mut build_options.features, true); - let app = get_app(tauri_config_, &interface); + let app = get_app(MobileTarget::Ios, tauri_config_, &interface); let (config, _metadata) = get_config( &app, tauri_config_, diff --git a/tooling/cli/src/mobile/ios/dev.rs b/tooling/cli/src/mobile/ios/dev.rs index 3704243b3..248c311bf 100644 --- a/tooling/cli/src/mobile/ios/dev.rs +++ b/tooling/cli/src/mobile/ios/dev.rs @@ -159,7 +159,7 @@ fn run_command(options: Options, noise_level: NoiseLevel) -> Result<()> { let interface = AppInterface::new(tauri_config_, Some(target_triple))?; - let app = get_app(tauri_config_, &interface); + let app = get_app(MobileTarget::Ios, tauri_config_, &interface); let (config, _metadata) = get_config( &app, tauri_config_, diff --git a/tooling/cli/src/mobile/ios/xcode_script.rs b/tooling/cli/src/mobile/ios/xcode_script.rs index 141d189cc..49b2851d8 100644 --- a/tooling/cli/src/mobile/ios/xcode_script.rs +++ b/tooling/cli/src/mobile/ios/xcode_script.rs @@ -81,7 +81,11 @@ pub fn command(options: Options) -> Result<()> { let tauri_config_ = tauri_config_guard.as_ref().unwrap(); let cli_options = read_options(&tauri_config_.identifier); let (config, metadata) = get_config( - &get_app(tauri_config_, &AppInterface::new(tauri_config_, None)?), + &get_app( + MobileTarget::Ios, + tauri_config_, + &AppInterface::new(tauri_config_, None)?, + ), tauri_config_, None, &cli_options, diff --git a/tooling/cli/src/mobile/mod.rs b/tooling/cli/src/mobile/mod.rs index a92d57c54..f0b1f7bfc 100644 --- a/tooling/cli/src/mobile/mod.rs +++ b/tooling/cli/src/mobile/mod.rs @@ -248,13 +248,19 @@ fn read_options(identifier: &str) -> CliOptions { options } -pub fn get_app(config: &TauriConfig, interface: &AppInterface) -> App { +pub fn get_app(target: Target, config: &TauriConfig, interface: &AppInterface) -> App { let identifier = config .identifier .rsplit('.') .collect::>() .join("."); + let identifier = match target { + Target::Android => identifier.replace('-', "_"), + #[cfg(target_os = "macos")] + Target::Ios => identifier.replace('_', "-"), + }; + if identifier.is_empty() { log::error!("Bundle identifier set in `tauri.conf.json > identifier` cannot be empty"); exit(1); @@ -318,7 +324,7 @@ fn ensure_init( Target::Android => { let java_folder = project_dir .join("app/src/main/java") - .join(tauri_config_.identifier.replace('.', "/")); + .join(tauri_config_.identifier.replace('.', "/").replace('-', "_")); if !java_folder.exists() { project_outdated_reasons .push("you have modified your \"identifier\" in the Tauri configuration"); @@ -330,7 +336,7 @@ fn ensure_init( .context("missing project.yml file in the Xcode project directory")?; if !project_yml.contains(&format!( "PRODUCT_BUNDLE_IDENTIFIER: {}", - tauri_config_.identifier + tauri_config_.identifier.replace('_', "-") )) { project_outdated_reasons .push("you have modified your \"identifier\" in the Tauri configuration");