From a6a95bb4a62da4706f07657394c8dbcafe26bfc9 Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Fri, 2 Sep 2022 11:39:38 +0200 Subject: [PATCH] wasm: add documentation for wasm support (#4966) --- tokio/src/lib.rs | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/tokio/src/lib.rs b/tokio/src/lib.rs index 804d0bf1301..3de3d21ef7e 100644 --- a/tokio/src/lib.rs +++ b/tokio/src/lib.rs @@ -383,6 +383,39 @@ //! //! [unstable features]: https://internals.rust-lang.org/t/feature-request-unstable-opt-in-non-transitive-crate-features/16193#why-not-a-crate-feature-2 //! [feature flags]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section +//! +//! ## WASM support +//! +//! Tokio has some limited support for the WASM platform. Without the +//! `tokio_unstable` flag, the following features are supported: +//! +//! * `sync` +//! * `macros` +//! * `io-util` +//! * `rt` +//! * `time` +//! +//! Enabling any other feature (including `full`) will cause a compilation +//! failure. +//! +//! The `time` module will only work on WASM platforms that have support for +//! timers (e.g. wasm32-wasi). The timing functions will panic if used on a WASM +//! platform that does not support timers. +//! +//! Note also that if the runtime becomes indefinitely idle, it will panic +//! immediately instead of blocking forever. On platforms that don't support +//! time, this means that the runtime can never be idle in any way. +//! +//! ### Unstable WASM support +//! +//! Tokio also has unstable support for some additional WASM features. This +//! requires the use of the `tokio_unstable` flag. +//! +//! Using this flag enables the use of `tokio::net` on the wasm32-wasi target. +//! However, not all methods are available on the networking types as WASI +//! currently does not support the creation of new sockets from within WASM. +//! Because of this, sockets must currently be created via the `FromRawFd` +//! trait. // Test that pointer width is compatible. This asserts that e.g. usize is at // least 32 bits, which a lot of components in Tokio currently assumes. @@ -426,7 +459,7 @@ compile_error!("Tokio's build script has incorrectly detected wasm."); feature = "signal" ) ))] -compile_error!("Only features sync,macros,io-util,rt are supported on wasm."); +compile_error!("Only features sync,macros,io-util,rt,time are supported on wasm."); // Includes re-exports used by macros. //