From 739a5f7df585519abcc1930b4b1ef3cc7764aa2a Mon Sep 17 00:00:00 2001 From: VirtualHotBar <96966978+VirtualHotBar@users.noreply.github.com> Date: Wed, 18 Feb 2026 11:11:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(ci):=20=E4=BF=AE=E5=A4=8D=20macOS=20?= =?UTF-8?q?=E4=BA=A4=E5=8F=89=E7=BC=96=E8=AF=91=E5=92=8C=20Windows=20WiX?= =?UTF-8?q?=20=E6=9E=84=E5=BB=BA=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 使用 CARGO_CFG_TARGET_ARCH 环境变量检测目标架构,支持交叉编译 - 添加 CARGO_CFG_TARGET_ARCH/OST 的 rerun-if-env-changed - 在 Windows runner 上显式安装 WiX Toolset 3.14.1 --- .github/workflows/main.yml | 6 ++++++ src-tauri/build.rs | 13 +++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3dfcd0d..28d76e9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -218,6 +218,12 @@ jobs: sudo apt-get update sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf + - name: Install Windows dependencies (WiX) + if: matrix.platform == 'windows-latest' + run: | + choco install wixtoolset --version 3.14.1 --no-progress -y + echo "C:\Program Files (x86)\WiX Toolset v3.14\bin" >> $env:GITHUB_PATH + - run: pnpm install --frozen-lockfile - name: Build Tauri app diff --git a/src-tauri/build.rs b/src-tauri/build.rs index 7406382..a81bbd1 100644 --- a/src-tauri/build.rs +++ b/src-tauri/build.rs @@ -141,6 +141,9 @@ fn main() -> anyhow::Result<()> { println!("cargo:rerun-if-env-changed=NETMOUNT_SKIP_WINFSP_DOWNLOAD"); println!("cargo:rerun-if-env-changed=NETMOUNT_GITHUB_PROXY"); println!("cargo:rerun-if-env-changed=NETMOUNT_SKIP_TAURI_BUILD"); + // 交叉编译时目标架构会变化,需要重新运行 build.rs + println!("cargo:rerun-if-env-changed=CARGO_CFG_TARGET_ARCH"); + println!("cargo:rerun-if-env-changed=CARGO_CFG_TARGET_OS"); // Locales are compiled into OUT_DIR/language.rs at build-time, so we must // tell Cargo to rerun build.rs when any locale json changes. println!("cargo:rerun-if-changed=locales/"); @@ -663,6 +666,13 @@ fn get_target_triple() -> String { } fn get_arch() -> String { + // 优先使用 Cargo 提供的目标架构(支持交叉编译) + // CARGO_CFG_TARGET_ARCH 在交叉编译时会被设置为正确的目标架构 + if let Ok(target_arch) = env::var("CARGO_CFG_TARGET_ARCH") { + return target_arch; + } + + // 降级方案:检测构建机器架构 #[cfg(not(target_os = "windows"))] { use std::process::Command; @@ -672,13 +682,12 @@ fn get_arch() -> String { .output() .expect("failed to execute process"); - if !output.status.success() { panic!("uname command failed"); } return String::from_utf8_lossy(&output.stdout).trim().to_string(); } - return env::consts::ARCH.to_owned(); + env::consts::ARCH.to_owned() } use futures_util::stream::StreamExt;