-
Notifications
You must be signed in to change notification settings - Fork 754
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
Add support for WebAssembly #642
Comments
I believe
Finally, if we want to officially support these targets, we'd need a CI job that ensures |
If someone who's more familiar with wasm than I am is interested in helping out with this, please let me know — I'm happy to provide guidance on the |
I don't know about other features that might be an issue but
This is something I would be interested in helping with but realistically it might be awhile (couple weeks or so) before I could do much. |
Oh, cool — I didn't know that! In that case, I think that |
I did a quick test, and it looks like every crate in the repo builds fine for We should probably be checking this on CI before we say that wasm targets are officially supported, though. |
Hey @hawkw , I'd be happy to take a look at adding this to CI if that's the next step? I assume that's just modifying the github actions file to also start targeting' |
@securityinsanity Thanks, that would be great! I think just adding the targets to GitHub Actions is a good first step, but there might be more to it than that? I'm not sure what the Rust testing story for I also suspect that at least some of the tests may not pass on wasm, since they rely on things like |
Looking at it for another crate, that seems to be the case yeah. Building is easy, executing the tests is currently not the best story: rustwasm/team#173 (seems to be |
Great, thank you! Do let me know if you have any questions about stuff on the |
So I've started working on this, and most things truly "just work" with
Unfortunately there is one snag, I'm particularly not too fond of, and would like an idea of what would be the easiest for the project long term. So testing currently requires tagging tests with: So for example: #[test]
fn default_name_test() {
let (subscriber, handle) = subscriber::mock()
.new_span(span::mock().named("default_name"))
.enter(span::mock().named("default_name"))
.exit(span::mock().named("default_name"))
.done()
.run_with_handle();
with_default(subscriber, || {
default_name();
});
handle.assert_finished();
} Becomes: #[test]
#[wasm_bindgen_test]
fn default_name_test() {
let (subscriber, handle) = subscriber::mock()
.new_span(span::mock().named("default_name"))
.enter(span::mock().named("default_name"))
.exit(span::mock().named("default_name"))
.done()
.run_with_handle();
with_default(subscriber, || {
default_name();
});
handle.assert_finished();
} In this case testing for wasm is "opt in". There is currently no way to just have: TBH I can't think of a solution that looks really good here, adding a custom test macro that by default runs test && wasm-bindgen-test, and force everyone to rebase? Introduce a linter where new tests added that are tagged test, without I'd appreciate some insight as what to would be easier for y'all, I'd be happy to really take any solution, just wanna make sure it's the easiest for everyone involved. Thanks! |
Hmm...in order to include the I think just making the change crate-by-crate is probably the best approach, but I'm not sure. It would be good to get input from other contributors on that. Why don't we start with a PR that just builds the crates for wasm targets on CI< and then add support for actually testing them in a follow-up? |
Yeah, there's a dev-dependency on
Yeah, we can do that. I'll give it a bit to give others a chance to chime in, but will prepare it on my side 😄 . |
Okay, that sounds fine. Let's make sure that this dependency is in [target.'cfg(target_arch = "wasm32)'.dev-dependencies] and similar, so that it doesn't need to be downloaded when running the test for other targets? Thanks for working on this! |
Yep, I've got that locally to ensure it's good! |
👋 Hi @securityinsanity, any updates on this? I've noticed that a handful of subscriber implementations for emitting diagnostics from Let me know if there are any blockers? |
Ah sorry I just forgot to come back to this! I can push up the building Pr later today as I assume most people have had a chance to respond back by now. 😄 |
Great! No real rush, I just wanted to see where you were at and if you were stuck on anything. Thanks again! |
refs tokio-rs#642 start building all crates, except `tracing-futures` in wasm32-unknown-unknown. this will validate going forward we don't break wasm32 build support. in the future we can start running tests crate by crate, and actually run those tests. the reason we're doing this is every single test has to be marked with another special attribute, and add a dev-only dependency. we don't wanna create a huge pr that has to have conflicts fixed all the time. in the future we can also look at adding in support for tracing-futures.
refs #642 ## Motivation More, and more code is targeting wasm architectures. This is useful for not only browsers, but also useful for environments that want extensibility where the host environment is protected, but still allows extensibility in a variety of languages. Tracing can help these architectures just as it can any other architecture. ## Solution start building all crates, except `tracing-futures` in wasm32-unknown-unknown architecture. this will validate going forward we don't break wasm32 build support. in the future we can start running tests crate by crate, and actually run those tests. the reason we're doing this is every single test has to be marked with another special attribute, and add a dev-only dependency. we don't wanna create a huge pr that has to have conflicts fixed all the time. in the future we can also look at adding in support for tracing-futures.
## Motivation refs #642 Start Testing the core crate in a wasm environment. This requires a special runner, and an extra dev-dependency. All tests have been ported over except for `span::spans_always_go_to_the_subscriber_that_tagged_them_even_across_threads` because that spins up a thread, and wasm has no concept of threads being spun up. ## Solution Add a wasm-pack tester, and properly tag all tests.
Just a note that: #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] is not enough, since For WASI ( So it should be: #[cfg_attr(all(target_arch = "wasm32", not(target_os = "wasi")), wasm_bindgen_test::wasm_bindgen_test)] |
I don't know if this is still a desired feature, but to make Though I'm happy to go further and actually add compatibility to |
Feature Request
Crates
tracing = "0.1.13"
tracing-subscriber = "0.2.3"
Motivation
To use Tracing in web frontend in addition to web backend.
Proposal
Support the build targets
wasm32-unknown-unknown
andwasm32-wasi
.Alternatives
Using a different tracing package for the frontend would introduce unnecessary complexity.
The text was updated successfully, but these errors were encountered: