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

Rework a bunch of cfg(feature) flags to be more principled #2666

Merged
merged 10 commits into from
May 7, 2022
6 changes: 3 additions & 3 deletions .github/workflows/main-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: -p yew --doc --features doc_test --target wasm32-unknown-unknown
args: -p yew --doc --all-features --target wasm32-unknown-unknown

integration_tests:
name: Integration Tests on ${{ matrix.toolchain }}
Expand Down Expand Up @@ -159,8 +159,8 @@ jobs:
- name: Run tests - yew
run: |
cd packages/yew
CHROMEDRIVER=$(which chromedriver) cargo test --features wasm_test --target wasm32-unknown-unknown
GECKODRIVER=$(which geckodriver) cargo test --features wasm_test --target wasm32-unknown-unknown
CHROMEDRIVER=$(which chromedriver) cargo test --features csr,hydration,ssr --target wasm32-unknown-unknown
GECKODRIVER=$(which geckodriver) cargo test --features csr,hydration,ssr --target wasm32-unknown-unknown

- name: Run tests - yew-router
run: |
Expand Down
5 changes: 3 additions & 2 deletions examples/function_router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ instant = { version = "0.1", features = ["wasm-bindgen"] }
[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.2", features = ["js"] }

[features]
csr = ["yew/csr"]
[[bin]]
name = "function_router"
required-features = ["yew/csr"]
2 changes: 1 addition & 1 deletion examples/function_router/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
href="https://cdn.jsdelivr.net/npm/bulma@0.9.0/css/bulma.min.css"
/>
<link data-trunk rel="sass" href="index.scss" />
<link data-trunk rel="rust" data-cargo-features="csr" data-bin="function_router" />
<link data-trunk rel="rust" data-cargo-features="yew/csr" data-bin="function_router" />
</head>

<body></body>
Expand Down
1 change: 0 additions & 1 deletion examples/function_router/src/bin/function_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ pub use function_router::*;

fn main() {
wasm_logger::init(wasm_logger::Config::new(log::Level::Trace));
#[cfg(feature = "csr")]
yew::Renderer::<App>::new().render();
}
2 changes: 1 addition & 1 deletion examples/ssr_router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
yew = { path = "../../packages/yew", features = ["ssr", "hydration", "trace_hydration"] }
yew = { path = "../../packages/yew", features = ["ssr", "hydration"] }
function_router = { path = "../function_router" }
log = "0.4"

Expand Down
2 changes: 1 addition & 1 deletion examples/suspense/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
yew = { path = "../../packages/yew", features = ["tokio", "csr"] }
yew = { path = "../../packages/yew", features = ["csr"] }
gloo-timers = { version = "0.2.2", features = ["futures"] }
wasm-bindgen-futures = "0.4"
wasm-bindgen = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion examples/suspense/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn app_content() -> HtmlResult {
})
};

let on_take_a_break = Callback::from(move |_| (resleep.clone())());
let on_take_a_break = Callback::from(move |_| resleep());

