@@ -44,9 +44,9 @@ Example usage:
4444# Installing Rust nightly and necessary components:
4545rustup toolchain install nightly --target wasm32-unknown-unknown --component rust-src
4646# Example `cargo build` usage:
47- RUSTFLAGS=-Ctarget-feature=+atomics,+bulk-memory cargo +nightly build --target wasm32-unknown-unknown -Zbuild-std=panic_abort,std
47+ 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
4848# Example `no_std` `cargo build` usage:
49- RUSTFLAGS=-Ctarget-feature=+atomics,+bulk-memory cargo +nightly build --target wasm32v1-none -Zbuild-std=core,alloc --no-default-features
49+ 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
5050```
5151
5252[ `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:
6161``` json
6262"rust-analyzer.cargo.target" : " wasm32-unknown-unknown" ,
6363"rust-analyzer.cargo.extraArgs" : [
64- " -Zbuild-std=panic_abort,std"
64+ " -Zbuild-std=panic_abort,std" ,
6565],
6666"rust-analyzer.cargo.extraEnv" : {
6767 "RUSTUP_TOOLCHAIN" : " nightly" ,
68- "RUSTFLAGS" : " -Ctarget-feature=+atomics,+bulk-memory"
68+ "RUSTFLAGS" : " -Ctarget-feature=+atomics,+bulk-memory" ,
69+ "CFLAGS_wasm32_unknown_unknown" : " -matomics -mbulk-memory" ,
6970},
7071```
7172
@@ -99,7 +100,7 @@ cargo test --workspace --target wasm32-unknown-unknown
99100# Run tests for `no_std`.
100101cargo +nightly test --workspace --target wasm32v1-none --no-default-features
101102# Run tests for Wasm atomics.
102- RUSTFLAGS=-Ctarget-feature=+atomics,+bulk-memory cargo +nightly test --workspace --target wasm32-unknown-unknown -Zbuild-std=panic_abort,std
103+ 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
103104```
104105
105106Make sure not to use ` --all-features ` .
@@ -175,33 +176,40 @@ full test coverage data via an artifact called `test-coverage`.
175176If you want to generate test coverage locally, here is an example shell script that you can use:
176177
177178``` sh
179+ rm -rf coverage-input
180+ rm -rf coverage-output
181+
178182# Single-threaded test run.
179183st () {
180- 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 $@
184+ 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}
181185}
182186
183187# Multi-threaded test run.
184188mt () {
185- 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 $@
189+ 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}
186190}
187191
188192# To collect object files.
189193objects=()
190194
195+ # Start Chromedriver in the background
196+ chromedriver --port=9000 &
197+ pid=$!
198+
191199# Run tests and adjust LLVM IR.
192200test () {
193201 local command=$1
194202 local path=$2
195203
196204 # Run tests.
197205 mkdir -p coverage-input/$path
198- WASM_BINDGEN_USE_BROWSER=1 CHROMEDRIVER=chromedriver WASM_BINDGEN_UNSTABLE_TEST_PROFRAW_OUT =$( realpath coverage-input/$path ) $command ${@: 3}
206+ 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}
199207
200208 local crate_name=web_time
201209 local IFS=$' \n '
202210 for file in $(
203211 # Extract path to artifacts.
204- $command ${@: 3} --no-run --message-format=json | \
212+ $command ' test ' ${@: 3} --no-run --message-format=json | \
205213 jq -r " select(.reason == \" compiler-artifact\" ) | (select(.target.kind == [\" test\" ]) // select(.target.name == \" $crate_name \" )) | .filenames[0]"
206214 )
207215 do
@@ -227,6 +235,9 @@ test st 'st-no_std' --no-default-features
227235test mt ' mt' -Zbuild-std=panic_abort,std
228236test mt ' mt-no_std' -Zbuild-std=core,alloc --no-default-features
229237
238+ # Shutdown Chromedriver
239+ kill $pid
240+
230241# Merge all generated `*.profraw` files.
231242rust-profdata merge -sparse coverage-input/* /* .profraw -o coverage-input/coverage.profdata
232243# Finally generate coverage information.
0 commit comments