Update rust.yml #21
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
name: Build | |
permissions: {} | |
on: | |
pull_request: | |
push: | |
branches: | |
- main | |
env: | |
# Disable incremental compilation for faster from-scratch builds | |
CARGO_INCREMENTAL: 0 | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [windows-latest, ubuntu-latest, macos-latest] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Rust | |
run: rustup update | |
# Regular build steps for desktop platforms | |
- name: Build for Desktop Platforms | |
run: cargo build --release | |
# Cleanup steps for Windows | |
- name: Clean up target directory (Windows only) | |
if: runner.os == 'Windows' | |
run: | | |
Remove-Item -Path "target\release\build" -Recurse -Force | |
Remove-Item -Path "target\release\deps" -Recurse -Force | |
Remove-Item -Path "target\release\examples" -Recurse -Force | |
Remove-Item -Path "target\release\incremental" -Recurse -Force | |
Remove-Item -Path "target\CACHEDIR.TAG" -Force | |
Remove-Item -Path "target\.rustc_info.json" -Force | |
Remove-Item -Path "target\release\.fingerprint" -Recurse -Force | |
Remove-Item -Path "target\release\.cargo-lock" -Force | |
# Cleanup steps for macOS and Linux | |
- name: Clean up target directory (macOS and Linux only) | |
if: runner.os != 'Windows' | |
run: | | |
rm -rf target/release/build | |
rm -rf target/release/deps | |
rm -rf target/release/examples | |
rm -rf target/release/incremental | |
rm -f target/CACHEDIR.TAG | |
rm -f target/.rustc_info.json | |
rm -rf target/release/.fingerprint | |
rm -f target/release/.cargo-lock | |
# Upload Artifact | |
- name: Upload Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build-${{ matrix.os }} | |
path: target/ | |
build-android: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Check out the code from the repository | |
- uses: actions/checkout@v4 | |
# Step 2: Set up Rust toolchain | |
- name: Set up Rust | |
run: rustup update | |
# Step 3: Install Android NDK | |
- name: Install Android NDK | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y wget unzip | |
wget https://dl.google.com/android/repository/android-ndk-r23b-linux.zip -O ndk.zip | |
unzip ndk.zip -d $HOME | |
echo "ANDROID_NDK_HOME=$HOME/android-ndk-r23b" >> $GITHUB_ENV | |
echo "$HOME/android-ndk-r23b/toolchains/llvm/prebuilt/linux-x86_64/bin" >> $GITHUB_PATH | |
# Step 4: Install Rust target for Android | |
- name: Add Android target | |
run: rustup target add aarch64-linux-android | |
# Step 5: Build for Android using Cross | |
- name: Build for Android | |
run: | | |
cargo install cross --git https://github.com/cross-rs/cross | |
cross build --release --target aarch64-linux-android | |
# Step 6: Clean up target directory (Android) | |
- name: Clean up target directory (Android) | |
run: | | |
rm -rf target/release/build | |
rm -rf target/release/deps | |
rm -rf target/release/examples | |
rm -rf target/release/incremental | |
rm -f target/CACHEDIR.TAG | |
rm -f target/.rustc_info.json | |
rm -rf target/release/.fingerprint | |
rm -f target/release/.cargo-lock | |
# Step 7: Upload Artifact for Android | |
- name: Upload Artifact for Android | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build-android | |
path: target/ | |
build-ios: | |
runs-on: macos-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Rust | |
run: rustup update | |
# Install Rust target for iOS | |
- name: Add iOS target | |
run: rustup target add aarch64-apple-ios | |
# Build for iOS | |
- name: Build for iOS | |
run: cargo build --release --target aarch64-apple-ios | |
# Cleanup steps for iOS | |
- name: Clean up target directory (iOS) | |
run: | | |
rm -rf target/aarch64-apple-ios/release/build | |
rm -rf target/aarch64-apple-ios/release/deps | |
rm -rf target/release/examples | |
rm -rf target/release/incremental | |
rm -f target/aarch64-apple-ios/CACHEDIR.TAG | |
rm -f target/CACHEDIR.TAG | |
rm -f target/.rustc_info.json | |
rm -rf target/aarch64-apple-ios/release/.fingerprint | |
rm -f target/aarch64-apple-ios/release/.cargo-lock | |
rm -rf target/release | |
# Upload Artifact | |
- name: Upload Artifact for iOS | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build-ios | |
path: target/ |