summaryrefslogtreecommitdiff
path: root/.github/workflows/test.yaml
blob: be1993bfcb9e15f078624d9bfb31d41d25a2a1ab (plain)
name: Rust CI

on:
  push:
    branches: ["**"]
  pull_request:
    branches: ["next", "main"]
  schedule:
    - cron: "0 0 * * 0"

jobs:
  build-wasm:
    name: Build wasm
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          submodules: true
          persist-credentials: false
      - name: Install Rust toolchain
        uses: actions-rust-lang/setup-rust-toolchain@46268bd060767258de96ed93c1251119784f2ab6 # v1.16.1
        with:
          toolchain: nightly
          components: rust-src
          rustflags: ""
          target: wasm32-unknown-unknown
      - name: Install Binaryen
        run: |
          BINARYEN_VERSION=version_129
          BINARYEN_DIR="binaryen-${BINARYEN_VERSION}"
          BINARYEN_ARCHIVE="${BINARYEN_DIR}-x86_64-linux.tar.gz"
          curl -L "https://github.com/WebAssembly/binaryen/releases/download/${BINARYEN_VERSION}/${BINARYEN_ARCHIVE}" -o "/tmp/${BINARYEN_ARCHIVE}"
          echo "50b9fa62b9abea752da92ec57e0c555fee578760cd237c40107957715d2976ba  /tmp/${BINARYEN_ARCHIVE}" | sha256sum -c -
          tar -xzf "/tmp/${BINARYEN_ARCHIVE}" -C /tmp
          sudo install "/tmp/${BINARYEN_DIR}/bin/wasm-opt" /usr/local/bin/wasm-opt
      - name: Install WABT
        run: sudo apt-get install -y wabt
      - name: Build wasm
        run: ./examples/rust/build.sh
      - name: Save artifacts
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: wasm
          path: examples/rust/out

  run-tests:
    needs: build-wasm
    strategy:
      matrix:
        include:
          - os: ubuntu-latest
            rust: stable
            name: "Linux x86 (stable)"
          - os: ubuntu-latest
            rust: nightly
            name: "Linux x86 (nightly)"
          - os: ubuntu-latest
            rust: stable
            name: "Linux x86 (stable, no default features)"
            args: "--no-default-features"
          - os: ubuntu-latest
            rust: nightly
            name: "Linux x86 (nightly, no default features)"
            args: "--no-default-features"
          - os: macos-14
            rust: stable
            name: "macOS arm64 (Apple M1)"
          - os: ubuntu-latest
            rust: stable
            name: "Linux arm64"
            target: aarch64-unknown-linux-gnu
          - os: ubuntu-latest
            rust: stable
            name: "Linux armv7"
            target: armv7-unknown-linux-gnueabihf

    name: Run tests on ${{ matrix.name }}
    runs-on: ${{ matrix.os }}
    steps:
      - name: Checkout code
        uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          submodules: true
          persist-credentials: false

      - name: Install Rust toolchain
        uses: actions-rust-lang/setup-rust-toolchain@46268bd060767258de96ed93c1251119784f2ab6 # v1.16.1
        with:
          toolchain: ${{ matrix.rust }}
          rustflags: ""
          components: rustfmt, clippy
        if: matrix.target == ''

      - name: Load wasm
        uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: wasm
          path: examples/rust/out

      - name: Run tests
        run: cargo test --workspace ${{ matrix.args }} && cargo test --workspace ${{ matrix.args }} --examples
        if: matrix.target == ''

      - name: Run clippy
        run: cargo clippy --workspace ${{ matrix.args }}
        if: matrix.target == ''

      - name: Run tests (${{ matrix.target }})
        uses: houseabsolute/actions-rust-cross@fe6ede73c7f0a50412ec05994e2aa5a7bf635eac # v1.0.7
        with:
          command: test
          target: ${{ matrix.target }}
          toolchain: ${{ matrix.rust }}
        if: matrix.target != ''