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

Add WASI support by tokio_wasi #11

Merged
merged 7 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,27 @@ repository = "https://github.com/futursolo/prokio"
rust-version = "1.60.0"

[dependencies]
futures = { version = "0.3", default-features = false, features = ["std", "async-await"] }
futures = { version = "0.3", default-features = false, features = [
"std",
"async-await",
] }
pin-project = "1.0.11"
pinned = "0.1.0"
once_cell = "1"

[target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi")))'.dependencies]
wasm-bindgen-futures = { version = "0.4" }
gloo = { version = "0.11" }

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen-futures = "0.4"
gloo = "0.8"
[target.'cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))'.dependencies]
tokio = { version = "1", features = ["rt", "time"] }
langyo marked this conversation as resolved.
Show resolved Hide resolved
tokio-stream = { version = "0.1", features = ["time"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
num_cpus = "1.13"
once_cell = "1"
tokio = { version = "1.21.1", features = ["rt", "time"] }
tokio-stream = { version = "0.1", features = ["time"] }

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
tokio = { version = "1.19", features = ["full"] }
tokio = { version = "1", features = ["full"] }

[features]
default = []
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ pub mod fmt;
pub mod pinned;
pub mod time;

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
#[path = "rt_wasm_bindgen/mod.rs"]
mod imp;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))]
#[path = "rt_tokio/mod.rs"]
mod imp;

Expand Down
10 changes: 9 additions & 1 deletion src/rt_tokio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ use local_worker::LocalWorker;
pub(crate) fn get_default_runtime_size() -> usize {
// We use num_cpus as std::thread::available_parallelism() does not take
// system resource constraint (e.g.: cgroups) into consideration.
num_cpus::get()
#[cfg(not(target_os = "wasi"))]
{
num_cpus::get()
}
// WASI does not support multi-threading at this moment.
#[cfg(target_os = "wasi")]
{
1
}
}

#[inline(always)]
Expand Down
Loading