From 647f02bb5958ca21036982df90249c98545d4e9a Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Wed, 15 Feb 2023 09:19:59 +1100 Subject: [PATCH] Use `cargo-zigbuild` for cross compilation (#767) * Disable link arg `-lgcc` for musl builds when `cargo-zigbuild` is used Signed-off-by: Jiahao XU --- .github/workflows/ci.yml | 2 +- .github/workflows/release-build.yml | 2 +- justfile | 9 +++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9d7c9bda..5f9c4e8a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,7 +63,7 @@ jobs: runs-on: ubuntu-latest env: CARGO_BUILD_TARGET: ${{ matrix.target }} - JUST_USE_CROSS: true + JUST_USE_CARGO_ZIGBUILD: true steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml index bf7617ba..45f78f22 100644 --- a/.github/workflows/release-build.yml +++ b/.github/workflows/release-build.yml @@ -34,7 +34,7 @@ jobs: runs-on: ${{ matrix.o }} env: CARGO_BUILD_TARGET: ${{ matrix.t }} - JUST_USE_CROSS: ${{ matrix.c }} + JUST_USE_CARGO_ZIGBUILD: ${{ matrix.c }} JUST_FOR_RELEASE: true steps: diff --git a/justfile b/justfile index 6d903a05..521332e4 100644 --- a/justfile +++ b/justfile @@ -2,6 +2,7 @@ ci := env_var_or_default("CI", "") for-release := env_var_or_default("JUST_FOR_RELEASE", "") use-cross := env_var_or_default("JUST_USE_CROSS", "") +use-cargo-zigbuild := env_var_or_default("JUST_USE_CARGO_ZIGBUILD", "") extra-build-args := env_var_or_default("JUST_EXTRA_BUILD_ARGS", "") extra-features := env_var_or_default("JUST_EXTRA_FEATURES", "") default-features := env_var_or_default("JUST_DEFAULT_FEATURES", "") @@ -36,7 +37,7 @@ output-folder := if target != target-host { "target" / target / output-profile-f output-path := output-folder / output-filename # which tool to use for compiling -cargo-bin := if use-cross != "" { "cross" } else { "cargo +nightly" } +cargo-bin := if use-cargo-zigbuild != "" { "cargo-zigbuild" } else if use-cross != "" { "cross" } else { "cargo +nightly" } # cargo compile options cargo-profile := if for-release != "" { "release" } else { "dev" } @@ -52,7 +53,7 @@ cargo-buildstd := if (cargo-profile / ci-or-no) == "release/ci" { # In musl release builds in CI, statically link gcclibs. rustc-gcclibs := if (cargo-profile / ci-or-no / target-libc) == "release/ci/musl" { - " -C link-arg=-lgcc -C link-arg=-static-libgcc" + if use-cargo-zigbuild != "" { "-C link-arg=-static-libgcc" } else { " -C link-arg=-lgcc -C link-arg=-static-libgcc" } } else { "" } # disable default features in CI for debug builds, for speed @@ -94,8 +95,8 @@ ci-apt-deps := if target == "x86_64-unknown-linux-gnu" { "liblzma-dev libzip-dev [linux] ci-install-deps: - {{ if ci-apt-deps == "" { "exit" } else { "" } }} - sudo apt update && sudo apt install -y --no-install-recommends {{ci-apt-deps}} + if [ -n "{{ci-apt-deps}}" ]; then sudo apt update && sudo apt install -y --no-install-recommends {{ci-apt-deps}}; fi + pip3 install cargo-zigbuild [macos] [windows]