From 7b64ab3c33b1268d7f6eddad10e52b2c928d0902 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Thu, 19 Dec 2024 22:25:39 +0100 Subject: [PATCH] Update `wasm-bindgen` --- .github/workflows/build.yaml | 4 ++- .github/workflows/coverage-documentation.yaml | 10 ++++--- .github/workflows/lint.yaml | 8 +++-- .github/workflows/test.yaml | 12 ++++++-- CONTRIBUTING.md | 29 +++++++++++++------ Cargo.toml | 10 ++++--- src/lib.rs | 3 +- src/time/instant.rs | 4 +-- tests-web/Cargo.toml | 5 +++- 9 files changed, 58 insertions(+), 27 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 20110af..f144802 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -36,6 +36,7 @@ jobs: description: with Atomics, atomics: true, component: --component rust-src, + cflags: -matomics -mbulk-memory, flags: "-Ctarget-feature=+atomics,+bulk-memory", build-std: true, } @@ -92,7 +93,8 @@ jobs: cargo update -p syn --precise 2.0.67 - name: Build env: - RUSTFLAGS: ${{ matrix.rust.flags }} + CFLAGS_wasm32_unknown_unknown: ${{ matrix.rust.cflags }} + CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUSTFLAGS: ${{ matrix.rust.flags }} run: cargo build ${{ matrix.features.features }} --target ${{ matrix.target.target }} $BUILD_STD_COMPONENTS diff --git a/.github/workflows/coverage-documentation.yaml b/.github/workflows/coverage-documentation.yaml index 62f108f..3181aff 100644 --- a/.github/workflows/coverage-documentation.yaml +++ b/.github/workflows/coverage-documentation.yaml @@ -39,17 +39,19 @@ jobs: env: CFLAGS_wasm32_unknown_unknown: ${{ matrix.mt.cflags }} - RUSTFLAGS: + CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUSTFLAGS: -Cinstrument-coverage -Zcoverage-options=condition -Zno-profiler-runtime --emit=llvm-ir - --cfg=wasm_bindgen_unstable_test_coverage ${{ matrix.mt.flags }} + --cfg=web_time_test_coverage ${{ matrix.mt.flags }} steps: - name: Checkout uses: actions/checkout@v4 - name: Install `wasm-bindgen-cli` - uses: taiki-e/install-action@v2 + uses: taiki-e/cache-cargo-install-action@v2 with: tool: wasm-bindgen-cli + git: https://github.com/daxpedda/wasm-bindgen + rev: d4cb4a5d94090c18b469796250744612fd347dbd - name: Install Clang v19 run: | wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - @@ -72,7 +74,7 @@ jobs: run: | chromedriver --port=9000 & mkdir coverage-output - WASM_BINDGEN_UNSTABLE_TEST_PROFRAW_OUT=$(realpath coverage-output) cargo test --workspace --features serde --target wasm32-unknown-unknown $BUILD_STD_COMPONENTS ${{ matrix.features.features }} --tests + LLVM_PROFILE_FILE=$(realpath coverage-output)/%m_%p.profraw cargo test --workspace --features serde --target wasm32-unknown-unknown $BUILD_STD_COMPONENTS ${{ matrix.features.features }} --tests - name: Prepare Object Files run: | mkdir coverage-input diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index ea54d3b..b410ede 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -34,6 +34,7 @@ jobs: description: with Atomics, atomics: true, component: ",rust-src", + cflags: -matomics -mbulk-memory, flags: "-Ctarget-feature=+atomics,+bulk-memory", build-std: true, } @@ -80,7 +81,8 @@ jobs: run: echo "BUILD_STD_COMPONENTS=-Zbuild-std=core,alloc" >> $GITHUB_ENV - name: Run Clippy env: - RUSTFLAGS: ${{ matrix.rust.flags }} + CFLAGS_wasm32_unknown_unknown: ${{ matrix.rust.cflags }} + CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUSTFLAGS: ${{ matrix.rust.flags }} run: cargo clippy --workspace --all-targets ${{ matrix.features.features }} --target ${{ matrix.target.target }} $BUILD_STD_COMPONENTS -- -D warnings @@ -106,6 +108,7 @@ jobs: description: with Atomics, atomics: true, component: --component rust-src, + cflags: -matomics -mbulk-memory, flags: "-Ctarget-feature=+atomics,+bulk-memory", build-std: true, } @@ -158,7 +161,8 @@ jobs: run: echo "BUILD_STD_COMPONENTS=-Zbuild-std=core,alloc" >> $GITHUB_ENV - name: Run Rustdoc env: - RUSTFLAGS: ${{ matrix.rust.flags }} + CFLAGS_wasm32_unknown_unknown: ${{ matrix.rust.cflags }} + CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUSTFLAGS: ${{ matrix.rust.flags }} RUSTDOCFLAGS: -D warnings ${{ matrix.rust.flags }} ${{ matrix.docsrs.flags }} run: cargo doc --workspace --no-deps --document-private-items --lib --examples ${{ diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 4564378..75dc29c 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -33,6 +33,7 @@ jobs: version: nightly, description: with Atomics, component: --component rust-src, + cflags: -matomics -mbulk-memory, flags: "-Ctarget-feature=+atomics,+bulk-memory", build-std: true, atomics: true, @@ -67,6 +68,7 @@ jobs: env: SAFARIDRIVER, binary: safaridriver, browser: true, + macos: true, } - { os: ubuntu-24.04, description: Node.js, nodejs: true } environment: @@ -119,11 +121,16 @@ jobs: with: tool: wasm-bindgen-cli git: https://github.com/daxpedda/wasm-bindgen - rev: 9dc93d8c096cdb50c2c2d8a181f337ddfa927517 + rev: d4cb4a5d94090c18b469796250744612fd347dbd - name: Install Rust run: | rustup toolchain install ${{ matrix.rust.version }} --profile minimal ${{ matrix.rust.component }} --target ${{ matrix.target.target }} rustup default ${{ matrix.rust.version }} + - name: Install Clang version with `wasm32-unknown-unknown` support on MacOS + if: matrix.driver.macos == true + run: | + brew install llvm + which clang - name: Set `build-std` components if: matrix.rust.build-std == true && matrix.features.no_std == false run: echo "BUILD_STD_COMPONENTS=-Zbuild-std=panic_abort,std" >> $GITHUB_ENV @@ -168,7 +175,8 @@ jobs: run: echo "${{ matrix.environment.name }}=1" >> $GITHUB_ENV - name: Test env: - RUSTFLAGS: ${{ matrix.rust.flags }} + CFLAGS_wasm32_unknown_unknown: ${{ matrix.rust.cflags }} + CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUSTFLAGS: ${{ matrix.rust.flags }} RUSTDOCFLAGS: ${{ matrix.rust.flags }} run: cargo test --features serde ${{ matrix.features.features }} --target ${{ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f2f9756..782f123 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -44,9 +44,9 @@ Example usage: # 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 --target wasm32-unknown-unknown -Zbuild-std=panic_abort,std +CFLAGS_wasm32_unknown_unknown="-matomics -mbulk-memory" RUSTFLAGS=-Ctarget-feature=+atomics,+bulk-memory cargo +nightly build --target wasm32-unknown-unknown -Zbuild-std=panic_abort,std # Example `no_std` `cargo build` usage: -RUSTFLAGS=-Ctarget-feature=+atomics,+bulk-memory cargo +nightly build --target wasm32v1-none -Zbuild-std=core,alloc --no-default-features +CFLAGS_wasm32_unknown_unknown="-matomics -mbulk-memory" RUSTFLAGS=-Ctarget-feature=+atomics,+bulk-memory cargo +nightly build --target wasm32v1-none -Zbuild-std=core,alloc --no-default-features ``` [`build-std`]: https://doc.rust-lang.org/1.73.0/cargo/reference/unstable.html#build-std @@ -61,11 +61,12 @@ 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" + "-Zbuild-std=panic_abort,std", ], "rust-analyzer.cargo.extraEnv": { "RUSTUP_TOOLCHAIN": "nightly", - "RUSTFLAGS": "-Ctarget-feature=+atomics,+bulk-memory" + "RUSTFLAGS": "-Ctarget-feature=+atomics,+bulk-memory", + "CFLAGS_wasm32_unknown_unknown": "-matomics -mbulk-memory", }, ``` @@ -99,7 +100,7 @@ cargo test --workspace --target wasm32-unknown-unknown # Run tests for `no_std`. cargo +nightly test --workspace --target wasm32v1-none --no-default-features # Run tests for Wasm atomics. -RUSTFLAGS=-Ctarget-feature=+atomics,+bulk-memory cargo +nightly test --workspace --target wasm32-unknown-unknown -Zbuild-std=panic_abort,std +CFLAGS_wasm32_unknown_unknown="-matomics -mbulk-memory" RUSTFLAGS=-Ctarget-feature=+atomics,+bulk-memory cargo +nightly test --workspace --target wasm32-unknown-unknown -Zbuild-std=panic_abort,std ``` Make sure not to use `--all-features`. @@ -175,19 +176,26 @@ full test coverage data via an artifact called `test-coverage`. If you want to generate test coverage locally, here is an example shell script that you can use: ```sh +rm -rf coverage-input +rm -rf coverage-output + # Single-threaded test run. st () { - RUSTFLAGS="-Cinstrument-coverage -Zcoverage-options=condition -Zno-profiler-runtime --emit=llvm-ir --cfg=wasm_bindgen_unstable_test_coverage" cargo +nightly test --workspace --features serde --target wasm32-unknown-unknown --tests $@ + CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUSTFLAGS="-Cinstrument-coverage -Zcoverage-options=condition -Zno-profiler-runtime --emit=llvm-ir --cfg web_time_test_coverage" cargo +nightly $1 --workspace --features serde --target wasm32-unknown-unknown --tests ${@:2} } # Multi-threaded test run. mt () { - CFLAGS_wasm32_unknown_unknown="-matomics -mbulk-memory" RUSTFLAGS="-Cinstrument-coverage -Zcoverage-options=condition -Zno-profiler-runtime --emit=llvm-ir --cfg=wasm_bindgen_unstable_test_coverage -Ctarget-feature=+atomics,+bulk-memory" cargo +nightly test --workspace --features serde --target wasm32-unknown-unknown --tests $@ + CFLAGS_wasm32_unknown_unknown="-matomics -mbulk-memory" CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUSTFLAGS="-Cinstrument-coverage -Zcoverage-options=condition -Zno-profiler-runtime --emit=llvm-ir -Ctarget-feature=+atomics,+bulk-memory --cfg web_time_test_coverage" cargo +nightly $1 --workspace --features serde --target wasm32-unknown-unknown --tests ${@:2} } # To collect object files. objects=() +# Start Chromedriver in the background +chromedriver --port=9000 & +pid=$! + # Run tests and adjust LLVM IR. test () { local command=$1 @@ -195,13 +203,13 @@ test () { # Run tests. mkdir -p coverage-input/$path - WASM_BINDGEN_USE_BROWSER=1 CHROMEDRIVER=chromedriver WASM_BINDGEN_UNSTABLE_TEST_PROFRAW_OUT=$(realpath coverage-input/$path) $command ${@:3} + WASM_BINDGEN_USE_BROWSER=1 CHROMEDRIVER_REMOTE=http://127.0.0.1:9000 LLVM_PROFILE_FILE=$(realpath coverage-input/$path/%m_%p.profraw) $command 'nextest run' ${@:3} local crate_name=web_time local IFS=$'\n' for file in $( # Extract path to artifacts. - $command ${@:3} --no-run --message-format=json | \ + $command 'test' ${@:3} --no-run --message-format=json | \ jq -r "select(.reason == \"compiler-artifact\") | (select(.target.kind == [\"test\"]) // select(.target.name == \"$crate_name\")) | .filenames[0]" ) do @@ -227,6 +235,9 @@ test st 'st-no_std' --no-default-features test mt 'mt' -Zbuild-std=panic_abort,std test mt 'mt-no_std' -Zbuild-std=core,alloc --no-default-features +# Shutdown Chromedriver +kill $pid + # Merge all generated `*.profraw` files. rust-profdata merge -sparse coverage-input/*/*.profraw -o coverage-input/coverage.profdata # Finally generate coverage information. diff --git a/Cargo.toml b/Cargo.toml index b50c3fb..cbdb353 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,9 +29,6 @@ wasm-bindgen = { version = "0.2.98", default-features = false } [build-dependencies] rustversion = { version = "1.0.0", optional = true } -[dev-dependencies] -wasm-bindgen-test = { version = "0.3", default-features = false } - [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] tests-native = { path = "tests-native", default-features = false, features = ["run"] } @@ -39,10 +36,15 @@ tests-native = { path = "tests-native", default-features = false, features = ["r getrandom = { version = "0.2", features = ["js"] } rand = { version = "0.8", default-features = false, features = ["getrandom", "std_rng"] } tests-web = { path = "tests-web", default-features = false, features = ["run"] } +wasm-bindgen-test = { version = "0.3", default-features = false, features = [ + "msrv", + "unstable-test-coverage", +] } [patch.crates-io] getrandom = { git = "https://github.com/daxpedda/getrandom", branch = "web-time" } js-sys = { git = "https://github.com/daxpedda/wasm-bindgen", branch = "web-time" } +minicov = { git = "https://github.com/daxpedda/minicov", branch = "web-time" } serde_test = { git = "https://github.com/daxpedda/test", branch = "no_std" } wasm-bindgen = { git = "https://github.com/daxpedda/wasm-bindgen", branch = "web-time" } wasm-bindgen-futures = { git = "https://github.com/daxpedda/wasm-bindgen", branch = "web-time" } @@ -90,9 +92,9 @@ single_use_lifetimes = "warn" trivial_casts = "warn" trivial_numeric_casts = "warn" unexpected_cfgs = { level = "warn", check-cfg = [ - 'cfg(wasm_bindgen_unstable_test_coverage)', 'cfg(v1_77)', 'cfg(nightly)', + 'cfg(web_time_test_coverage)', ] } unnameable_types = "warn" unreachable_pub = "warn" diff --git a/src/lib.rs b/src/lib.rs index 66f5a84..ad0a95e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -54,7 +54,7 @@ //! # #[cfg(target_arch = "wasm32")] //! # use tests_web as _; //! # -//! # #[wasm_bindgen_test::wasm_bindgen_test] +//! # #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] //! # fn main() { //! let now = Instant::now(); //! let time = SystemTime::now(); @@ -167,7 +167,6 @@ #![cfg_attr(all(target_arch = "wasm32", not(feature = "std")), no_std)] #![cfg_attr(all(test, target_arch = "wasm32"), no_main)] #![cfg_attr(all(doc, docsrs), feature(doc_cfg))] -#![cfg_attr(wasm_bindgen_unstable_test_coverage, feature(coverage_attribute))] #![cfg_attr(all(not(feature = "std"), nightly), feature(asm_experimental_arch))] #[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))] diff --git a/src/time/instant.rs b/src/time/instant.rs index 3d4ac63..0c041d4 100644 --- a/src/time/instant.rs +++ b/src/time/instant.rs @@ -300,7 +300,7 @@ impl F64 { /// Put `debug_assert!` in a function to clap `coverage(off)` on it. /// /// See . - #[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] + #[cfg_attr(web_time_test_coverage, coverage(off))] fn check(this: f64) { debug_assert!(this.is_sign_positive(), "found negative input"); debug_assert!( @@ -327,7 +327,7 @@ impl F64 { } #[cfg(test)] -#[cfg_attr(wasm_bindgen_unstable_test_coverage, coverage(off))] +#[cfg_attr(web_time_test_coverage, coverage(off))] mod test { //! Testing internal code. diff --git a/tests-web/Cargo.toml b/tests-web/Cargo.toml index 505a5bc..c5e20c0 100644 --- a/tests-web/Cargo.toml +++ b/tests-web/Cargo.toml @@ -37,7 +37,10 @@ serde_test = { version = "1", optional = true, default-features = false } static_assertions = "1" wasm-bindgen = { version = "0.2", default-features = false } wasm-bindgen-futures = { version = "0.4", default-features = false } -wasm-bindgen-test = { version = "0.3", default-features = false } +wasm-bindgen-test = { version = "0.3", default-features = false, features = [ + "msrv", + "unstable-test-coverage", +] } web-sys = { version = "0.3", default-features = false, features = [ "CssStyleDeclaration", "Document",