From 967f598bf1fde056199a8d5c665f8d687e7a21c9 Mon Sep 17 00:00:00 2001 From: Jose Fernandez Date: Sun, 9 Jun 2024 16:44:10 -0600 Subject: [PATCH] Use cross-rs to build binaries in CI Previously we were building the binaries in CI using cargo directly. With this change we are using cross-rs to build the binaries and we now also target aarch64. Signed-off-by: Jose Fernandez --- .github/workflows/rust.yml | 23 +++++++++++++++-------- Cross.toml | 9 ++++----- dockerfiles/Dockerfile.aarch64 | 5 +++++ dockerfiles/Dockerfile.x86_64 | 3 +++ 4 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 dockerfiles/Dockerfile.aarch64 create mode 100644 dockerfiles/Dockerfile.x86_64 diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 880993c..4b256b2 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -16,18 +16,25 @@ jobs: runs-on: ubuntu-20.04 permissions: contents: write + strategy: + matrix: + target: + - x86_64-unknown-linux-gnu + - aarch64-unknown-linux-gnu steps: - uses: actions/checkout@v4.1.1 - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install -y zlib1g-dev libelf-dev + + - name: Install cross + run: cargo install cross --git https://github.com/cross-rs/cross + - name: Test - run: cargo test - - name: clippy - run: cargo clippy --all --tests --all-features --no-deps + run: cross test --target ${{ matrix.target }} + + - name: Clippy + run: cross clippy --target ${{ matrix.target }} --all --tests --all-features --no-deps + - name: Build - run: cargo build --release + run: cross build --target ${{ matrix.target }} --release - name: Build RPM if: startsWith(github.ref, 'refs/tags/v') diff --git a/Cross.toml b/Cross.toml index 2c1fd84..029263e 100644 --- a/Cross.toml +++ b/Cross.toml @@ -1,10 +1,9 @@ [build] xargo = false default-target = "x86_64-unknown-linux-gnu" -pre-build = ["apt-get update && apt-get install -y zlib1g-dev libelf-dev"] + +[target.x86_64-unknown-linux-gnu] +dockerfile = "dockerfiles/Dockerfile.x86_64" [target.aarch64-unknown-linux-gnu] -pre-build = [ - "dpkg --add-architecture $CROSS_DEB_ARCH", - "apt-get update && apt-get --assume-yes install zlib1g-dev:$CROSS_DEB_ARCH libelf-dev:$CROSS_DEB_ARCH" -] \ No newline at end of file +dockerfile = "dockerfiles/Dockerfile.aarch64" \ No newline at end of file diff --git a/dockerfiles/Dockerfile.aarch64 b/dockerfiles/Dockerfile.aarch64 new file mode 100644 index 0000000..fa79d7e --- /dev/null +++ b/dockerfiles/Dockerfile.aarch64 @@ -0,0 +1,5 @@ +FROM ghcr.io/cross-rs/aarch64-unknown-linux-gnu:main + +RUN apt-get update && apt-get install --assume-yes clang zlib1g-dev libelf-dev +RUN dpkg --add-architecture arm64 +RUN apt-get update && apt-get install --assume-yes zlib1g-dev:arm64 libelf-dev:arm64 diff --git a/dockerfiles/Dockerfile.x86_64 b/dockerfiles/Dockerfile.x86_64 new file mode 100644 index 0000000..06c3aea --- /dev/null +++ b/dockerfiles/Dockerfile.x86_64 @@ -0,0 +1,3 @@ +FROM ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main + +RUN apt-get update && apt-get install --assume-yes zlib1g-dev libelf-dev clang \ No newline at end of file