Skip to content

Commit

Permalink
Add WASI support by tokio_wasi (#11)
Browse files Browse the repository at this point in the history
* Try to add WASI target support.

* Enable tokio_wasi by wasi feature.

* Add the impl for wasi environment.

* Use target_os instead of feature.

* Remove unused tokio_wasi module, use offical tokio instead.

* Use same original `tokio`.

* Pin tokio's version.
  • Loading branch information
langyo authored Dec 11, 2023
1 parent 2056845 commit 83d97d4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
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.35", features = ["rt", "time"] }
tokio-stream = { version = "0.1.14", 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

0 comments on commit 83d97d4

Please sign in to comment.