From 5511dfccc66536d23a7a8d79a182559875e2adc4 Mon Sep 17 00:00:00 2001 From: cavivie Date: Tue, 9 Apr 2024 18:42:36 +0800 Subject: [PATCH] feat(ci): support to test and build targets via github ci --- .github/actions/ndk-dev-rs/action.yml | 37 +++++++++ .github/workflows/main.yml | 108 ++++++++++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 .github/actions/ndk-dev-rs/action.yml create mode 100644 .github/workflows/main.yml diff --git a/.github/actions/ndk-dev-rs/action.yml b/.github/actions/ndk-dev-rs/action.yml new file mode 100644 index 0000000..93b1eea --- /dev/null +++ b/.github/actions/ndk-dev-rs/action.yml @@ -0,0 +1,37 @@ +name: Setup Android NDK and Rust compiler ENV +description: Setup an Android_NDK_HOME environment by downloading and Rust compiler environment. +inputs: + rust-target: + description: Rust target to build + required: true + sdk-version: + description: Exact SDK version to use + default: "33" + ndk-version: + description: Exact NDK version to use + default: "25" + ndk-platform: + description: Which host platform to use + default: "linux" +runs: + using: "composite" + steps: + - name: Download Android NDK + run: curl --http1.1 -O https://dl.google.com/android/repository/android-ndk-r${{ inputs.ndk-version }}-${{ inputs.ndk-platform }}.zip + shell: bash + - name: Extract Android NDK + run: unzip -q android-ndk-r${{ inputs.ndk-version }}-${{ inputs.ndk-platform }}.zip + shell: bash + - name: Set Rust compiler ENV + run: | + ndk_home=${{ github.workspace }}/android-ndk-r${{ inputs.ndk-version }} + platform=$(ls ${ndk_home}/toolchains/llvm/prebuilt/ | head -1) + ndk_tool=${ndk_home}/toolchains/llvm/prebuilt/${platform}/bin + envvar_suffix=$(echo ${{ inputs.rust-target }} | sed "s/-/_/g") + upper_suffix=$(echo ${envvar_suffix} | tr '[:lower:]' '[:upper:]') + tool_prefix=${{ inputs.rust-target }}${{ inputs.sdk-version }} + echo "ANDROID_NDK_HOME=${ndk_home}" >> $GITHUB_ENV + echo "CC_${envvar_suffix}=${ndk_tool}/${tool_prefix}-clang" >> $GITHUB_ENV + echo "AR_${envvar_suffix}=${ndk_tool}/llvm-ar" >> $GITHUB_ENV + echo "CARGO_TARGET_${upper_suffix}_LINKER=${ndk_tool}/${tool_prefix}-clang" >> $GITHUB_ENV + shell: bash diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..6722beb --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,108 @@ +name: CI +on: [push, pull_request] + +env: + CARGO_INCREMENTAL: 0 + CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse + +jobs: + test: + name: Test + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - build: linux-amd64 + os: ubuntu-latest + target: x86_64-unknown-linux-gnu + - build: android-arm64 + os: ubuntu-latest + target: aarch64-linux-android + no_run: --no-run + - build: android-amd64 + os: ubuntu-latest + target: x86_64-linux-android + no_run: --no-run + - build: macos-amd64 + os: macos-latest + target: x86_64-apple-darwin + - build: macos-arm64 + os: macos-14 + target: aarch64-apple-darwin + - build: ios-arm64 + os: macos-latest + target: aarch64-apple-ios + no_run: --no-run + - build: windows-amd64 + os: windows-latest + target: x86_64-pc-windows-msvc + - build: windows-arm64 + os: windows-latest + target: aarch64-pc-windows-msvc + no_run: --no-run + steps: + - uses: actions/checkout@v4 + - name: Install Rust (rustup) + run: | + set -euxo pipefail + rustup toolchain install stable --no-self-update --profile minimal --target ${{ matrix.target }} + rustup default stable + shell: bash + - uses: Swatinem/rust-cache@v2 + - name: Setup android environment + uses: ./.github/actions/ndk-dev-rs + with: + rust-target: ${{ matrix.target }} + if: contains(matrix.build, 'android') + - run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} + - run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release + + msrv: + name: MSRV + runs-on: ${{ matrix.os }} + env: + MSRV: 1.65.0 + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + steps: + - uses: actions/checkout@v4 + - name: Install Rust + run: | + rustup toolchain install $MSRV --no-self-update --profile minimal + rustup toolchain install nightly --no-self-update --profile minimal + rustup default $MSRV + shell: bash + - name: Create Cargo.lock with minimal version + run: cargo +nightly update -Zminimal-versions + - name: Cache downloaded crates since minimal version is really slow in fetching + uses: Swatinem/rust-cache@v2 + - run: cargo check --lib -p netstack-smoltcp --locked + - run: cargo check --lib -p netstack-smoltcp --locked --all-features + + clippy: + name: Clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Rust + run: | + rustup toolchain install stable --no-self-update --profile minimal --component rustfmt + rustup default stable + shell: bash + - uses: Swatinem/rust-cache@v2 + - run: cargo clippy + + rustfmt: + name: Rustfmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Rust + run: | + rustup toolchain install stable --no-self-update --profile minimal --component rustfmt + rustup default stable + shell: bash + - uses: Swatinem/rust-cache@v2 + - run: cargo fmt -- --check