Skip to content

Commit

Permalink
wasm: add documentation for wasm support (#4966)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darksonn committed Sep 2, 2022
1 parent ce5d2a4 commit a6a95bb
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion tokio/src/lib.rs
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
//
Expand Down

0 comments on commit a6a95bb

Please sign in to comment.