From 4e64f058ee9807145c15da602ce33c888512b454 Mon Sep 17 00:00:00 2001 From: Niklas Dusenlund Date: Fri, 3 Jan 2025 10:24:36 +0100 Subject: [PATCH 1/2] Add aarch64/arm64 to CI --- .github/workflows/cbindgen.yml | 69 ++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/.github/workflows/cbindgen.yml b/.github/workflows/cbindgen.yml index b36c2511..45cec5b7 100644 --- a/.github/workflows/cbindgen.yml +++ b/.github/workflows/cbindgen.yml @@ -88,3 +88,72 @@ jobs: run: | cargo +nightly update -Zminimal-versions cargo +nightly test + + build-arm64: + + runs-on: ubuntu-latest + env: + CARGO_BUILD_TARGET: aarch64-unknown-linux-gnu + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER: qemu-aarch64-static + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc-11 + + steps: + - uses: actions/checkout@v3 + + - run: | + sudo sed -i 's/^deb /deb [arch=amd64] /' /etc/apt/sources.list + echo "deb [arch=arm64] http://ports.ubuntu.com/ jammy main multiverse universe" | sudo tee -a /etc/apt/sources.list + echo "deb [arch=arm64] http://ports.ubuntu.com/ jammy-security main multiverse universe" | sudo tee -a /etc/apt/sources.list + echo "deb [arch=arm64] http://ports.ubuntu.com/ jammy-backports main multiverse universe" | sudo tee -a /etc/apt/sources.list + echo "deb [arch=arm64] http://ports.ubuntu.com/ jammy-updates main multiverse universe" | sudo tee -a /etc/apt/sources.list + + sudo dpkg --add-architecture arm64 + sudo apt-get update + sudo apt-get install -y qemu-user-static gcc-11-aarch64-linux-gnu + sudo apt-get install -y libc6:arm64 + + - name: Install stable Rust + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{env.CARGO_BUILD_TARGET}} + + - name: Install Python + uses: actions/setup-python@v4 + with: + python-version: '3.8' + + - name: Install Cython + run: | + python -m pip install --upgrade pip wheel + pip install Cython==3.0.2 + + - name: Build + run: | + cargo +stable build --verbose + + - name: Build no-default-features + run: | + cargo +stable build --verbose --no-default-features + + - name: Test package + env: + CBINDGEN_TEST_VERIFY: 1 + run: | + cargo +stable package --verbose + (cd target/package/cbindgen-$(cargo +stable run -- --version | cut -d ' ' -f 2) && cargo +stable test --verbose) + + - name: Install nightly Rust + uses: dtolnay/rust-toolchain@nightly + with: + targets: ${{env.CARGO_BUILD_TARGET}} + + - name: Test + env: + CBINDGEN_TEST_VERIFY: 1 + run: | + cargo +nightly test --verbose + + - name: Test minimal-versions + run: | + cargo +nightly update -Zminimal-versions + cargo +nightly test From 9bdf01beaf4bd01086efb7ffd5e42de7f14ae5b5 Mon Sep 17 00:00:00 2001 From: Niklas Dusenlund Date: Sat, 4 Jan 2025 01:30:17 +0100 Subject: [PATCH 2/2] Refactor arm64 build to matrix strategy Github is gradually moving ubuntu-latest to ubuntu-24.04 and the apt sources look slightly different. My fork and upstream ends up having different "ubuntu-latest", so I pin it to 24. --- .github/workflows/cbindgen.yml | 87 ++++++++++------------------------ 1 file changed, 25 insertions(+), 62 deletions(-) diff --git a/.github/workflows/cbindgen.yml b/.github/workflows/cbindgen.yml index 45cec5b7..090dc64e 100644 --- a/.github/workflows/cbindgen.yml +++ b/.github/workflows/cbindgen.yml @@ -14,7 +14,7 @@ on: jobs: rustfmt-clippy: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v3 @@ -41,81 +41,44 @@ jobs: cargo +${{steps.msrv.outputs.name}} test nonexistent-test --verbose build: + runs-on: ubuntu-24.04 - runs-on: ubuntu-latest + strategy: + matrix: + arch: [amd64, arm64] + include: + - arch: arm64 + env: + CARGO_BUILD_TARGET: aarch64-unknown-linux-gnu + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc-11 steps: - uses: actions/checkout@v3 - - name: Install stable Rust - uses: dtolnay/rust-toolchain@stable - - - name: Install Python - uses: actions/setup-python@v4 - with: - python-version: '3.8' - - - name: Install Cython - run: | - python -m pip install --upgrade pip wheel - pip install Cython==3.0.2 - - - name: Build - run: | - cargo +stable build --verbose - - - name: Build no-default-features - run: | - cargo +stable build --verbose --no-default-features - - - name: Test package - env: - CBINDGEN_TEST_VERIFY: 1 - run: | - cargo +stable package --verbose - (cd target/package/cbindgen-$(cargo +stable run -- --version | cut -d ' ' -f 2) && cargo +stable test --verbose) - - - name: Install nightly Rust - uses: dtolnay/rust-toolchain@nightly - - - name: Test - env: - CBINDGEN_TEST_VERIFY: 1 + - name: Setup environment variables for cross compiling + if: matrix.arch != 'amd64' run: | - cargo +nightly test --verbose + echo CARGO_BUILD_TARGET=${{matrix.env.CARGO_BUILD_TARGET}} >> ${GITHUB_ENV} + echo CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=${{matrix.env.CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER}} >> ${GITHUB_ENV} - - name: Test minimal-versions + - name: Install cross linker and emulator + if: matrix.arch == 'arm64' run: | - cargo +nightly update -Zminimal-versions - cargo +nightly test - - build-arm64: - - runs-on: ubuntu-latest - env: - CARGO_BUILD_TARGET: aarch64-unknown-linux-gnu - CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER: qemu-aarch64-static - CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc-11 - - steps: - - uses: actions/checkout@v3 - - - run: | - sudo sed -i 's/^deb /deb [arch=amd64] /' /etc/apt/sources.list - echo "deb [arch=arm64] http://ports.ubuntu.com/ jammy main multiverse universe" | sudo tee -a /etc/apt/sources.list - echo "deb [arch=arm64] http://ports.ubuntu.com/ jammy-security main multiverse universe" | sudo tee -a /etc/apt/sources.list - echo "deb [arch=arm64] http://ports.ubuntu.com/ jammy-backports main multiverse universe" | sudo tee -a /etc/apt/sources.list - echo "deb [arch=arm64] http://ports.ubuntu.com/ jammy-updates main multiverse universe" | sudo tee -a /etc/apt/sources.list + # Only works on noble (and later?) + sudo sed -i '/^Components/a Architectures: amd64' /etc/apt/sources.list.d/ubuntu.sources + echo "deb [arch=arm64] http://ports.ubuntu.com/ $(lsb_release -sc) main multiverse universe" | sudo tee -a /etc/apt/sources.list.d/ports.list + echo "deb [arch=arm64] http://ports.ubuntu.com/ $(lsb_release -sc)-security main multiverse universe" | sudo tee -a /etc/apt/sources.list.d/ports.list + echo "deb [arch=arm64] http://ports.ubuntu.com/ $(lsb_release -sc)-backports main multiverse universe" | sudo tee -a /etc/apt/sources.list.d/ports.list + echo "deb [arch=arm64] http://ports.ubuntu.com/ $(lsb_release -sc)-updates main multiverse universe" | sudo tee -a /etc/apt/sources.list.d/ports.list sudo dpkg --add-architecture arm64 sudo apt-get update - sudo apt-get install -y qemu-user-static gcc-11-aarch64-linux-gnu - sudo apt-get install -y libc6:arm64 + sudo apt-get install -y qemu-user gcc-11-aarch64-linux-gnu libc6:arm64 - name: Install stable Rust uses: dtolnay/rust-toolchain@stable with: - targets: ${{env.CARGO_BUILD_TARGET}} + targets: ${{matrix.env.CARGO_BUILD_TARGET}} - name: Install Python uses: actions/setup-python@v4 @@ -145,7 +108,7 @@ jobs: - name: Install nightly Rust uses: dtolnay/rust-toolchain@nightly with: - targets: ${{env.CARGO_BUILD_TARGET}} + targets: ${{matrix.env.CARGO_BUILD_TARGET}} - name: Test env: