# spell-checker:ignore wasip wasmtime name: WASI # spell-checker:ignore TRIGGERPATH on: pull_request: push: branches: - main permissions: contents: read # End the current execution if there is a new changeset in the PR. concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} jobs: test_wasi: name: Tests runs-on: ubuntu-latest strategy: fail-fast: false matrix: job: - { target: wasm32-wasip1, rust-flags: "--cfg wasi_runner" } - { target: wasm32-wasip2, rust-flags: "--cfg wasi_runner --cfg wasip2_runner" } steps: - uses: actions/checkout@v7.0.1 with: persist-credentials: false - uses: dtolnay/rust-toolchain@stable with: targets: ${{ matrix.job.target }} - uses: Swatinem/rust-cache@v2 with: key: "${{ matrix.job.target }}" - name: Install wasmtime run: | curl https://wasmtime.dev/install.sh -sSf | bash echo "$HOME/.wasmtime/bin" >> $GITHUB_PATH - name: Run unit tests env: CARGO_TARGET_WASM32_WASIP1_RUNNER: wasmtime CARGO_TARGET_WASM32_WASIP2_RUNNER: wasmtime run: | # Get all utilities and exclude ones that don't compile for ${{ matrix.job.target }} EXCLUDE="df|du|env|more|tac" UTILS=$(./util/show-utils.sh | tr ' ' '\n' | grep -vE "^($EXCLUDE)$" | sed 's/^/-p uu_/' | tr '\n' ' ') cargo test --target ${{ matrix.job.target }} --no-default-features $UTILS - name: Run integration tests via wasmtime if: matrix.job.target == 'wasm32-wasip1' env: RUSTFLAGS: ${{ matrix.job.rust-flags }} run: | # Build the WASI binary cargo build --target ${{ matrix.job.target }} --no-default-features --features feat_wasm # Run host-compiled integration tests against the WASI binary. # Tests incompatible with WASI are annotated with # #[cfg_attr(wasi_runner, ignore)] in the test source files. # The binary above is built without default features, so it has no # caret diagnostics; the host test crate does have them, hence the # not(wasi_runner) in the cfg guarding every `mod diagnostics`. # TODO: add integration tests for these tools as WASI support is extended: # arch b2sum cksum csplit date dir dircolors fmt join # ls md5sum mkdir mv nproc pathchk pr printenv ptx pwd readlink # realpath rm rmdir seq sha1sum sha224sum sha256sum sha384sum # sha512sum shred sleep sort split tsort uname uniq vdir UUTESTS_BINARY_PATH="$(pwd)/target/${{ matrix.job.target }}/debug/coreutils.wasm" \ UUTESTS_WASM_RUNNER=wasmtime \ cargo test --test tests -- \ test_base32:: test_base64:: test_basenc:: test_basename:: \ test_cat:: test_comm:: test_cp:: test_cut:: test_dirname:: test_echo:: \ test_expand:: test_expr:: test_factor:: test_false:: test_fold:: \ test_head:: test_link:: test_ln:: test_mktemp:: test_nl:: test_numfmt:: \ test_od:: test_paste:: test_printf:: test_shuf:: test_sum:: \ test_tail:: test_tee:: test_test:: test_touch:: test_tr:: \ test_true:: test_truncate:: \ test_unexpand:: test_unlink:: test_wc:: test_yes::