From ccc3ea729de205ef467f737f1feeb5bf02d9cd72 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Tue, 28 May 2024 19:48:24 +0300 Subject: [PATCH] fix(codegen): use `TAURI_ENV_TARGET_TRIPLE` to determine the current platform-specific config (#9646) * fix(codegen): use `TAURI_ENV_TARGET_TRIPLE` to determine the current platform-specific config * set env var * Update .changes/tauri-codegen-use-correct-env.md --------- Co-authored-by: Lucas Nogueira --- .changes/tauri-codegen-use-correct-env.md | 5 +++++ .changes/tauri-correct-platform-file.md | 6 ++++++ core/tauri-build/src/lib.rs | 2 ++ core/tauri-codegen/src/context.rs | 3 +-- core/tauri-codegen/src/lib.rs | 11 +++++++++-- tooling/bundler/src/bundle/windows/msi/wix.rs | 4 ++-- 6 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 .changes/tauri-codegen-use-correct-env.md create mode 100644 .changes/tauri-correct-platform-file.md diff --git a/.changes/tauri-codegen-use-correct-env.md b/.changes/tauri-codegen-use-correct-env.md new file mode 100644 index 000000000..5f0b66582 --- /dev/null +++ b/.changes/tauri-codegen-use-correct-env.md @@ -0,0 +1,5 @@ +--- +"tauri-codegen": "patch" +--- + +Use `TAURI_ENV_TARGET_TRIPLE` (which is set by `tauri-build`) to determine the target when reading the config file. diff --git a/.changes/tauri-correct-platform-file.md b/.changes/tauri-correct-platform-file.md new file mode 100644 index 000000000..5cccf70cf --- /dev/null +++ b/.changes/tauri-correct-platform-file.md @@ -0,0 +1,6 @@ +--- +"tauri": "patch:bug" +--- + +Parse the correct platform `tauri..conf.json` config file when building or developing for mobile. + diff --git a/core/tauri-build/src/lib.rs b/core/tauri-build/src/lib.rs index bc08cd87e..2134b14b0 100644 --- a/core/tauri-build/src/lib.rs +++ b/core/tauri-build/src/lib.rs @@ -530,6 +530,8 @@ pub fn try_build(attributes: Attributes) -> Result<()> { tauri_utils::plugin::load_global_api_scripts(&out_dir); println!("cargo:rustc-env=TAURI_ENV_TARGET_TRIPLE={target_triple}"); + // when running codegen in this build script, we need to access the env var directly + std::env::set_var("TAURI_ENV_TARGET_TRIPLE", &target_triple); // TODO: far from ideal, but there's no other way to get the target dir, see let target_dir = out_dir diff --git a/core/tauri-codegen/src/context.rs b/core/tauri-codegen/src/context.rs index 32c5d23ca..45e6ea80f 100644 --- a/core/tauri-codegen/src/context.rs +++ b/core/tauri-codegen/src/context.rs @@ -139,8 +139,7 @@ pub fn context_codegen(data: ContextData) -> Result Result<(Config, PathBuf), CodegenConfigError> .map(ToOwned::to_owned) .ok_or_else(|| CodegenConfigError::Parent(path.into_owned()))?; + let target = std::env::var("TAURI_ENV_TARGET_TRIPLE") + .as_deref() + .map(Target::from_triple) + .unwrap_or_else(|_| Target::current()); + // in the future we may want to find a way to not need the TAURI_CONFIG env var so that // it is impossible for the content of two separate configs to get mixed up. The chances are // already unlikely unless the developer goes out of their way to run the cli on a different // project than the target crate. let mut config = serde_json::from_value(tauri_utils::config::parse::read_from( - tauri_utils::platform::Target::current(), + target, parent.clone(), )?)?; + if let Ok(env) = std::env::var("TAURI_CONFIG") { let merge_config: serde_json::Value = serde_json::from_str(&env).map_err(CodegenConfigError::FormatInline)?; json_patch::merge(&mut config, &merge_config); } - let old_cwd = std::env::current_dir().map_err(CodegenConfigError::CurrentDir)?; // Set working directory to where `tauri.config.json` is, so that relative paths in it are parsed correctly. + let old_cwd = std::env::current_dir().map_err(CodegenConfigError::CurrentDir)?; std::env::set_current_dir(parent.clone()).map_err(CodegenConfigError::CurrentDir)?; let config = serde_json::from_value(config)?; diff --git a/tooling/bundler/src/bundle/windows/msi/wix.rs b/tooling/bundler/src/bundle/windows/msi/wix.rs index 11579abcb..9f66967b8 100644 --- a/tooling/bundler/src/bundle/windows/msi/wix.rs +++ b/tooling/bundler/src/bundle/windows/msi/wix.rs @@ -586,9 +586,9 @@ pub fn build_wix_app_installer( data.insert("feature_group_refs", to_json(&wix.feature_group_refs)); data.insert("feature_refs", to_json(&wix.feature_refs)); data.insert("merge_refs", to_json(&wix.merge_refs)); - fragment_paths = wix.fragment_paths.clone(); + fragment_paths.clone_from(&wix.fragment_paths); enable_elevated_update_task = wix.enable_elevated_update_task; - custom_template_path = wix.template.clone(); + custom_template_path.clone_from(&wix.template); if let Some(banner_path) = &wix.banner_path { let filename = banner_path