From ccad91a4a930c1693e8cce5201caa68f1d2d0a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E6=AD=A3=E8=B6=85?= Date: Mon, 14 Jul 2025 20:01:52 +0800 Subject: [PATCH] fix: resolve zstd-sys compilation issues with zig cross-compilation (#203) - Update to mlugg/setup-zig@v2 for better stability and features - Use Zig 0.13.0 for improved musl target support - Add system zstd libraries (libzstd-dev, zstd) to Ubuntu dependencies - Configure environment variables for zstd-sys to use pkg-config - Enable pkg-config feature for zstd dependency to prefer system library - Add proper C/C++ compiler configuration for musl targets Fixes the 'error: unable to parse target query x86_64-unknown-linux-musl: UnknownOperatingSystem' compilation error in zstd-sys during cross-compilation. --- .github/actions/setup/action.yml | 6 +++++- .github/workflows/build.yml | 11 +++++++++++ Cargo.toml | 2 +- build-rustfs.sh | 17 ++++++++++++++++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 2e1d8d17..39d14ed6 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -58,7 +58,9 @@ runs: libwebkit2gtk-4.1-dev \ libxdo-dev \ pkg-config \ - libssl-dev + libssl-dev \ + libzstd-dev \ + zstd - name: Install protoc uses: arduino/setup-protoc@v3 @@ -81,6 +83,8 @@ runs: - name: Install Zig if: inputs.install-cross-tools == 'true' uses: mlugg/setup-zig@v2 + with: + version: 0.13.0 - name: Install cargo-zigbuild if: inputs.install-cross-tools == 'true' diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0023af39..1bf9c913 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -191,6 +191,17 @@ jobs: run: | # Use unified build script for consistent builds ./build-rustfs.sh --platform ${{ matrix.target }} + env: + # Set environment variables for zstd-sys to avoid target parsing issues + ZSTD_SYS_USE_PKG_CONFIG: 1 + PKG_CONFIG_ALLOW_CROSS: 1 + # For musl targets, use system zstd if available + CC_x86_64_unknown_linux_musl: zig cc -target x86_64-linux-musl + CXX_x86_64_unknown_linux_musl: zig c++ -target x86_64-linux-musl + AR_x86_64_unknown_linux_musl: zig ar + CC_aarch64_unknown_linux_musl: zig cc -target aarch64-linux-musl + CXX_aarch64_unknown_linux_musl: zig c++ -target aarch64-linux-musl + AR_aarch64_unknown_linux_musl: zig ar - name: Create release package id: package diff --git a/Cargo.toml b/Cargo.toml index 64ef4ed0..1da46e42 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -265,7 +265,7 @@ wildmatch = { version = "2.4.0", features = ["serde"] } winapi = { version = "0.3.9" } xxhash-rust = { version = "0.8.15", features = ["xxh64", "xxh3"] } zip = "2.4.2" -zstd = "0.13.3" +zstd = { version = "0.13.3", features = ["pkg-config"] } anyhow = "1.0.98" [profile.wasm-dev] diff --git a/build-rustfs.sh b/build-rustfs.sh index 1ce73f90..c0eeb0c9 100755 --- a/build-rustfs.sh +++ b/build-rustfs.sh @@ -173,12 +173,27 @@ setup_rust_environment() { # For cargo-zigbuild, set up additional environment variables if command -v cargo-zigbuild &> /dev/null; then print_message $YELLOW "Configuring cargo-zigbuild for musl target..." + + # Set environment variables for better musl support export CC_x86_64_unknown_linux_musl="zig cc -target x86_64-linux-musl" export CXX_x86_64_unknown_linux_musl="zig c++ -target x86_64-linux-musl" + export AR_x86_64_unknown_linux_musl="zig ar" + export CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER="zig cc -target x86_64-linux-musl" + export CC_aarch64_unknown_linux_musl="zig cc -target aarch64-linux-musl" export CXX_aarch64_unknown_linux_musl="zig c++ -target aarch64-linux-musl" - export AR_x86_64_unknown_linux_musl="zig ar" export AR_aarch64_unknown_linux_musl="zig ar" + export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER="zig cc -target aarch64-linux-musl" + + # Set environment variables for zstd-sys to avoid target parsing issues + export ZSTD_SYS_USE_PKG_CONFIG=1 + export PKG_CONFIG_ALLOW_CROSS=1 + + # Use system zstd if available for musl builds + if [[ "$PLATFORM" == *"musl"* ]]; then + export ZSTD_SYS_USE_PKG_CONFIG=1 + export PKG_CONFIG_ALLOW_CROSS=1 + fi fi fi