-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: cross-compilation for aarch64 on macOS and Linux
- Loading branch information
Showing
2 changed files
with
125 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,35 +3,59 @@ on: | |
push: | ||
tags: | ||
- "v[0-9]+.[0-9]+.[0-9]+" | ||
# Just used for testing | ||
pull_request: | ||
branches: | ||
- main | ||
paths: | ||
- ".github/workflows/release.yml" | ||
workflow_dispatch: | ||
|
||
jobs: | ||
linux-gnu: | ||
runs-on: ubuntu-latest | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
permissions: | ||
contents: write | ||
defaults: | ||
run: | ||
shell: bash | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
targets: | ||
- x86_64-unknown-linux-gnu | ||
- aarch64-unknown-linux-gnu | ||
env: | ||
CARGO_BUILD_TARGET: ${{ matrix.targets }} | ||
os: | ||
- ubuntu-latest | ||
- macos-latest | ||
# - windows-latest | ||
arch: | ||
- x86_64 | ||
- aarch64 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup Rust | ||
run: | | ||
rustup target add $CARGO_BUILD_TARGET | ||
- name: Setup cross-compilation for aarch64 | ||
if: matrix.targets == 'aarch64-unknown-linux-gnu' | ||
- name: Install Cross | ||
if: matrix.arch == 'aarch64' && matrix.os == 'ubuntu-latest' | ||
uses: taiki-e/install-action@v2 | ||
with: | ||
tool: cross | ||
- name: Setup environment | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y gcc-aarch64-linux-gnu | ||
if [ "${{ matrix.os }}" = "macos-latest" ]; then | ||
CARGO_CMD=cargo | ||
CARGO_BUILD_TARGET="${{ matrix.arch }}-apple-darwin" | ||
rustup target add $CARGO_BUILD_TARGET | ||
else | ||
if [ "${{ matrix.arch }}" = "aarch64" ]; then | ||
CARGO_CMD=cross | ||
else | ||
CARGO_CMD=cargo | ||
fi | ||
CARGO_BUILD_TARGET="${{ matrix.arch }}-unknown-linux-gnu" | ||
fi | ||
echo "CARGO_CMD=$CARGO_CMD" >> $GITHUB_ENV | ||
echo "CARGO_BUILD_TARGET=$CARGO_BUILD_TARGET" >> $GITHUB_ENV | ||
- name: Build | ||
run: | | ||
cargo build --release --locked --bin maa | ||
$CARGO_CMD build --release --locked --package maa-cli | ||
- name: Checkout version branch | ||
uses: actions/checkout@v3 | ||
with: | ||
|
@@ -42,54 +66,62 @@ jobs: | |
run: | | ||
version_file="$PWD/version/version.json" | ||
target="$CARGO_BUILD_TARGET" | ||
maa_cli_version=$(yq -oy ".package.version" maa-cli/Cargo.toml) | ||
cd target/x86_64-unknown-linux-gnu/release || exit 1 | ||
version=$maa_cli_version | ||
version=$(yq -oy ".package.version" maa-cli/Cargo.toml) | ||
cd "target/$target/release" || exit 1 | ||
if [ "${{ matrix.os }}" == "ubuntu-latest" ]; then | ||
archive_name="maa_cli-v$version-$target.tar.gz" | ||
tar -czvf $archive_name maa && | ||
checksum=$(shasum -a 256 $archive_name) && | ||
echo "$checksum" > $archive_name.sha256sum && | ||
yq -i -oj ".maa-cli.$target.version = \"$version\"" $version_file && | ||
yq -i -oj ".maa-cli.$target.tag = \"v$version\"" $version_file && | ||
yq -i -oj ".maa-cli.$target.name = \"$archive_name\"" $version_file && | ||
yq -i -oj ".maa-cli.$target.size = $(stat -c %s $archive_name)" $version_file && | ||
yq -i -oj ".maa-cli.$target.sha256sum = \"$(echo $checksum | cut -d ' ' -f 1)\"" $version_file && | ||
echo "name=v$version" >> $GITHUB_OUTPUT && | ||
exit 0 | ||
tar -czvf $archive_name maa || exit 1 | ||
yq -i -oj ".maa-cli.$target.size = $(stat -c %s $archive_name)" $version_file | ||
else | ||
archive_name="maa_cli-v$version-$target.zip" | ||
zip $archive_name maa || exit 1 | ||
yq -i -oj ".maa-cli.$target.size = $(stat -f %z $archive_name)" $version_file | ||
fi | ||
checksum="$(shasum -a 256 $archive_name)" | ||
echo "$checksum" > $archive_name.sha256sum | ||
yq -i -oj ".maa-cli.$target.version = \"$version\"" $version_file | ||
yq -i -oj ".maa-cli.$target.tag = \"v$version\"" $version_file | ||
yq -i -oj ".maa-cli.$target.name = \"$archive_name\"" $version_file | ||
yq -i -oj ".maa-cli.$target.sha256sum = \"$(echo $checksum | cut -d ' ' -f 1)\"" $version_file | ||
echo "name=v$version" >> $GITHUB_OUTPUT | ||
- name: Upload to GitHub Releases | ||
if: github.event_name == 'push' && github.ref == 'refs/tags/v*' | ||
uses: svenstaro/upload-release-action@v2 | ||
with: | ||
release_name: ${{ steps.archive.outputs.name }} | ||
repo_token: ${{ secrets.GITHUB_TOKEN }} | ||
file_glob: true | ||
file: target/x86_64-unknown-linux-gnu/release/maa*.tar.gz* | ||
file: target/*/release/maa.*z* | ||
overwrite: true | ||
- name: Commit and push version.json | ||
if: github.event_name == 'push' && github.ref == 'refs/tags/v*' | ||
run: | | ||
cd version || exit 1 | ||
git config --local user.name "github-actions[bot]" | ||
git config --local user.email "github-actions[bot]@users.noreply.github.com" | ||
if [ -z "$(git diff version.json)" ]; then | ||
echo "No changes to commit" | ||
exit 0 | ||
exit 1 | ||
fi | ||
git commit version.json -m "Update version.json" && | ||
git push | ||
universal-apple-darwin: | ||
runs-on: macos-latest | ||
needs: build | ||
permissions: | ||
contents: write | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup Rust | ||
- name: Get tag | ||
run: | | ||
rustup target add x86_64-apple-darwin | ||
rustup target add aarch64-apple-darwin | ||
- name: Build | ||
run: | | ||
cargo build --release --locked --bin maa --target x86_64-apple-darwin --target aarch64-apple-darwin | ||
echo "MAA_CLI_VERSION=$(yq -oy ".package.version" maa-cli/Cargo.toml)" >> $GITHUB_ENV | ||
- name: Download artifacts from GitHub Release | ||
uses: robinraju/[email protected] | ||
with: | ||
tag: "v${{ env.MAA_CLI_VERSION }}" | ||
filename: maa_cli-v${{ env.MAA_CLI_VERSION }}-*-apple-darwin.zip | ||
- name: Checkout version branch | ||
uses: actions/checkout@v3 | ||
with: | ||
|
@@ -99,10 +131,12 @@ jobs: | |
id: archive | ||
run: | | ||
version_file="$PWD/version/version.json" | ||
maa_cli_version=$(yq -oy ".package.version" maa-cli/Cargo.toml) | ||
version=$MAA_CLI_VERSION | ||
for arch in x86_64 aarch64; do | ||
mkdir -p "arch-apple-darwin" | ||
unzip maa_cli-v$version-$arch-apple-darwin.zip -d arch-apple-darwin | ||
done | ||
target="universal-apple-darwin" | ||
cd target || exit 1 | ||
version=$maa_cli_version | ||
archive_name="maa_cli-v$version-$target.zip" | ||
lipo -create -output maa x86_64-apple-darwin/release/maa aarch64-apple-darwin/release/maa && | ||
zip $archive_name maa && | ||
|
@@ -117,12 +151,14 @@ jobs: | |
exit 0 | ||
- name: Upload to GitHub Releases | ||
uses: svenstaro/upload-release-action@v2 | ||
if: github.event_name == 'push' && github.ref == 'refs/tags/v*' | ||
with: | ||
repo_token: ${{ secrets.GITHUB_TOKEN }} | ||
file_glob: true | ||
file: target/maa*.zip* | ||
overwrite: true | ||
- name: Commit and push version.json | ||
if: github.event_name == 'push' && github.ref == 'refs/tags/v*' | ||
run: | | ||
cd version || exit 1 | ||
git config --local user.name "github-actions[bot]" | ||
|
@@ -132,70 +168,3 @@ jobs: | |
exit 0 | ||
fi | ||
git commit version.json -m "Update version.json" && git push | ||
# windows-msvc: | ||
# runs-on: windows-latest | ||
# permissions: | ||
# contents: write | ||
# strategy: | ||
# fail-fast: false | ||
# matrix: | ||
# targets: | ||
# - x86_64-pc-windows-msvc | ||
# - aarch64-pc-windows-msvc | ||
# env: | ||
# CARGO_BUILD_TARGET: ${{ matrix.targets }} | ||
# steps: | ||
# - name: Checkout | ||
# uses: actions/checkout@v3 | ||
# - name: Setup Rust | ||
# shell: bash | ||
# run: | | ||
# rustup target add $CARGO_BUILD_TARGET | ||
# - name: Build | ||
# shell: bash | ||
# run: | | ||
# cargo build --release --locked --bin maa | ||
# - name: Checkout version branch | ||
# uses: actions/checkout@v3 | ||
# with: | ||
# ref: version | ||
# path: version | ||
# - name: Archive binaries, generate checksums and update version.json | ||
# id: archive | ||
# shell: bash | ||
# run: | | ||
# version_file="$PWD/version/version.json" | ||
# target="$CARGO_BUILD_TARGET" | ||
# maa_cli_version=$(yq -oy ".package.version" maa-cli/Cargo.toml) | ||
# cd target/x86_64-pc-windows-msvc/release || exit 1 | ||
# version=$maa_cli_version | ||
# archive_name="maa_cli-v$version-$target.zip" | ||
# zip $archive_name maa.exe && | ||
# checksum=$(shasum -a 256 $archive_name) && | ||
# echo "$checksum" > $archive_name.sha256sum && | ||
# yq -i -oj ".maa-cli.$target.version = \"$version\"" $version_file && | ||
# yq -i -oj ".maa-cli.$target.tag = \"v$version\"" $version_file && | ||
# yq -i -oj ".maa-cli.$target.name = \"$archive_name\"" $version_file && | ||
# yq -i -oj ".maa-cli.$target.size = $(stat -c %s $archive_name)" $version_file && | ||
# yq -i -oj ".maa-cli.$target.sha256sum = \"$(echo $checksum | cut -d ' ' -f 1)\"" $version_file && | ||
# echo "name=v$version" >> $GITHUB_OUTPUT && | ||
# exit 0 | ||
# - name: Upload to GitHub Releases | ||
# uses: svenstaro/upload-release-action@v2 | ||
# with: | ||
# repo_token: ${{ secrets.GITHUB_TOKEN }} | ||
# file_glob: true | ||
# file: target/x86_64-pc-windows-msvc/release/maa*.zip* | ||
# overwrite: true | ||
# - name: Commit and push version.json | ||
# shell: bash | ||
# run: | | ||
# cd version || exit 1 | ||
# git config --local user.name "github-actions[bot]" | ||
# git config --local user.email "github-actions[bot]@users.noreply.github.com" | ||
# if [ -z "$(git diff version.json)" ]; then | ||
# echo "No changes to commit" | ||
# exit 0 | ||
# fi | ||
# git commit version.json -m "Update version.json" && git push |