Skip to content

Commit 03207b3

Browse files
authored
Update test coverage documentation to LLVM 19 (#4265)
1 parent 2a1c7ac commit 03207b3

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

guide/src/wasm-bindgen-test/coverage.md

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ Currently it is particularly difficult to [deliver compile-line arguments to pro
2222

2323
Make sure you are using `RUSTFLAGS=-Cinstrument-coverage -Zno-profiler-runtime`.
2424

25-
Due to the current limitation of `llvm-cov`, we can't collect profiling symbols from the generated `.wasm` files. Instead, we can grab them from the LLVM IR with `--emit=llvm-ir` by using Clang. Additionally, the emitted LLVM IR files by Rust contain invalid code that can't be parsed by Clang, so they need to be adjusted.
26-
27-
At the time of writing Rust Nightly uses LLVM v19, however [minicov] only supports LLVM v18. Usage of Clang or any LLVM tools must match the version used by [minicov].
28-
29-
[minicov]: https://crates.io/crates/minicov
25+
Due to the current limitation of `llvm-cov`, we can't collect profiling symbols from the generated `.wasm` files. Instead, we can grab them from the LLVM IR with `--emit=llvm-ir` by using Clang. Usage of Clang or any LLVM tools must match the LLVM version used by Rust.
3026

3127
### Arguments to the test runner
3228

@@ -58,11 +54,9 @@ CARGO_HOST_RUSTFLAGS=--cfg=wasm_bindgen_unstable_test_coverage \
5854
RUSTFLAGS="-Cinstrument-coverage -Zno-profiler-runtime --emit=llvm-ir --cfg=wasm_bindgen_unstable_test_coverage" \
5955
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER=wasm-bindgen-test-runner \
6056
cargo +nightly test -Ztarget-applies-to-host -Zhost-config --tests
61-
# Adjust the LLVM IR and compile to object files:
57+
# Compile to object files:
6258
# - Extract a list of compiled artifacts from Cargo and filter them with `jq`.
6359
# - Figure out the path to the LLVM IR file corresponding to an artifact.
64-
# - Replace every function body with `unreachable`.
65-
# - Remove Rust-specific `range` annotations from function signatures.
6660
# - Compile to object file with Clang and store for later usage with `llvm-cov`.
6761
crate_name=name_of_the_tested_crate_in_snake_case
6862
objects=()
@@ -81,20 +75,14 @@ do
8175
file=$(dirname $file)/$(basename $file .wasm).ll
8276
fi
8377

84-
perl -i -p0e 's/(^define.*?$).*?^}/$1\nstart:\n unreachable\n}/gms' $file
85-
counter=1
86-
while (( counter != 0 )); do
87-
counter=$(perl -i -p0e '$c+= s/(^(define|declare)(,? [^\n ]+)*),? range\(.*?\)/$1/gm; END{print "$c"}' $file)
88-
done
89-
90-
output = $(basename $file .ll).o
91-
clang-18 $input -Wno-override-module -c -o $output
92-
objects+=(-object $output)
78+
output = $(basename $file .ll).o
79+
clang-19 $file -Wno-override-module -c -o $output
80+
objects+=(-object $output)
9381
done
9482
# Merge all generated raw profiling data.
95-
llvm-profdata-18 merge -sparse *.profraw -o coverage.profdata
83+
llvm-profdata-19 merge -sparse *.profraw -o coverage.profdata
9684
# Produce test coverage data in the HTML format and pass the object files we generated earlier.
97-
llvm-cov-18 show -show-instantiations=false -Xdemangler=rustfilt -output-dir coverage -format=html -instr-profile=coverage.profdata ${objects[@]} -sources src
85+
llvm-cov-19 show -show-instantiations=false -Xdemangler=rustfilt -output-dir coverage -format=html -instr-profile=coverage.profdata ${objects[@]} -sources src
9886
```
9987

10088
[rustc book]: https://doc.rust-lang.org/nightly/rustc/instrument-coverage.html

0 commit comments

Comments
 (0)