Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Wasm? #221

Open
mfreeborn opened this issue Sep 18, 2022 · 6 comments · May be fixed by #338
Open

Support for Wasm? #221

mfreeborn opened this issue Sep 18, 2022 · 6 comments · May be fixed by #338
Labels
C-enhancement Category: A new feature or an improvement for an existing one C-upstream-bug Category: This is a bug of compiler or dependencies (the fix may require action in the upstream) help wanted Call for participation: Help is requested to fix this issue

Comments

@mfreeborn
Copy link

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?

@taiki-e
Copy link
Owner

taiki-e commented Sep 19, 2022

As for the second issue, it is the same issue as rust-lang/rust#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 taiki-e added C-enhancement Category: A new feature or an improvement for an existing one help wanted Call for participation: Help is requested to fix this issue C-upstream-bug Category: This is a bug of compiler or dependencies (the fix may require action in the upstream) labels Sep 19, 2022
@njelich
Copy link
Contributor

njelich commented Sep 27, 2023

@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.

@taiki-e
Copy link
Owner

taiki-e commented Sep 27, 2023

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.

@fzyzcjy
Copy link

fzyzcjy commented Dec 19, 2023

Hi, is there any updates? Thanks! (I guess no...? :/ )

@njelich
Copy link
Contributor

njelich commented Dec 19, 2023

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.

@aDogCalledSpot
Copy link

aDogCalledSpot commented Jan 14, 2024

With rustwasm/wasm-bindgen#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: A new feature or an improvement for an existing one C-upstream-bug Category: This is a bug of compiler or dependencies (the fix may require action in the upstream) help wanted Call for participation: Help is requested to fix this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants