cargo-llvm-cov
cargo-llvm-cov copied to clipboard
Support for Wasm?
I'd really like to be able to run my Web Assembly tests and get coverage reports for them.
First issue, can I specify a custom binary to run e.g. instead of cargo test
, my test command is wasm-pack test --node
.
Second issue, I get a compile error when trying to build on wasm32-unknown-unknown
:
$ cargo llvm-cov --target wasm32-unknown-unknown
info: when --target option is used, coverage for proc-macro and build script will not be displayed because cargo does not pass RUSTFLAGS to them
Compiling cfg-if v1.0.0
Compiling scoped-tls v1.0.0
Compiling ag-grid-derive v0.1.0
error[E0463]: can't find crate for `profiler_builtins`
|
= note: the compiler may have been built without the profiler runtime
For more information about this error, try `rustc --explain E0463`.
error: could not compile `cfg-if` due to previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `scoped-tls` due to previous error
Is the above possible?
As for the second issue, it is the same issue as https://github.com/rust-lang/rust/issues/81684.
One or both of the following may work:
- support minicov (but, I guess we can already handle minicov by just passing some flags as rustflags)
- use wasi with own toolchain built with
profiler = true
and this patch (once this PR is merged, building own toolchain may no longer be necessary)
As for the first issue, I think we can add a subcommand as we did for nextest. something like: cargo llvm-cov wasm-pack test --node
.
That said, the second issue needs to be resolved first.
@taiki-e Hey, can we do anything to help develop this feature? The PR mentioned above in Rust repos was closed, and a lot has changed in the past year.
I don't think the situation has changed much on this issue. Someone will need to either contribute to rustc to improve the situation (e.g., by taking over a PR that closed as inactive) or investigate (and document) how to make cargo-llvm-cov work with a profiler-builtins alternative.
Hi, is there any updates? Thanks! (I guess no...? :/ )
Actually. Here is a spicy boy I made.
https://github.com/hknio/wasmcov
It doesn't use cargo-llvm-cov, but uses the llvm-cov package directly.
With https://github.com/rustwasm/wasm-bindgen/pull/3782, I think we can follow up here.
We could do something like cargo llvm-cov --wasm-bindgen test
to generate the profraw with wasm-pack
and then process it.
An annoying thing is that we have to use --emit=llvm-ir
because llvm-cov
can't get the debug info from the .wasm
(despite the info being in there). So we would have to run clang target/wasm32-unknown-unknown/debug/deps/{file_name}.ll -Wno-override-module -c -o {file_name}.o
and then search for this .o
as the binary for the reporting.
I would really love this. It would mean you can merge normal tests with wasm_bindgen_tests easily.