Skip to content

Update packaging and CI #277

Update packaging and CI

Update packaging and CI #277

Workflow file for this run

name: Rust
on:
push:
branches:
- master
tags:
- '[0-9]+.[0-9]+.[0-9]+'
pull_request:
env:
SDK_BUILD_TOOLS_VERSION: '34.0.0'
NDK_VERSION: '25.2.9519653'
ANDROID_PLATFORM: '34'
jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Setup Rust
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
components: rustfmt
- uses: Swatinem/rust-cache@v2
- name: Format
run: cargo fmt --all -- --check
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Setup Rust
uses: dtolnay/rust-toolchain@v1
with:
toolchain: nightly
targets: x86_64-linux-android
components: rust-docs
- uses: Swatinem/rust-cache@v2
- name: Documentation
env:
DOCS_RS: 1
run: cargo doc --target x86_64-linux-android --features java-interface,doc-cfg
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Setup Android SDK
uses: android-actions/setup-android@v3
with:
log-accepted-android-sdk-licenses: false
packages: build-tools;${{ env.SDK_BUILD_TOOLS_VERSION }} ndk;${{ env.NDK_VERSION }} platforms;android-${{ env.ANDROID_PLATFORM }}
- name: Config Android NDK
env:
TRIPLE: x86_64-linux-android
run: |
echo "$ANDROID_SDK_ROOT/ndk/$NDK_VERSION/toolchains/llvm/prebuilt/linux-x86_64/bin" >> $GITHUB_PATH
for var in ANDROID_NDK ANDROID_NDK_HOME ANDROID_NDK_LATEST_HOME ANDROID_NDK_ROOT NDK_HOME; do
echo "$var=$ANDROID_SDK_ROOT/ndk/$NDK_VERSION" >> $GITHUB_ENV
done
TRIPLE_ENV=$(echo $TRIPLE | tr '-' '_')
echo "CC_${TRIPLE_ENV}=${TRIPLE}21-clang" >> $GITHUB_ENV
echo "CXX_${TRIPLE_ENV}=${TRIPLE}21-clang++" >> $GITHUB_ENV
echo "AR_${TRIPLE_ENV}=llvm-ar" >> $GITHUB_ENV
- uses: dtolnay/rust-toolchain@v1
with:
toolchain: nightly
target: x86_64-linux-android
components: clippy
- uses: Swatinem/rust-cache@v2
- run: cargo clippy --all --features java-interface --all-targets --target x86_64-linux-android
build:
needs:
- format
- docs
- check
- cargo-ndk
runs-on: ubuntu-latest
strategy:
fail-fast: ${{ github.event_name == 'pull_request' || startsWith(github.ref, 'refs/tags/') }}
matrix:
rust:
- stable
- nightly
profile:
- debug
- release
target:
- armv7-linux-androideabi
- aarch64-linux-android
- i686-linux-android
- x86_64-linux-android
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Setup Android SDK
uses: android-actions/setup-android@v3
with:
log-accepted-android-sdk-licenses: false
packages: build-tools;${{ env.SDK_BUILD_TOOLS_VERSION }} ndk;${{ env.NDK_VERSION }} platforms;android-${{ env.ANDROID_PLATFORM }}
- name: Config Android NDK
run: |
echo "$ANDROID_SDK_ROOT/ndk/$NDK_VERSION/toolchains/llvm/prebuilt/linux-x86_64/bin" >> $GITHUB_PATH
for var in ANDROID_NDK ANDROID_NDK_HOME ANDROID_NDK_LATEST_HOME ANDROID_NDK_ROOT NDK_HOME; do
echo "$var=$ANDROID_SDK_ROOT/ndk/$NDK_VERSION" >> $GITHUB_ENV
done
- name: Setup Rust ${{ matrix.rust }} [${{ matrix.target }}]
uses: dtolnay/rust-toolchain@v1
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
components: rustfmt
- name: Setup Cargo ndk
uses: actions/cache@v4
with:
path: ~/.cargo/bin/cargo-ndk
key: ${{ runner.os }}-cargo-ndk
- uses: Swatinem/rust-cache@v2
- name: Prepare config
id: config
run: |
echo "android-target=$(case "${{ matrix.target }}" in
armv7-linux-androideabi) printf armeabi-v7a;;
aarch64-linux-android) printf arm64-v8a;;
i686-linux-android) printf x86;;
x86_64-linux-android) printf x86_64;;
esac)" >> $GITHUB_OUTPUT
if [[ "${{ matrix.target }}" =~ "64" ]]; then
echo "android-api=21" >> $GITHUB_OUTPUT
else
echo "android-api=19" >> $GITHUB_OUTPUT
fi
if [[ "${{ matrix.profile }}" == "release" ]]; then
echo "cargo-args=--release" >> $GITHUB_OUTPUT
else
echo "cargo-args=" >> $GITHUB_OUTPUT
fi
- name: Build target ${{ matrix.target }}
run: cargo ndk --platform ${{ steps.config.outputs.android-api }} --target ${{ steps.config.outputs.android-target }} --bindgen -- build ${{ steps.config.outputs.cargo-args }} --features generate-bindings
- name: Get latest build path
id: result
run: |
echo "build-path=$(ls -td target/${{ matrix.target }}/${{ matrix.profile }}/build/oboe-sys-*/ | head -1)" >> $GITHUB_OUTPUT
- name: Copy bindings
if: matrix.rust == 'stable' && matrix.profile == 'release'
run: |
mkdir -p bindings
cp ${{ steps.result.outputs.build-path }}out/bindings.rs bindings/bindings_$(echo ${{ matrix.target }} | sed -r 's/^([^-]+).*$/\1/').rs
- name: Upload bindings
if: matrix.rust == 'stable' && matrix.profile == 'release'
uses: actions/upload-artifact@v4
with:
name: bindings-${{ matrix.target }}
path: bindings
overwrite: true
- name: Archive library
if: matrix.rust == 'stable'
run: tar -czf liboboe-ext_${{ matrix.target }}_${{ matrix.profile }}.tar.gz -C ${{ steps.result.outputs.build-path }}/out/library liboboe-ext.a
- name: Upload library
if: matrix.rust == 'stable'
uses: actions/upload-artifact@v4
with:
name: library-${{ matrix.target }}-${{ matrix.profile }}
path: liboboe-ext_${{ matrix.target }}_${{ matrix.profile }}.tar.gz
overwrite: true
update-bindings:
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
needs:
- build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Download bindings
uses: actions/download-artifact@v4
with:
pattern: bindings-*
merge-multiple: true
path: sys/src
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
base: ${{ github.head_ref }}
commit-message: Updated bindings
branch: update-bindings
delete-branch: true
title: Update bindings
body: |
Bindings should be updated to be consistent with latest changes
build-demo:
needs:
- build
- cargo-mobile2
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Setup Android SDK
uses: android-actions/setup-android@v3
with:
log-accepted-android-sdk-licenses: false
packages: build-tools;${{ env.SDK_BUILD_TOOLS_VERSION }} ndk;${{ env.NDK_VERSION }} platforms;android-${{ env.ANDROID_PLATFORM }}
- name: Config Android NDK
run: |
echo "$ANDROID_SDK_ROOT/ndk/$NDK_VERSION/toolchains/llvm/prebuilt/linux-x86_64/bin" >> $GITHUB_PATH
for var in ANDROID_NDK ANDROID_NDK_HOME ANDROID_NDK_LATEST_HOME ANDROID_NDK_ROOT NDK_HOME; do
echo "$var=$ANDROID_SDK_ROOT/ndk/$NDK_VERSION" >> $GITHUB_ENV
done
- name: Setup Rust
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
targets: armv7-linux-androideabi aarch64-linux-android i686-linux-android x86_64-linux-android
- name: Setup Cargo mobile
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/cargo-android
~/.cargo/bin/cargo-mobile
~/.cargo/.cargo-mobile2
key: ${{ runner.os }}-cargo-mobile2
- uses: Swatinem/rust-cache@v2
- name: Create signing key
run: |
if [ -z "${{ secrets.APK_KEYSTORE_PASSWORD }}" ]; then
# create temporary keystore to sign apk
rm -f demo/release.keystore
keytool -genkey -dname "cn=Nobrand, ou=RnD, o=example.com, c=US" -v -keystore demo/release.keystore -alias demo -keyalg RSA -keysize 2048 -validity 20000 -storepass android
else
# use existing keystore to sign apk
sed -i 's/keystore_password = "android"/keystore_password = "${{ secrets.APK_KEYSTORE_PASSWORD }}"/' demo/Cargo.toml
fi
- name: Init demo apk
run: |
cd demo && cargo mobile init && sed -ri 's/((compile|target)Sdk *= *)33/\134/g' gen/android/app/build.gradle.kts
- name: Build demo apk
run: cd demo && cargo mobile android apk build --release --split-per-abi
- name: Upload demo apk
uses: actions/upload-artifact@v4
with:
name: apk
path: demo/gen/android/app/build/outputs/apk/*/release/*.apk
release:
if: github.repository == 'katyo/oboe-rs' && startsWith(github.ref, 'refs/tags/')
needs:
- build
- build-demo
runs-on: ubuntu-latest
steps:
- name: Download libraries
uses: actions/download-artifact@v4
with:
pattern: library-*
merge-multiple: true
- name: Download demo
uses: actions/download-artifact@v4
with:
name: apk
- name: Create release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: |
*.tar.gz
*.apk
#prerelease: true
#draft: true
fail_on_unmatched_files: true
publish:
if: github.repository == 'katyo/oboe-rs' && startsWith(github.ref, 'refs/tags/')
needs:
- release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Setup Rust
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
- name: Publish crates
uses: katyo/publish-crates@v1
with:
registry-token: ${{ secrets.CRATES_TOKEN }}
args: --no-verify
#dry-run: true
cargo-ndk:
runs-on: ubuntu-latest
steps:
- name: Prepare cache
uses: actions/cache@v4
id: cache
with:
path: ~/.cargo/bin/cargo-ndk
key: ${{ runner.os }}-cargo-ndk
- name: Setup cargo ndk
if: steps.cache.outputs.cache-hit != 'true'
run: cargo install cargo-ndk --force
cargo-mobile2:
runs-on: ubuntu-latest
steps:
- name: Prepare cache
uses: actions/cache@v4
id: cache
with:
path: |
~/.cargo/bin/cargo-android
~/.cargo/bin/cargo-mobile
~/.cargo/.cargo-mobile2
key: ${{ runner.os }}-cargo-mobile2
- name: Setup cargo mobile2
if: steps.cache.outputs.cache-hit != 'true'
run: cargo install cargo-mobile2