From f885a9110d6a6feeb2576c01dff2ba4de1f604ea Mon Sep 17 00:00:00 2001 From: FujiApple Date: Fri, 20 Oct 2023 17:37:26 +0800 Subject: [PATCH] build: update ci job to use cargo-cross (WIP) --- .github/workflows/rust.yml | 88 ++++++++++++++++++++++---------------- Cargo.toml | 10 +++++ 2 files changed, 61 insertions(+), 37 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a6e6f91..bd1f567 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -11,42 +11,56 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - rust: - - stable - # - nightly + build: [linux, macos, windows, netbsd] + include: + - build: linux + os: ubuntu-latest + target: x86_64-unknown-linux-gnu + - build: macos + os: macos-latest + target: x86_64-apple-darwin + - build: windows + os: windows-latest + target: x86_64-pc-windows-msvc + - build: netbsd + os: ubuntu-22.04 + target: x86_64-unknown-netbsd steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ matrix.rust }} - override: true - components: rustfmt, clippy - - uses: Swatinem/rust-cache@v1 - - name: cargo build - uses: actions-rs/cargo@v1 - with: - command: build - args: --verbose - - name: cargo test - uses: actions-rs/cargo@v1 - with: - command: test - args: --verbose - - name: cargo test (without chrono) - uses: actions-rs/cargo@v1 - with: - command: test - args: --verbose --no-default-features --features coinit_apartmentthreaded - - name: cargo fmt - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check - - name: cargo clippy - uses: actions-rs/cargo@v1 - with: - command: clippy - args: -- -D warnings + - name: Checkout repository + uses: actions/checkout@v2 + with: + fetch-depth: 1 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + target: ${{ matrix.target }} + + - name: Use Cross + shell: bash + run: | + cargo install cross + echo "CARGO=cross" >> $GITHUB_ENV + echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV + echo "RUSTC_LOG=rustc_codegen_ssa::back::link=info" >> $GITHUB_ENV + - name: cargo test + run: ${{ env.CARGO }} test --verbose ${{ env.TARGET_FLAGS }} + + - name: cargo test (without chrono) + run: ${{ env.CARGO }} test --verbose --no-default-features --features coinit_apartmentthreaded ${{ env.TARGET_FLAGS }} + + - name: cargo fmt + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + - name: cargo clippy + uses: actions-rs/cargo@v1 + with: + command: clippy + args: -- -D warnings diff --git a/Cargo.toml b/Cargo.toml index 8c76f5c..dc62508 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,3 +51,13 @@ windows = { version = "0.44.0", features = [ "Win32_UI_Shell_PropertiesSystem", ] } scopeguard = "1.2.0" + +[package.metadata.cross.target.x86_64-unknown-netbsd] +pre-build = [ + "mkdir -p /tmp/netbsd", + "curl https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.2/amd64/binary/sets/base.tar.xz -O", + "tar -C /tmp/netbsd -xJf base.tar.xz", + "cp /tmp/netbsd/usr/lib/libexecinfo.so /usr/local/x86_64-unknown-netbsd/lib", + "rm base.tar.xz", + "rm -rf /tmp/netbsd", +] \ No newline at end of file