-
Notifications
You must be signed in to change notification settings - Fork 319
feat(libsy): support wasm32-unknown-unknown targets #829
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
base: main
Are you sure you want to change the base?
Changes from all commits
9956fde
c857d8d
aad840f
26fe647
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| //! Runtime abstraction over task spawning and monotonic clocks, so the crate | ||
| //! runs on native Tokio hosts and on single-threaded wasm32 hosts (browsers, | ||
| //! Cloudflare Workers) alike. | ||
|
|
||
| /// Monotonic instant. On wasm32 `std::time::Instant::now()` aborts, so a | ||
| /// JS-clock-backed drop-in replacement is used there. | ||
| #[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] | ||
| pub(crate) use std::time::Instant; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we scope the JS branches to
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 26fe647: every JS branch ( |
||
| #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] | ||
| pub(crate) use web_time::Instant; | ||
|
|
||
| /// Handle that aborts the task returned by [`spawn_abortable`]. | ||
| #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] | ||
| pub(crate) use futures::future::AbortHandle; | ||
| #[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] | ||
| pub(crate) use tokio::task::AbortHandle; | ||
|
|
||
| /// Spawns a future on the host runtime and returns a handle that aborts it. | ||
| #[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] | ||
| pub(crate) fn spawn_abortable<F>(future: F) -> AbortHandle | ||
| where | ||
| F: std::future::Future<Output = ()> + Send + 'static, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we leave the native path on Tokio's own abort handle? This adds a
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 26fe647: native |
||
| { | ||
| tokio::spawn(future).abort_handle() | ||
| } | ||
|
|
||
| /// Spawns a future on the JS microtask queue and returns a handle that aborts it. | ||
| #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] | ||
| pub(crate) fn spawn_abortable<F>(future: F) -> AbortHandle | ||
| where | ||
| F: std::future::Future<Output = ()> + 'static, | ||
| { | ||
| let (handle, registration) = AbortHandle::new_pair(); | ||
| wasm_bindgen_futures::spawn_local(async move { | ||
| let _ = futures::future::Abortable::new(future, registration).await; | ||
| }); | ||
| handle | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a compile/lint check, not a Worker or browser runtime test. I think that's fine if we call this compile support for Rust wasm hosts. If we're claiming runtime support, we should add a small smoke test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compile support is the claim. The PR body's first line says "compile for wasm32-unknown-unknown", and the CI step is a clippy check on that target. Our Worker runs it at runtime on our side; a smoke test in this repo can come in a follow-up if the team wants to claim runtime support.