Skip to content

Commit

Permalink
ci: use macos-lastest and support target Windows aarch64 (#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangl-cc authored Dec 24, 2024
1 parent cca2fc3 commit 3629373
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 44 deletions.
10 changes: 9 additions & 1 deletion .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ runs:
;;
esac
echo "CARGO_BUILD_TARGET=$target" >> $GITHUB_ENV
- name: Setup Cross Compiling Toolchain (Rust)
- name: Setup Rust Target
if: inputs.host_arch != inputs.target_arch
shell: bash
run: rustup target add $CARGO_BUILD_TARGET
Expand All @@ -57,3 +57,11 @@ runs:
echo "AR_aarch64_unknown_linux_gnu=aarch64-linux-gnu-ar" >> $GITHUB_ENV
echo "CFLAGS_aarch64_unknown_linux_gnu=--sysroot=/usr/aarch64-linux-gnu" >> $GITHUB_ENV
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
- name: Setup Cross Compiling Toolchain (LLVM for aarch64 on x86_64 Windows)
if: >
inputs.target_arch == 'aarch64' &&
inputs.host_arch == 'x86_64' &&
startsWith(inputs.os, 'windows')
shell: powershell
run: |
Add-Content $env:GITHUB_PATH "C:\Program Files (x86)\Microsoft Visual Studio\2022\Enterprise\VC\Tools\Llvm\x64\bin"
11 changes: 6 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
os:
- ubuntu-latest
- macos-13 # x86_64 runner
- macos-14 # aarch64 runner
- macos-latest # aarch64 runner
- windows-latest
env:
MAA_EXTRA_SHARE_NAME: maa-test
Expand All @@ -65,7 +65,7 @@ jobs:
env:
MAA_CONFIG_DIR: ${{ github.workspace }}/maa-cli/config_examples
run: |
cargo run -- install beta
cargo run -- install beta
core_dir=$(cargo run -- dir library)
resource_dir=$(cargo run -- dir resource)
cache_dir=$(cargo run -- dir cache)
Expand Down Expand Up @@ -95,6 +95,7 @@ jobs:
matrix:
os:
- ubuntu-latest
- windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -116,7 +117,7 @@ jobs:
matrix:
os:
- ubuntu-latest
- macos-14
- macos-latest
- windows-latest
feature:
- core_installer # disabled cli_installer and git2, used by package manager
Expand All @@ -143,7 +144,7 @@ jobs:
os:
- ubuntu-latest
- macos-13 # x86_64 runner
- macos-14 # aarch64 runner
- macos-latest # aarch64 runner
- windows-latest
steps:
- name: Checkout
Expand Down Expand Up @@ -174,7 +175,7 @@ jobs:
matrix:
os:
- ubuntu-latest
- macos-14 # aarch64 runner
- macos-latest # aarch64 runner
- windows-latest
env:
MAA_EXTRA_SHARE_NAME: maa-test
Expand Down
57 changes: 19 additions & 38 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,27 +111,28 @@ jobs:
os:
- ubuntu-latest
- windows-latest
arch:
host-arch:
- x86_64
target-arch:
- x86_64
- aarch64
# macOS can be natively built on both x86_64 and aarch64
include:
- os: macos-13 # x86_64 runner
arch: x86_64
- os: macos-14 # aaarch64 runner
arch: aarch64
exclude:
# Failed to cross compile ring on Windows
- os: windows-latest
arch: aarch64
- os: macos-13
host-arch: x86_64
target-arch: x86_64
- os: macos-latest
host-arch: aarch64
target-arch: aarch64
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Cross Compilation Toolchains
uses: ./.github/actions/setup
with:
os: ${{ matrix.os }}
host_arch: ${{ matrix.os == 'macos-14' && 'aarch64' || 'x86_64' }}
target_arch: ${{ matrix.arch }}
host_arch: ${{ matrix.host-arch }}
target_arch: ${{ matrix.target-arch }}
- name: Build
env:
CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 1
Expand All @@ -142,18 +143,18 @@ jobs:
cargo build --release --package maa-cli --locked --features vendored-openssl
- name: Tar Artifact
env:
TARGET_OS: ${{ matrix.os }}
TARGET_ARCH: ${{ matrix.arch }}
OS: ${{ matrix.os }}
IS_CROSS: ${{ matrix.host-arch != matrix.target-arch }}
run: |
target_dir="target/$CARGO_BUILD_TARGET/release"
if [[ "$TARGET_OS" == "windows"* ]]; then
if [[ "$OS" == "windows"* ]]; then
exe="maa.exe"
else
exe="maa"
fi
file "$target_dir/$exe" # check file status
# dry run if not cross compiling
if [[ "$TARGET_ARCH" == "x86_64" || "$TARGET_OS" == "macos-14" ]]; then
if [[ "$IS_CROSS" == "false" ]]; then
"$target_dir/$exe" --version
fi
tar -cvf "$CARGO_BUILD_TARGET.tar" -C "$target_dir" "$exe"
Expand All @@ -168,7 +169,7 @@ jobs:
build-universal:
name: Build Universal Binary
if: ${{ !fromJson(needs.meta.outputs.skip) }}
runs-on: macos-14
runs-on: macos-latest
needs: [meta, build]
steps:
# download all artifacts, even if not all are used,
Expand Down Expand Up @@ -230,17 +231,8 @@ jobs:
yq -i -oj ".details.commit = \"$COMMIT\"" "$version_file"
done
targets=(
x86_64-unknown-linux-gnu
aarch64-unknown-linux-gnu
universal-apple-darwin
x86_64-apple-darwin
aarch64-apple-darwin
x86_64-pc-windows-msvc
)
for target in "${targets[@]}"; do
dir="maa_cli-$target"
for dir in maa_cli-*; do
target=${dir#maa_cli-}
tar -xvf "$dir/$target.tar" -C "$dir"
# use tar on linux and zip on other platforms
case "$target" in
Expand Down Expand Up @@ -273,17 +265,6 @@ jobs:
echo "$checksum" > "$archive_name.sha256"
sha256sum "$archive_name_unversioned" > "$archive_name_unversioned.sha256"
# old version info (deprecated)
# only update when a stable release is published
if [ "$CHANNEL" == "stable" ]; then
version_file="version/version.json"
yq -i -oj ".maa-cli.$target.version = \"$VERSION\"" "$version_file"
yq -i -oj ".maa-cli.$target.tag = \"$TAG\"" "$version_file"
yq -i -oj ".maa-cli.$target.name = \"$archive_name\"" "$version_file"
yq -i -oj ".maa-cli.$target.size = $size" $version_file
yq -i -oj ".maa-cli.$target.sha256sum = \"$checksum_hash\"" "$version_file"
fi
# target dependent version info
for version_file in "${version_files[@]}"; do
yq -i -oj ".details.assets.$target.name = \"$archive_name\"" "$version_file"
Expand Down

0 comments on commit 3629373

Please sign in to comment.