From e7e830caa14f11617f7888e8b3f55b7ab7420c22 Mon Sep 17 00:00:00 2001 From: Samuel Maier Date: Fri, 6 Sep 2024 15:59:29 +0200 Subject: [PATCH] Add config files to ease contribution --- .cargo/config.toml | 8 ++++++ .github/workflows/audit.yaml | 2 +- .github/workflows/coverage-documentation.yaml | 15 ++++++----- .gitignore | 2 ++ CONTRIBUTING.md | 26 +++---------------- 5 files changed, 24 insertions(+), 29 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 10762f9..0344372 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,10 @@ [target.wasm32-unknown-unknown] runner = "wasm-bindgen-test-runner" +rustflags = [ + "-C", + "target-feature=+atomics,+bulk-memory", +] + +# Only kicks in if actually compiled with unstable compiler. +[unstable] +build-std = ["std,panic_abort"] diff --git a/.github/workflows/audit.yaml b/.github/workflows/audit.yaml index 0aa8444..3be6254 100644 --- a/.github/workflows/audit.yaml +++ b/.github/workflows/audit.yaml @@ -26,4 +26,4 @@ jobs: with: tool: cargo-audit - name: Run Audit - run: cargo audit -D warnings + run: cargo +stable audit -D warnings diff --git a/.github/workflows/coverage-documentation.yaml b/.github/workflows/coverage-documentation.yaml index 05f6630..3889f64 100644 --- a/.github/workflows/coverage-documentation.yaml +++ b/.github/workflows/coverage-documentation.yaml @@ -24,14 +24,17 @@ jobs: strategy: matrix: mt: - - { id: 0 } + - { + id: 0, + description: without Atomics, + envs: "CARGO_TARGET_wasm32_unknown_unknown_RUSTDOCFLAGS= cargo +stable --verbose test", + toolchain: "stable", + } - { id: 1, description: with Atomics, component: --component rust-src, - cflags: -matomics -mbulk-memory, - flags: "-Ctarget-feature=+atomics,+bulk-memory", - args: "-Zbuild-std=panic_abort,std", + toolchain: "nightly", } steps: @@ -46,7 +49,7 @@ jobs: - name: Install Rust nightly run: | rustup toolchain install nightly --profile minimal --target wasm32-unknown-unknown ${{ matrix.mt.component }} - rustup default nightly + rustup default ${{ matrix.mt.toolchain }} - name: Test env: CHROMEDRIVER: chromedriver @@ -58,7 +61,7 @@ jobs: WASM_BINDGEN_UNSTABLE_TEST_PROFRAW_OUT: coverage-output run: | mkdir coverage-output - cargo test --all-features --target wasm32-unknown-unknown -Ztarget-applies-to-host -Zhost-config ${{ matrix.mt.args }} --tests + ${{ matrix.mt.envs }} cargo +${{ matrix.mt.toolchain }} test --all-features --target wasm32-unknown-unknown -Ztarget-applies-to-host -Zhost-config ${{ matrix.mt.args }} --tests - name: Prepare Object Files env: CFLAGS_wasm32_unknown_unknown: ${{ matrix.mt.cflags }} diff --git a/.gitignore b/.gitignore index 9faba4e..1582a53 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ /Cargo.lock /coverage-input /coverage-output +/.vscode/* +!.vscode/settings.json \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b573f33..84551e4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,39 +11,21 @@ This crate has some code paths that depend on Wasm Atomics, which has some prere - Cargo's [`build-std`]. - The `atomics` and `bulk-memory` target features. -Example usage: - -```sh -# Installing Rust nightly and necessary components: -rustup toolchain install nightly --target wasm32-unknown-unknown --component rust-src -# Example `cargo build` usage: -RUSTFLAGS=-Ctarget-feature=+atomics,+bulk-memory cargo +nightly build -Zbuild-std=panic_abort,std --target wasm32-unknown-unknown -``` +These are set using [`rust-toolchain.toml`](./rust-toolchain.toml). ### Rust Analyzer To get proper diagnostics for Rust Atomics it can be helpful to configure Rust Analyzer to support that. -Here is an example configuration for Visual Studio Code: - -```json -"rust-analyzer.cargo.target": "wasm32-unknown-unknown", -"rust-analyzer.cargo.extraArgs": [ - "-Zbuild-std=panic_abort,std" -], -"rust-analyzer.cargo.extraEnv": { - "RUSTUP_TOOLCHAIN": "nightly", - "RUSTFLAGS": "-Ctarget-feature=+atomics,+bulk-memory" -}, -``` +It takes the settings from `rust-toolchain.toml`, but we also need to specify a target, as seen for vscode in [.vscode/settings.json](./.vscode/settings.json). ## Testing -Tests are run as usual, but tests that require Wasm Atomics can be run like this: +Tests are run as usual, but also rewuire an explicit target: ```sh -RUSTFLAGS=-Ctarget-feature=+atomics,+bulk-memory cargo +nightly test -Zbuild-std=panic_abort,std --target wasm32-unknown-unknown +cargo test --target wasm32-unknown-unknown ``` Additionally, keep in mind that usage of [`#[should_panic]`](`should_panic`) is known to cause