Skip to content

Commit ccc3ea7

Browse files
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 <lucas@tauri.app>
1 parent bcc63bf commit ccc3ea7

File tree

6 files changed

+25
-6
lines changed

6 files changed

+25
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-codegen": "patch"
3+
---
4+
5+
Use `TAURI_ENV_TARGET_TRIPLE` (which is set by `tauri-build`) to determine the target when reading the config file.
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri": "patch:bug"
3+
---
4+
5+
Parse the correct platform `tauri.<platform>.conf.json` config file when building or developing for mobile.
6+

core/tauri-build/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,8 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
530530
tauri_utils::plugin::load_global_api_scripts(&out_dir);
531531

532532
println!("cargo:rustc-env=TAURI_ENV_TARGET_TRIPLE={target_triple}");
533+
// when running codegen in this build script, we need to access the env var directly
534+
std::env::set_var("TAURI_ENV_TARGET_TRIPLE", &target_triple);
533535

534536
// TODO: far from ideal, but there's no other way to get the target dir, see <https://github.com/rust-lang/cargo/issues/5457>
535537
let target_dir = out_dir

core/tauri-codegen/src/context.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
139139
assets,
140140
} = data;
141141

142-
let target = std::env::var("TARGET")
143-
.or_else(|_| std::env::var("TAURI_ENV_TARGET_TRIPLE"))
142+
let target = std::env::var("TAURI_ENV_TARGET_TRIPLE")
144143
.as_deref()
145144
.map(Target::from_triple)
146145
.unwrap_or_else(|_| Target::current());

core/tauri-codegen/src/lib.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use std::{
1818
path::{Path, PathBuf},
1919
};
2020
pub use tauri_utils::config::{parse::ConfigError, Config};
21+
use tauri_utils::platform::Target;
2122

2223
mod context;
2324
pub mod embedded_assets;
@@ -63,22 +64,28 @@ pub fn get_config(path: &Path) -> Result<(Config, PathBuf), CodegenConfigError>
6364
.map(ToOwned::to_owned)
6465
.ok_or_else(|| CodegenConfigError::Parent(path.into_owned()))?;
6566

67+
let target = std::env::var("TAURI_ENV_TARGET_TRIPLE")
68+
.as_deref()
69+
.map(Target::from_triple)
70+
.unwrap_or_else(|_| Target::current());
71+
6672
// in the future we may want to find a way to not need the TAURI_CONFIG env var so that
6773
// it is impossible for the content of two separate configs to get mixed up. The chances are
6874
// already unlikely unless the developer goes out of their way to run the cli on a different
6975
// project than the target crate.
7076
let mut config = serde_json::from_value(tauri_utils::config::parse::read_from(
71-
tauri_utils::platform::Target::current(),
77+
target,
7278
parent.clone(),
7379
)?)?;
80+
7481
if let Ok(env) = std::env::var("TAURI_CONFIG") {
7582
let merge_config: serde_json::Value =
7683
serde_json::from_str(&env).map_err(CodegenConfigError::FormatInline)?;
7784
json_patch::merge(&mut config, &merge_config);
7885
}
7986

80-
let old_cwd = std::env::current_dir().map_err(CodegenConfigError::CurrentDir)?;
8187
// Set working directory to where `tauri.config.json` is, so that relative paths in it are parsed correctly.
88+
let old_cwd = std::env::current_dir().map_err(CodegenConfigError::CurrentDir)?;
8289
std::env::set_current_dir(parent.clone()).map_err(CodegenConfigError::CurrentDir)?;
8390

8491
let config = serde_json::from_value(config)?;

tooling/bundler/src/bundle/windows/msi/wix.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,9 @@ pub fn build_wix_app_installer(
586586
data.insert("feature_group_refs", to_json(&wix.feature_group_refs));
587587
data.insert("feature_refs", to_json(&wix.feature_refs));
588588
data.insert("merge_refs", to_json(&wix.merge_refs));
589-
fragment_paths = wix.fragment_paths.clone();
589+
fragment_paths.clone_from(&wix.fragment_paths);
590590
enable_elevated_update_task = wix.enable_elevated_update_task;
591-
custom_template_path = wix.template.clone();
591+
custom_template_path.clone_from(&wix.template);
592592

593593
if let Some(banner_path) = &wix.banner_path {
594594
let filename = banner_path

0 commit comments

Comments
 (0)