Ok(html! {
<div class="content-area">
Expand Down
1 change: 0 additions & 1 deletion packages/yew-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ yew = { path = "../yew" }
[build-dependencies]

[features]
doc_test = []
lints = []
3 changes: 0 additions & 3 deletions packages/yew-router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ description = "A router implementation for the Yew framework"
repository = "https://github.com/yewstack/yew"
rust-version = "1.56.0"

[features]
wasm_test = []

[dependencies]
yew = { version = "0.19.3", path = "../yew", default-features= false }
yew-router-macro = { version = "0.16.0", path = "../yew-router-macro" }
Expand Down
9 changes: 4 additions & 5 deletions packages/yew/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,16 @@ features = [
]

[features]
ssr = ["futures", "html-escape"]
# TODO: `dep:` syntax only supported with MSRV 1.60, would be more precise
# tokio = ["dep:tokio"]
ssr = ["futures", "html-escape"] # dep:html-escape
csr = []
hydration = ["csr"]
trace_hydration = ["hydration"]
doc_test = ["csr", "hydration", "ssr"]
wasm_test = ["csr", "hydration", "ssr"]
default = []

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

[package.metadata.docs.rs]
features = ["doc_test"]
all-features = true
rustdoc-args = ["--cfg", "documenting"]
3 changes: 2 additions & 1 deletion packages/yew/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ args = [
"--headless",
"--",
"--features",
"wasm_test"
"csr,hydration,ssr",
]

[tasks.ssr-test]
command = "cargo"
args = ["test", "ssr_tests", "--features", "ssr"]

[tasks.test]
args = ["test", "--all-targets", "--all-features"]
dependencies = ["native-test", "wasm-test"]

[tasks.clippy-feature-soundness]
Expand Down
2 changes: 1 addition & 1 deletion packages/yew/src/app_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::dom_bundle::BSubtree;
use crate::html::{BaseComponent, NodeRef, Scope, Scoped};

/// An instance of an application.
#[derive(Debug)]
#[cfg_attr(documenting, doc(cfg(feature = "csr")))]
#[derive(Debug)]
pub struct AppHandle<COMP: BaseComponent> {
/// `Scope` holder
pub(crate) scope: Scope<COMP>,
Expand Down
4 changes: 2 additions & 2 deletions packages/yew/src/dom_bundle/bcomp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ mod feat_hydration {
}
}

#[cfg(feature = "wasm_test")]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
mod tests {
use std::ops::Deref;
Expand Down Expand Up @@ -481,7 +481,7 @@ mod tests {
}
}

#[cfg(feature = "wasm_test")]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
mod layout_tests {
extern crate self as yew;
Expand Down
8 changes: 4 additions & 4 deletions packages/yew/src/dom_bundle/blist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,11 @@ mod feat_hydration {
}
}

#[cfg(all(test, feature = "wasm_test"))]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
mod layout_tests {
extern crate self as yew;

#[cfg(feature = "wasm_test")]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

use crate::html;
Expand Down Expand Up @@ -581,11 +581,11 @@ mod layout_tests {
}
}

#[cfg(all(test, feature = "wasm_test"))]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
mod layout_tests_keys {
extern crate self as yew;

#[cfg(feature = "wasm_test")]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};
use web_sys::Node;

Expand Down
4 changes: 2 additions & 2 deletions packages/yew/src/dom_bundle/bnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ mod feat_hydration {
}
}

#[cfg(all(test, feature = "wasm_test"))]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
mod layout_tests {
#[cfg(feature = "wasm_test")]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

use super::*;
Expand Down
4 changes: 2 additions & 2 deletions packages/yew/src/dom_bundle/bportal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ impl BPortal {
}
}

#[cfg(all(test, feature = "wasm_test"))]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
mod layout_tests {
extern crate self as yew;

#[cfg(feature = "wasm_test")]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};
use yew::virtual_dom::VPortal;

Expand Down
2 changes: 1 addition & 1 deletion packages/yew/src/dom_bundle/btag/listeners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl Registry {
}
}

#[cfg(feature = "wasm_test")]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
mod tests {
use std::marker::PhantomData;
Expand Down
12 changes: 6 additions & 6 deletions packages/yew/src/dom_bundle/btag/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,13 @@ impl BTag {
self.key.as_ref()
}

#[cfg(feature = "wasm_test")]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
fn reference(&self) -> &Element {
&self.reference
}

#[cfg(feature = "wasm_test")]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
fn children(&self) -> &[BNode] {
match &self.inner {
Expand All @@ -280,7 +280,7 @@ impl BTag {
}
}

#[cfg(feature = "wasm_test")]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
fn tag(&self) -> &str {
match &self.inner {
Expand Down Expand Up @@ -383,7 +383,7 @@ mod feat_hydration {
}
}

#[cfg(feature = "wasm_test")]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
mod tests {
use gloo_utils::document;
Expand Down Expand Up @@ -975,11 +975,11 @@ mod tests {
}
}

#[cfg(all(test, feature = "wasm_test"))]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
mod layout_tests {
extern crate self as yew;

#[cfg(feature = "wasm_test")]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

use crate::html;
Expand Down
8 changes: 4 additions & 4 deletions packages/yew/src/dom_bundle/btext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ mod feat_hydration {
mod test {
extern crate self as yew;

#[cfg(feature = "wasm_test")]
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

use crate::html;

#[cfg(feature = "wasm_test")]
#[cfg(target_arch = "wasm32")]
wasm_bindgen_test_configure!(run_in_browser);

#[test]
Expand All @@ -177,11 +177,11 @@ mod test {
}
}

#[cfg(all(test, feature = "wasm_test"))]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
mod layout_tests {
extern crate self as yew;

#[cfg(feature = "wasm_test")]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

use crate::html;
Expand Down
4 changes: 2 additions & 2 deletions packages/yew/src/dom_bundle/fragment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::ops::{Deref, DerefMut};

use web_sys::{Element, Node};

use super::BSubtree;
use crate::dom_bundle::BSubtree;
use crate::html::NodeRef;
use crate::virtual_dom::Collectable;

/// A Hydration Fragment
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub(crate) struct Fragment(VecDeque<Node>);
pub struct Fragment(VecDeque<Node>);

impl Deref for Fragment {
type Target = VecDeque<Node>;
Expand Down
22 changes: 10 additions & 12 deletions packages/yew/src/dom_bundle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ mod btag;
mod btext;
mod subtree_root;

#[cfg(feature = "hydration")]
mod fragment;

mod traits;
mod utils;

Expand All @@ -32,16 +29,9 @@ use bportal::BPortal;
use bsuspense::BSuspense;
use btag::{BTag, Registry};
use btext::BText;
#[cfg(feature = "hydration")]
pub(crate) use fragment::Fragment;
pub use subtree_root::set_event_bubbling;
pub(crate) use subtree_root::BSubtree;
use subtree_root::EventDescriptor;
#[cfg(feature = "hydration")]
use traits::Hydratable;
pub use subtree_root::{set_event_bubbling, BSubtree};
use traits::{Reconcilable, ReconcileTarget};
#[cfg(feature = "hydration")]
use utils::node_type_str;
use utils::{insert_node, test_log};

/// A Bundle.
Expand Down Expand Up @@ -84,9 +74,15 @@ impl Bundle {
}

#[cfg(feature = "hydration")]
#[path = "."]
mod feat_hydration {
use super::*;
pub(super) use super::traits::Hydratable;
pub(super) use super::utils::node_type_str;
#[path = "./fragment.rs"]
mod fragment;
pub use fragment::Fragment;

use super::*;
impl Bundle {
/// Creates a bundle by hydrating a virtual dom layout.
pub fn hydrate(
Expand All @@ -101,3 +97,5 @@ mod feat_hydration {
}
}
}
#[cfg(feature = "hydration")]
pub(crate) use feat_hydration::*;
4 changes: 2 additions & 2 deletions packages/yew/src/dom_bundle/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ pub(super) fn insert_node(node: &Node, parent: &Element, next_sibling: Option<&N
};
}

#[cfg(all(test, feature = "wasm_test", verbose_tests))]
#[cfg(all(test, target_arch = "wasm32", verbose_tests))]
macro_rules! test_log {
($fmt:literal, $($arg:expr),* $(,)?) => {
::wasm_bindgen_test::console_log!(concat!("\t ", $fmt), $($arg),*);
};
}
#[cfg(not(all(test, feature = "wasm_test", verbose_tests)))]
#[cfg(not(all(test, target_arch = "wasm32", verbose_tests)))]
macro_rules! test_log {
($fmt:literal, $($arg:expr),* $(,)?) => {
// Only type-check the format expression, do not run any side effects
Expand Down
Loading