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

Separate Yew Platform #2893

Merged
merged 10 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 7 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
12 changes: 0 additions & 12 deletions ci/feature-soundness-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,3 @@ cargo clippy --release --no-default-features --features default,ssr -- --deny=wa
cargo clippy --release --no-default-features --features csr,default,ssr -- --deny=warnings
cargo clippy --release --no-default-features --features hydration,ssr -- --deny=warnings
cargo clippy --release --no-default-features --features default,hydration,ssr -- --deny=warnings
cargo clippy --release --no-default-features --features tokio -- --deny=warnings
cargo clippy --release --no-default-features --features csr,tokio -- --deny=warnings
cargo clippy --release --no-default-features --features default,tokio -- --deny=warnings
cargo clippy --release --no-default-features --features csr,default,tokio -- --deny=warnings
cargo clippy --release --no-default-features --features hydration,tokio -- --deny=warnings
cargo clippy --release --no-default-features --features default,hydration,tokio -- --deny=warnings
cargo clippy --release --no-default-features --features ssr,tokio -- --deny=warnings
cargo clippy --release --no-default-features --features csr,ssr,tokio -- --deny=warnings
cargo clippy --release --no-default-features --features default,ssr,tokio -- --deny=warnings
cargo clippy --release --no-default-features --features csr,default,ssr,tokio -- --deny=warnings
cargo clippy --release --no-default-features --features hydration,ssr,tokio -- --deny=warnings
cargo clippy --release --no-default-features --features default,hydration,ssr,tokio -- --deny=warnings
Comment on lines -21 to -32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume they move to prokio, correct?

Copy link
Member Author

@futursolo futursolo Oct 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is removed completely and does not present in prokio as well. As previously mentioned, the tokio feature is not very useful. I expect the current situation to stay years before it changes. So I guess it might be better to remove tokio feature and read it when we need it.

12 changes: 0 additions & 12 deletions ci/feature-soundness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,3 @@ cargo clippy --no-default-features --features default,ssr -- --deny=warnings
cargo clippy --no-default-features --features csr,default,ssr -- --deny=warnings
cargo clippy --no-default-features --features hydration,ssr -- --deny=warnings
cargo clippy --no-default-features --features default,hydration,ssr -- --deny=warnings
cargo clippy --no-default-features --features tokio -- --deny=warnings
cargo clippy --no-default-features --features csr,tokio -- --deny=warnings
cargo clippy --no-default-features --features default,tokio -- --deny=warnings
cargo clippy --no-default-features --features csr,default,tokio -- --deny=warnings
cargo clippy --no-default-features --features hydration,tokio -- --deny=warnings
cargo clippy --no-default-features --features default,hydration,tokio -- --deny=warnings
cargo clippy --no-default-features --features ssr,tokio -- --deny=warnings
cargo clippy --no-default-features --features csr,ssr,tokio -- --deny=warnings
cargo clippy --no-default-features --features default,ssr,tokio -- --deny=warnings
cargo clippy --no-default-features --features csr,default,ssr,tokio -- --deny=warnings
cargo clippy --no-default-features --features hydration,ssr,tokio -- --deny=warnings
cargo clippy --no-default-features --features default,hydration,ssr,tokio -- --deny=warnings
20 changes: 16 additions & 4 deletions examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/futures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
pulldown-cmark = { version = "0.9", default-features = false }
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
yew = { path = "../../packages/yew", features = ["tokio", "csr"] }
yew = { path = "../../packages/yew", features = ["csr"] }
gloo = "0.8"

[dependencies.web-sys]
Expand Down
2 changes: 1 addition & 1 deletion examples/js_callback/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"

[dependencies]
wasm-bindgen = "0.2"
yew = { path = "../../packages/yew", features = ["csr", "tokio"] }
yew = { path = "../../packages/yew", features = ["csr"] }
wasm-bindgen-futures = "0.4"
js-sys = "0.3"
once_cell = "1"
2 changes: 1 addition & 1 deletion examples/simple_ssr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ clap = { version = "3.1.7", features = ["derive"] }

[features]
hydration = ["yew/hydration"]
ssr = ["yew/ssr", "yew/tokio"]
ssr = ["yew/ssr"]
2 changes: 1 addition & 1 deletion examples/ssr_router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ hyper = { version = "0.14", features = ["server", "http1"] }
jemallocator = "0.5"

[features]
ssr = ["yew/ssr", "yew/tokio"]
ssr = ["yew/ssr"]
hydration = ["yew/hydration"]
28 changes: 11 additions & 17 deletions packages/yew/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,21 @@ slab = "0.4"
wasm-bindgen = "0.2"
yew-macro = { version = "^0.19.0", path = "../yew-macro" }
thiserror = "1.0"
futures = { version = "0.3", default-features = false, features = ["std", "async-await"] }
futures = { version = "0.3", default-features = false, features = ["std"] }
html-escape = { version = "0.2.9", optional = true }
implicit-clone = { version = "0.3", features = ["map"] }
base64ct = { version = "1.5.0", features = ["std"], optional = true }
bincode = { version = "1.3.3", optional = true }
serde = { version = "1", features = ["derive"] }
tracing = "0.1.36"
pin-project = "1.0.11"
prokio = "0.1.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen-futures = "0.4"
Comment on lines +38 to +39
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we still need a direct dependency on this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is due to yew is using wasm_bindgen_futures::JsFuture in a couple places.


