diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml index 786356e53..889f8d3dd 100644 --- a/.github/workflows/audit.yml +++ b/.github/workflows/audit.yml @@ -7,7 +7,7 @@ on: jobs: audit: name: Rust Audit - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - name: Checkout repository uses: actions/checkout@v2 @@ -16,8 +16,7 @@ jobs: - name: Run rust-audit id: rust-audit - run: | - cargo audit --deny warnings + run: cargo audit --deny warnings - name: Notify on Slack uses: 8398a7/action-slack@v3 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2f028be70..8080b611a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,17 +1,27 @@ +# You can find more information about the design decisions here: +# https://github.com/xaynetwork/xayn_ai/pull/21 + name: Rust-CI -on: +on: push: env: RUST_STABLE: 1.49.0 RUST_NIGHTLY: nightly-2021-01-31 + CARGO_NDK: 2.2.0 + ANDROID_PLATFORM_VERSION: 21 + CARGO_LIPO: 3.1.1 + # cmd: shasum -a 256 cross + CROSS_CHECKSUM: 18a3599273773a7d1e333b413751f0adc1a83ec8045d060fee4f0639bd6baaf0 jobs: registry-cache: + # we use the latest stable rustc + cargo version that is already installed on the image + # https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-README.md#rust-tools name: cargo-fetch + runs-on: ubuntu-20.04 timeout-minutes: 5 - runs-on: ubuntu-latest outputs: cache-key: ${{ steps.cache-key.outputs.key }} cache-date: ${{ steps.get-date.outputs.date }} @@ -19,28 +29,20 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 - - name: Install stable toolchain - id: rust-toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ env.RUST_STABLE }} - default: true - # We want to create a new cache after a week. Otherwise, the cache will # take up too much space by caching old dependencies - - name: Year + ISO week number + - name: Generate Year + ISO week number key id: get-date - run: echo "::set-output name=date::$(/bin/date -u "+%Y-%V")" shell: bash + run: echo "::set-output name=date::$(/bin/date -u "+%Y-%V")" - - name: Cache key + - name: Generate cargo registry cache key id: cache-key - run: echo "::set-output name=key::$(echo ${{ runner.os }}-cargo-registry-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/Cargo.lock') }})" shell: bash + run: echo "::set-output name=key::$(echo ${{ runner.os }}-cargo-registry-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/Cargo.lock') }})" - - name: Cache cargo registry - uses: actions/cache@v2 + - name: Restore cargo registry ${{ steps.cache-key.outputs.key }} cache + uses: actions/cache@v2.1.4 with: path: | ~/.cargo/registry @@ -48,19 +50,19 @@ jobs: key: ${{ steps.cache-key.outputs.key }} restore-keys: ${{ runner.os }}-cargo-registry-${{ steps.get-date.outputs.date }}- - - name: cargo fetch + - name: Fetch dependencies run: cargo fetch format: name: cargo-fmt needs: registry-cache + runs-on: ubuntu-20.04 timeout-minutes: 10 - runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v2 - - name: Install nightly toolchain + - name: Install ${{ env.RUST_NIGHTLY }} toolchain id: rust-toolchain uses: actions-rs/toolchain@v1 with: @@ -84,13 +86,13 @@ jobs: check: name: cargo-check needs: registry-cache + runs-on: ubuntu-20.04 timeout-minutes: 20 - runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v2 - - name: Install stable toolchain + - name: Install ${{ env.RUST_STABLE }} toolchain id: rust-toolchain uses: actions-rs/toolchain@v1 with: @@ -123,13 +125,13 @@ jobs: clippy: name: cargo-clippy needs: [registry-cache, check] + runs-on: ubuntu-20.04 timeout-minutes: 20 - runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v2 - - name: Install stable toolchain + - name: Install ${{ env.RUST_STABLE }} toolchain id: rust-toolchain uses: actions-rs/toolchain@v1 with: @@ -161,13 +163,13 @@ jobs: test: name: cargo-test needs: [registry-cache, check] + runs-on: ubuntu-20.04 timeout-minutes: 20 - runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v2 - - name: Install stable toolchain + - name: Install ${{ env.RUST_STABLE }} toolchain id: rust-toolchain uses: actions-rs/toolchain@v1 with: @@ -190,7 +192,6 @@ jobs: key: ${{ runner.os }}-cargo-${{ steps.rust-toolchain.outputs.rustc }}-tests-${{ needs.registry-cache.outputs.cache-date }}-${{ hashFiles('**/Cargo.lock') }} restore-keys: ${{ runner.os }}-cargo-${{ steps.rust-toolchain.outputs.rustc }}-tests-${{ needs.registry-cache.outputs.cache-date }}- - # TODO: cache this as well to avoid frequent downloading - name: Download data run: sh download_data.sh @@ -205,18 +206,19 @@ jobs: coverage: name: cargo-tarpaulin needs: [registry-cache, test] + runs-on: ubuntu-20.04 timeout-minutes: 20 - runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v2 - - name: Install stable toolchain + - name: Install ${{ env.RUST_STABLE }} toolchain id: rust-toolchain uses: actions-rs/toolchain@v1 with: toolchain: ${{ env.RUST_STABLE }} profile: minimal + default: true - name: Use cached cargo registry uses: actions/cache@v2 @@ -233,7 +235,6 @@ jobs: key: ${{ runner.os }}-cargo-${{ steps.rust-toolchain.outputs.rustc }}-tarpaulin-${{ needs.registry-cache.outputs.cache-date }}-${{ hashFiles('**/Cargo.lock') }} restore-keys: ${{ runner.os }}-cargo-${{ steps.rust-toolchain.outputs.rustc }}-tarpaulin-${{ needs.registry-cache.outputs.cache-date }}- - # TODO: cache this as well to avoid frequent downloading - name: Download data run: sh download_data.sh @@ -242,3 +243,127 @@ jobs: with: version: '0.16.0' args: '-v --all-features --force-clean --lib --ignore-tests --fail-under 70' + + install-cargo-lipo: + # we use the latest stable rustc + cargo version that is already installed on the image + # https://github.com/actions/virtual-environments/blob/main/images/macos/macos-10.15-Readme.md#rust-tools + name: install-cargo-lipo + runs-on: macos-10.15 + outputs: + cache-key: ${{ steps.cache-key.outputs.key }} + timeout-minutes: 15 + steps: + - name: Generate cargo-lipo cache key + id: cache-key + shell: bash + run: echo "::set-output name=key::$(echo ${{ runner.os }}-cargo-lipo-bin-${{ env.CARGO_LIPO }})" + + - name: Restore ${{ steps.cache-key.outputs.key }} cache + uses: actions/cache@v2.1.4 + id: cargo-lipo-cache + with: + path: ~/.cargo/bin/cargo-lipo + key: ${{ steps.cache-key.outputs.key }} + + - name: Install cargo-lipo ${{ env.CARGO_LIPO }} + if: ${{ !steps.cargo-lipo-cache.outputs.cache-hit }} + run: cargo install cargo-lipo --version ${{ env.CARGO_LIPO }} + + test-android-libs: + name: test-android-libs + needs: [registry-cache, test] + runs-on: ubuntu-20.04 + timeout-minutes: 20 + strategy: + fail-fast: false + matrix: + target: [aarch64-linux-android, armv7-linux-androideabi, i686-linux-android, x86_64-linux-android] + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install ${{ env.RUST_STABLE }} toolchain + id: rust-toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ env.RUST_STABLE }} + target: ${{ matrix.target }} + default: true + + - name: Restore ${{ needs.registry-cache.outputs.cache-key }} cache + uses: actions/cache@v2.1.4 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ needs.registry-cache.outputs.cache-key }} + + - name: Install Cross + shell: bash + run: | + wget -q -O - https://github.com/rust-embedded/cross/releases/download/v0.2.1/cross-v0.2.1-x86_64-unknown-linux-gnu.tar.gz | tar xvzf - + echo "${{ env.CROSS_CHECKSUM }} *cross" | shasum -c - + mv cross ~/.cargo/bin/ + + - name: Download data + run: sh download_data.sh + + - name: Restore build artifacts + uses: actions/cache@v2.1.4 + with: + path: ${{ github.workspace }}/target + key: ${{ runner.os }}-cargo-${{ steps.rust-toolchain.outputs.rustc }}-test-${{ matrix.target }}-${{ needs.registry-cache.outputs.cache-date }}-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo-${{ steps.rust-toolchain.outputs.rustc }}-test-${{ matrix.target }}-${{ needs.registry-cache.outputs.cache-date }}- + + - name: Test Android library ${{ matrix.target }} + env: + RUSTFLAGS: "-C opt-level=3 -C debug-assertions=yes -D warnings" + run: cross test --target ${{ matrix.target }} --all-targets -- -Z unstable-options --report-time + + build-ios-libs: + name: build-ios-libs + needs: [registry-cache, install-cargo-lipo, test] + runs-on: macos-10.15 + timeout-minutes: 20 + strategy: + fail-fast: false + matrix: + target: [aarch64-apple-ios, x86_64-apple-ios] + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install ${{ env.RUST_STABLE }} toolchain with target ${{ matrix.target }} + id: rust-toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ env.RUST_STABLE }} + target: ${{ matrix.target }} + default: true + + - name: Restore ${{ needs.registry-cache.outputs.cache-key }} cache + uses: actions/cache@v2.1.4 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ needs.registry-cache.outputs.cache-key }} + + - name: Restore ${{ needs.install-cargo-lipo.outputs.cache-key }} cache + uses: actions/cache@v2.1.4 + with: + path: ~/.cargo/bin/cargo-lipo + key: ${{ needs.install-cargo-lipo.outputs.cache-key }} + + - name: Restore build artifacts + uses: actions/cache@v2.1.4 + with: + path: ${{ github.workspace }}/target + key: ${{ runner.os }}-cargo-${{ steps.rust-toolchain.outputs.rustc }}-build-${{ matrix.target }}-${{ needs.registry-cache.outputs.cache-date }}-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo-${{ steps.rust-toolchain.outputs.rustc }}-build-${{ matrix.target }}-${{ needs.registry-cache.outputs.cache-date }}- + + - name: Build iOS library ${{ matrix.target }} + working-directory: ./xayn-ai-ffi-c + run: cargo lipo --targets ${{ matrix.target }} diff --git a/Cross.toml b/Cross.toml new file mode 100644 index 000000000..1a4557b51 --- /dev/null +++ b/Cross.toml @@ -0,0 +1,2 @@ +[build.env] +passthrough = ["RUSTFLAGS"]