Skip to content

Commit 793ee05

Browse files
authored
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
1 parent da8c9a7 commit 793ee05

16 files changed

Lines changed: 67 additions & 53 deletions

File tree

.changes/mobile-identifier.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"tauri-cli": patch:bug
3+
"tauri-build": patch:bug
4+
"@tauri-apps/cli": patch:bug
5+
"tauri-runtime-wry": patch:bug
6+
---
7+
8+
Allow hyphens and underscores on app identifiers.

Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/tauri-build/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,12 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
476476
let mut android_package_prefix = String::new();
477477
for (i, w) in s.enumerate() {
478478
if i == last {
479-
println!("cargo:rustc-env=TAURI_ANDROID_PACKAGE_NAME_APP_NAME={w}");
479+
println!(
480+
"cargo:rustc-env=TAURI_ANDROID_PACKAGE_NAME_APP_NAME={}",
481+
w.replace('-', "_")
482+
);
480483
} else {
481-
android_package_prefix.push_str(w);
484+
android_package_prefix.push_str(&w.replace(['_', '-'], "_1"));
482485
android_package_prefix.push('_');
483486
}
484487
}

core/tauri-macros/src/mobile.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,10 @@ use quote::{format_ident, quote};
88
use std::env::var;
99
use syn::{parse_macro_input, spanned::Spanned, ItemFn};
1010

11-
fn get_env_var<R: FnOnce(String) -> String>(
12-
name: &str,
13-
replacer: R,
14-
error: &mut Option<TokenStream2>,
15-
function: &ItemFn,
16-
) -> TokenStream2 {
11+
fn get_env_var(name: &str, error: &mut Option<TokenStream2>, function: &ItemFn) -> TokenStream2 {
1712
match var(name) {
1813
Ok(value) => {
19-
let ident = format_ident!("{}", replacer(value));
14+
let ident = format_ident!("{value}");
2015
quote!(#ident)
2116
}
2217
Err(_) => {
@@ -37,18 +32,8 @@ pub fn entry_point(_attributes: TokenStream, item: TokenStream) -> TokenStream {
3732
let function_name = &function.sig.ident;
3833

3934
let mut error = None;
40-
let domain = get_env_var(
41-
"TAURI_ANDROID_PACKAGE_NAME_PREFIX",
42-
|r| r,
43-
&mut error,
44-
&function,
45-
);
46-
let app_name = get_env_var(
47-
"TAURI_ANDROID_PACKAGE_NAME_APP_NAME",
48-
|r| r.replace('-', "_"),
49-
&mut error,
50-
&function,
51-
);
35+
let domain = get_env_var("TAURI_ANDROID_PACKAGE_NAME_PREFIX", &mut error, &function);
36+
let app_name = get_env_var("TAURI_ANDROID_PACKAGE_NAME_APP_NAME", &mut error, &function);
5237

5338
if let Some(e) = error {
5439
quote!(#e).into()

core/tauri-runtime-wry/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ rustdoc-args = [ "--cfg", "docsrs" ]
1818

1919
[dependencies]
2020
wry = { version = "0.42", default-features = false, features = [ "drag-drop", "protocol", "os-webview" ] }
21-
tao = { version = "0.29", default-features = false, features = [ "rwh_06" ] }
21+
tao = { version = "0.29.1", default-features = false, features = [ "rwh_06" ] }
2222
tauri-runtime = { version = "2.0.0-rc.5", path = "../tauri-runtime" }
2323
tauri-utils = { version = "2.0.0-rc.5", path = "../tauri-utils" }
2424
raw-window-handle = "0.6"

examples/api/src-tauri/Cargo.lock

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tooling/cli/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tooling/cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ name = "cargo-tauri"
3939
path = "src/main.rs"
4040

4141
[dependencies]
42-
cargo-mobile2 = { version = "0.13.4", default-features = false }
42+
cargo-mobile2 = { version = "0.13.5", default-features = false }
4343
jsonrpsee = { version = "0.24", features = [ "server" ] }
4444
jsonrpsee-core = "0.24"
4545
jsonrpsee-client-transport = { version = "0.24", features = [ "ws" ] }

tooling/cli/src/mobile/android/android_studio_script.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ pub fn command(options: Options) -> Result<()> {
5252
let tauri_config_ = tauri_config_guard.as_ref().unwrap();
5353
let cli_options = read_options(&tauri_config_.identifier);
5454
let (config, metadata) = get_config(
55-
&get_app(tauri_config_, &AppInterface::new(tauri_config_, None)?),
55+
&get_app(
56+
MobileTarget::Android,
57+
tauri_config_,
58+
&AppInterface::new(tauri_config_, None)?,
59+
),
5660
tauri_config_,
5761
None,
5862
&cli_options,

tooling/cli/src/mobile/android/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub fn command(options: Options, noise_level: NoiseLevel) -> Result<()> {
114114
let interface = AppInterface::new(tauri_config_, build_options.target.clone())?;
115115
interface.build_options(&mut Vec::new(), &mut build_options.features, true);
116116

117-
let app = get_app(tauri_config_, &interface);
117+
let app = get_app(MobileTarget::Android, tauri_config_, &interface);
118118
let (config, metadata) = get_config(
119119
&app,
120120
tauri_config_,

0 commit comments

Comments
 (0)