[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
# We still need tokio as we have docs linked to it.
tokio = { version = "1.19", features = ["rt"] }

[dependencies.web-sys]
version = "^0.3.59"
Expand Down Expand Up @@ -69,21 +76,12 @@ features = [
"SubmitEvent"
]

[target.'cfg(target_arch = "wasm32")'.dependencies]
# we move it here so no promise-based spawn_local can present for
# non-wasm32 targets.
wasm-bindgen-futures = "0.4"

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

[dev-dependencies]
wasm-bindgen-test = "0.3"
gloo = { version = "0.8", features = ["futures"] }
wasm-bindgen-futures = "0.4"
rustversion = "1"
trybuild = "1"

Expand All @@ -95,15 +93,11 @@ features = [
]

[features]
tokio = ["dep:tokio", "dep:num_cpus", "dep:tokio-stream"]
ssr = ["dep:html-escape", "dep:base64ct", "dep:bincode"]
csr = []
hydration = ["csr", "dep:bincode"]
default = []

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

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "documenting"]
2 changes: 1 addition & 1 deletion packages/yew/Makefile.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tasks.native-test]
command = "cargo"
args = ["test", "--features", "csr,ssr,hydration,tokio"]
args = ["test", "--features", "csr,ssr,hydration"]

[tasks.wasm-test]
command = "wasm-pack"
Expand Down
1 change: 0 additions & 1 deletion packages/yew/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
//! - `csr`: Enables Client-side Rendering support and [`Renderer`]. Only enable this feature if you
//! are making a Yew application (not a library).
//! - `ssr`: Enables Server-side Rendering support and [`ServerRenderer`].
//! - `tokio`: Enables future-based APIs on non-wasm32 targets with tokio runtime.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both tokio on wasi with threading support and async-std's spawn_local are unstable.
tokio and wasm-bindgen-futures are going to be the only runtime that is supported by prokio for the moment.

Hence, I feel it might be better to forego the tokio feature until we need it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this this way. Tokio is hidden behind the pseudo-runtime (prokio) and doesn't need to be exposed here.

//! - `hydration`: Enables Hydration support.
//!
//! ## Example
Expand Down
48 changes: 48 additions & 0 deletions packages/yew/src/platform.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//! Yew's compatibility between JavaScript Runtime and Native Runtimes.
//!
//! This module is also published under the name [prokio](crate@prokio) on crates.io.
//!
//! # Rationale
//!
//! When designing components and libraries that works on both WebAssembly targets backed by
//! JavaScript Runtime and non-WebAssembly targets with Native Runtimes. Developers usually face
//! challenges that requires applying multiple feature flags throughout their application:
//!
//! 1. Select I/O and timers that works with the target runtime.
//! 2. Native Runtimes usually require `Send` futures and WebAssembly types are usually `!Send`.
//!
//! # Implementation
//!
//! To alleviate these issues, Yew implements a single-threaded runtime that executes `?Send`
//! (`Send` or `!Send`) futures.
//!
//! On platforms with multi-threading support, Yew spawns multiple independent runtimes
//! proportional to the CPU core number. When tasks are spawned with a runtime handle, it will
//! randomly select a worker thread from the internal pool. All tasks spawned with `spawn_local`
//! will run on the same thread as the thread the task was running. When the runtime runs in a
//! WebAssembly target, all tasks will be scheduled on the main thread.
//!
//! This runtime is designed in favour of IO-bounded workload with similar runtime cost.
//! When running I/O workloads, it would produce a slightly better performance as tasks are
//! never moved to another thread. However, If a worker thread is busy,
//! other threads will not be able to steal tasks scheduled on the busy thread.
//! When you have a CPU-bounded task where CPU time is significantly
//! more expensive, it should be spawned with a dedicated thread (or Web Worker) and communicates
//! with the application using channels.
//!
//! Yew platform provides the following components:
//!
//! 1. A Task Scheduler that is capable of running non-Send tasks.
//! 2. A Timer that is compatible with the scheduler backend.
//! 3. Task Synchronisation Mechanisms.
//!
//! # Runtime Backend
//!
//! The Yew runtime is implemented with different runtimes depending on the target platform and can
//! use all features (timers / IO / task synchronisation) from the selected native runtime:
//!
//! - `wasm-bindgen-futures` (WebAssembly targets)
//! - `tokio` (non-WebAssembly targets)

#[doc(inline)]
pub use prokio::*;
Comment on lines +47 to +48
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can put this in lib.rs to have the same effect:

#[doc(inline)]
pub use prokio as platform;

That way you can avoid duplicating the doc comments.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentional. The documentation of yew::platform and prokio is slightly different. The wording is adjusted to mention Yew in the documentation.

Loading