Skip to content

Commit

Permalink
Add Apple M1 target aarch64-apple-darwin to CI (#486)
Browse files Browse the repository at this point in the history
Use cross-compiler to build M1 ARM apple target. Must use vendored
openssl build because of cross-compilation.

Co-authored-by: Yuri Astrakhan <[email protected]>
  • Loading branch information
stepankuzmin and nyurik authored Nov 18, 2022
1 parent 9fdda3d commit 935c251
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:

jobs:
build:
name: Build ${{ matrix.target }}
strategy:
fail-fast: true
matrix:
Expand All @@ -21,18 +22,14 @@ jobs:
target: x86_64-pc-windows-msvc
- os: macOS-latest
target: x86_64-apple-darwin
- os: macOS-latest
target: aarch64-apple-darwin
runs-on: ${{ matrix.os }}
steps:
# - name: Install stable toolchain
# uses: dtolnay/rust-toolchain@master
# with:
# toolchain: ${{ matrix.rust }}
# override: true
# target: ${{ matrix.target }}
- name: Checkout
uses: actions/checkout@v3
- name: Lint
if: runner.os == 'Linux'
if: matrix.target == 'x86_64-unknown-linux-gnu'
shell: bash
run: |
cargo fmt --all -- --check
Expand All @@ -45,40 +42,54 @@ jobs:
- name: Run build
shell: bash
run: |
cargo build --release --target ${{ matrix.target }}
if [[ "${{ matrix.target }}" == "aarch64-apple-darwin" ]]; then
rustup target add aarch64-apple-darwin
# compile without debug symbols
RUSTFLAGS='-C link-arg=-s' cargo build --release --target ${{ matrix.target }} --features=vendored-openssl
else
cargo build --release --target ${{ matrix.target }}
fi
mkdir target_releases
if [[ "${{ runner.os }}" == "Windows" ]]; then
mv target/${{ matrix.target }}/release/martin.exe target_releases
else
mv target/${{ matrix.target }}/release/martin target_releases
fi
- name: Save build artifacts
- name: Save build artifact build-${{ matrix.target }}
uses: actions/upload-artifact@v3
with:
name: build-${{ runner.os }}
name: build-${{ matrix.target }}
path: target_releases/*

test:
name: Test builds on ${{ matrix.os }}
name: Test & package ${{ matrix.target }}
needs: [build]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
include:
- os: ubuntu-latest
bin: martin
target: x86_64-unknown-linux-gnu
name: martin-Linux-x86_64.tar.gz
- os: windows-latest
bin: martin.exe
target: x86_64-pc-windows-msvc
name: martin-Windows-x86_64.zip
- os: macOS-latest
bin: martin
target: x86_64-apple-darwin
name: martin-Darwin-x86_64.tar.gz
- os: ubuntu-latest
bin: martin
target: aarch64-apple-darwin
name: martin-Darwin-aarch64.tar.gz
runs-on: ${{ matrix.os }}
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Start postgres
if: matrix.target != 'aarch64-apple-darwin'
uses: nyurik/action-setup-postgis@v1
id: pg
with:
Expand All @@ -87,12 +98,13 @@ jobs:
database: test
rights: --superuser
- name: Init database
if: matrix.target != 'aarch64-apple-darwin'
shell: bash
run: tests/fixtures/initdb.sh
env:
DATABASE_URL: ${{ steps.pg.outputs.connection-uri }}
- name: Unit Tests (Linux)
if: runner.os == 'Linux'
if: matrix.target == 'x86_64-unknown-linux-gnu'
shell: bash
run: |
cargo test --all
Expand All @@ -101,22 +113,17 @@ jobs:
DATABASE_URL: ${{ steps.pg.outputs.connection-uri }}
- uses: actions/download-artifact@v3
with:
name: build-${{ runner.os }}
name: build-${{ matrix.target }}
path: target/
- name: Compare test output results (TODO)
if: false && runner.os == 'Linux'
run: |
# TODO: this test is currently broken
# the output of the tests is not deterministic
diff --brief --recursive --new-file tests/output tests/expected
- name: Save test output on failure (Linux)
if: failure() && runner.os == 'Linux'
if: failure() && matrix.target == 'x86_64-unknown-linux-gnu'
uses: actions/upload-artifact@v3
with:
name: test-output
path: tests/output/*
retention-days: 5
- name: Test
if: matrix.target != 'aarch64-apple-darwin'
shell: bash
run: |
if [[ "${{ runner.os }}" != "Windows" ]]; then
Expand All @@ -131,15 +138,18 @@ jobs:
shell: bash
run: |
cd target/
strip ${{ matrix.bin }}
# Symbol stripping does not work cross-platform
if [[ "${{ matrix.target }}" != "aarch64-apple-darwin" ]]; then
strip ${{ matrix.bin }}
fi
if [[ "${{ runner.os }}" == "Windows" ]]; then
7z a ../${{ matrix.name }} ${{ matrix.bin }}
else
tar czvf ../${{ matrix.name }} ${{ matrix.bin }}
fi
cd -
- name: Generate SHA-256 (MacOS)
if: runner.os == 'macOS'
if: matrix.target == 'x86_64-apple-darwin' || matrix.target == 'aarch64-apple-darwin'
run: shasum -a 256 ${{ matrix.name }}
- name: Publish
if: startsWith(github.ref, 'refs/tags/')
Expand Down

0 comments on commit 935c251

Please sign in to comment.