Kaynağa Gözat

fix(cli): Handle target triples with 4 components (#8448)

* fix(cli): Handle target triples with 4 components

Follow up of #8321 which broke the `TAURI_ENV_` vars for linux, windows and ios-sim

* use host for platform as is

* clippy
Fabian-Lars 1 yıl önce
ebeveyn
işleme
41990cd344

+ 6 - 0
.changes/cli-hook-env-vars.md

@@ -0,0 +1,6 @@
+---
+'tauri-cli': 'patch:bug'
+'@tauri-apps/cli': 'patch:bug'
+---
+
+Prevent `Invalid target triple` warnings and correctly set `TAURI_ENV_` vars when target triple contains 4 components. `darwin` and `androideabi` are no longer replaced with `macos` and `android` in `TAURI_ENV_PLATFORM`.

+ 7 - 12
tooling/cli/src/interface/rust.rs

@@ -230,8 +230,11 @@ impl Interface for Rust {
 
     let target_triple = &self.app_settings.target_triple;
     let target_components: Vec<&str> = target_triple.split('-').collect();
-    let (arch, host) = match target_components.as_slice() {
-      [arch, _, host] => (*arch, *host),
+    let (arch, host, _host_env) = match target_components.as_slice() {
+      // 3 components like aarch64-apple-darwin
+      [arch, _, host] => (*arch, *host, None),
+      // 4 components like x86_64-pc-windows-msvc and aarch64-apple-ios-sim
+      [arch, _, host, host_env] => (*arch, *host, Some(*host_env)),
       _ => {
         log::warn!("Invalid target triple: {}", target_triple);
         return env;
@@ -246,16 +249,8 @@ impl Interface for Rust {
         a => a.into(),
       },
     );
-    env.insert(
-      "TAURI_ENV_PLATFORM",
-      match host {
-        // keeps compatibility with old `std::env::consts::OS` implementation
-        "darwin" => "macos".into(),
-        "ios-sim" => "ios".into(),
-        "androideabi" => "android".into(),
-        h => h.into(),
-      },
-    );
+
+    env.insert("TAURI_ENV_PLATFORM", host.into());
 
     env.insert(
       "TAURI_ENV_FAMILY",