cargo-llvm-cov icon indicating copy to clipboard operation
cargo-llvm-cov copied to clipboard

[Proposal] Add support for `wasm-pack test`

Open aDogCalledSpot opened this issue 7 months ago • 0 comments

Follows up from https://github.com/taiki-e/cargo-llvm-cov/issues/221.

I'm currently working on generating profraw data from wasm-pack test: https://github.com/rustwasm/wasm-bindgen/pull/3782

TLDR: It will be possible to generate a wasm.profraw with the following command:

RUSTFLAGS="-Cinstrument-coverage -Zno-profiler-runtime --emit=llvm-ir" wasm-pack test --chrome --headless --coverage --profraw-out=wasm.profraw

I would to add support for this operation in cargo-llvm-cov and would therefore like to discuss what the interface and the implementation for this should look like.

Interface

For the interface, I propose adding a --wasm flag to llvm-cov test which then runs wasm-pack test instead of cargo test.

Implementation

If the --wasm flag is present in the llvm-cov test command, then we execute the command written above and dump the profraw in the usual llvm-cov-target/.

LLVM currently isn't able to read the debuginfo from the .wasm, which is why we use --emit=llvm-ir in the RUSTFLAGS. We now need to generate a native .o with clang, so llvm-cov can map the hits in the profdata back to lines in the source code.

clang target/wasm32-unknown-unknown/debug/deps/{file_name}.ll -Wno-override-module -c -o target/llvm-cov-target/{file_name}.o

Merging the profdata should work just before.

Reporting needs to additionally pass our generated .o as -object to llvm-cov.


Let me know what you think! I'm happy to submit a PR if this looks good to everyone.

aDogCalledSpot avatar Jan 15 '24 09:01 aDogCalledSpot