From 65536409afad51f9b8956dedba323307fd3ce393 Mon Sep 17 00:00:00 2001 From: Finn Bear Date: Tue, 23 May 2023 22:16:00 -0700 Subject: [PATCH 01/11] Fix #120 - don't compile in JsValue in proc_macro. --- packages/stylist-core/Cargo.toml | 1 + packages/stylist-core/src/error.rs | 1 + packages/stylist-macros/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/stylist-core/Cargo.toml b/packages/stylist-core/Cargo.toml index 19c801d..6f1a291 100644 --- a/packages/stylist-core/Cargo.toml +++ b/packages/stylist-core/Cargo.toml @@ -37,3 +37,4 @@ wasm-bindgen-test = "0.3.33" [features] parser = ["dep:nom"] +proc_macro = [] \ No newline at end of file diff --git a/packages/stylist-core/src/error.rs b/packages/stylist-core/src/error.rs index ff64393..296999d 100644 --- a/packages/stylist-core/src/error.rs +++ b/packages/stylist-core/src/error.rs @@ -16,6 +16,7 @@ pub enum Error { /// /// This is usually raised when the style element failed to mount. #[error("Failed to Interact with Web API. Are you running in Browser?")] + #[cfg(not(feature = "proc_macro"))] Web(Option), /// Failed to read styles from the StyleManager. diff --git a/packages/stylist-macros/Cargo.toml b/packages/stylist-macros/Cargo.toml index db6e308..6e0c5a3 100644 --- a/packages/stylist-macros/Cargo.toml +++ b/packages/stylist-macros/Cargo.toml @@ -25,7 +25,7 @@ rust-version = "1.60" proc-macro = true [dependencies] -stylist-core = { path = "../stylist-core", version = "0.12", features = ["parser"] } +stylist-core = { path = "../stylist-core", version = "0.12", features = ["parser", "proc_macro"] } litrs = "0.4.0" proc-macro-error = "1.0.4" From 9272103c1b5e7485dfda7b3e2cf6feb9a0542002 Mon Sep 17 00:00:00 2001 From: Finn Bear Date: Tue, 23 May 2023 22:37:19 -0700 Subject: [PATCH 02/11] Different approach - don't compile in JsValue outside wasm32. --- packages/stylist-core/Cargo.toml | 3 +-- packages/stylist-core/src/error.rs | 8 ++++++-- packages/stylist-macros/Cargo.toml | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/stylist-core/Cargo.toml b/packages/stylist-core/Cargo.toml index 6f1a291..76136fe 100644 --- a/packages/stylist-core/Cargo.toml +++ b/packages/stylist-core/Cargo.toml @@ -36,5 +36,4 @@ env_logger = "0.10.0" wasm-bindgen-test = "0.3.33" [features] -parser = ["dep:nom"] -proc_macro = [] \ No newline at end of file +parser = ["dep:nom"] \ No newline at end of file diff --git a/packages/stylist-core/src/error.rs b/packages/stylist-core/src/error.rs index 296999d..952f528 100644 --- a/packages/stylist-core/src/error.rs +++ b/packages/stylist-core/src/error.rs @@ -1,5 +1,10 @@ use thiserror::Error; +#[cfg(target_arch = "wasm32")] +type JsValue = wasm_bindgen::JsValue; +#[cfg(not(target_arch = "wasm32"))] +type JsValue = (); + #[derive(Debug, Error, PartialEq)] pub enum Error { /// Failed to parse CSS. @@ -16,8 +21,7 @@ pub enum Error { /// /// This is usually raised when the style element failed to mount. #[error("Failed to Interact with Web API. Are you running in Browser?")] - #[cfg(not(feature = "proc_macro"))] - Web(Option), + Web(Option), /// Failed to read styles from the StyleManager. /// diff --git a/packages/stylist-macros/Cargo.toml b/packages/stylist-macros/Cargo.toml index 6e0c5a3..db6e308 100644 --- a/packages/stylist-macros/Cargo.toml +++ b/packages/stylist-macros/Cargo.toml @@ -25,7 +25,7 @@ rust-version = "1.60" proc-macro = true [dependencies] -stylist-core = { path = "../stylist-core", version = "0.12", features = ["parser", "proc_macro"] } +stylist-core = { path = "../stylist-core", version = "0.12", features = ["parser"] } litrs = "0.4.0" proc-macro-error = "1.0.4" From 9cb8927ab0f853390f1607ae5c505ed1a24a6812 Mon Sep 17 00:00:00 2001 From: Finn Bear Date: Tue, 23 May 2023 22:37:59 -0700 Subject: [PATCH 03/11] Restore \n at EOF. --- packages/stylist-core/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/stylist-core/Cargo.toml b/packages/stylist-core/Cargo.toml index 76136fe..19c801d 100644 --- a/packages/stylist-core/Cargo.toml +++ b/packages/stylist-core/Cargo.toml @@ -36,4 +36,4 @@ env_logger = "0.10.0" wasm-bindgen-test = "0.3.33" [features] -parser = ["dep:nom"] \ No newline at end of file +parser = ["dep:nom"] From e3924025d5d632dbea81d440099f6fcffd9755e6 Mon Sep 17 00:00:00 2001 From: Kaede Hoshikawa Date: Tue, 6 Jun 2023 19:41:34 +0900 Subject: [PATCH 04/11] Use features to workaround proc macro linker error. --- packages/stylist-core/Cargo.toml | 1 + packages/stylist-core/src/ast/context.rs | 4 +--- packages/stylist-core/src/error.rs | 4 ++-- packages/stylist-macros/Cargo.toml | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/stylist-core/Cargo.toml b/packages/stylist-core/Cargo.toml index 19c801d..d5901ea 100644 --- a/packages/stylist-core/Cargo.toml +++ b/packages/stylist-core/Cargo.toml @@ -37,3 +37,4 @@ wasm-bindgen-test = "0.3.33" [features] parser = ["dep:nom"] +__proc_macro_workaround = [] diff --git a/packages/stylist-core/src/ast/context.rs b/packages/stylist-core/src/ast/context.rs index 53dffe0..ce36c96 100644 --- a/packages/stylist-core/src/ast/context.rs +++ b/packages/stylist-core/src/ast/context.rs @@ -73,9 +73,7 @@ impl<'a> StyleContext<'a> { /// Calculate the layers that current context differs from the parent context fn unique_conditions(&self) -> impl Iterator { - self.conditions() - .into_iter() - .skip(self.common_conditions().count()) + self.conditions().skip(self.common_conditions().count()) } /// Calculate the layers that parent context differs from current context diff --git a/packages/stylist-core/src/error.rs b/packages/stylist-core/src/error.rs index 952f528..cac05e7 100644 --- a/packages/stylist-core/src/error.rs +++ b/packages/stylist-core/src/error.rs @@ -1,8 +1,8 @@ use thiserror::Error; -#[cfg(target_arch = "wasm32")] +#[cfg(not(feature = "__proc_macro_workaround"))] type JsValue = wasm_bindgen::JsValue; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(feature = "__proc_macro_workaround")] type JsValue = (); #[derive(Debug, Error, PartialEq)] diff --git a/packages/stylist-macros/Cargo.toml b/packages/stylist-macros/Cargo.toml index db6e308..ba58f52 100644 --- a/packages/stylist-macros/Cargo.toml +++ b/packages/stylist-macros/Cargo.toml @@ -25,7 +25,7 @@ rust-version = "1.60" proc-macro = true [dependencies] -stylist-core = { path = "../stylist-core", version = "0.12", features = ["parser"] } +stylist-core = { path = "../stylist-core", version = "0.12", features = ["parser", "__proc_macro_workaround"] } litrs = "0.4.0" proc-macro-error = "1.0.4" From f93c06dc9b6bab3cfa7d24a7685b73537957ad94 Mon Sep 17 00:00:00 2001 From: Kaede Hoshikawa Date: Tue, 6 Jun 2023 19:53:03 +0900 Subject: [PATCH 05/11] Fix browser tests. --- CHANGELOG.md | 23 +++++++++++++++++++++-- packages/stylist-core/src/error.rs | 4 ++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 228c9b5..8822c01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,13 @@ # Changelog +### v0.12.1 + +- Implemented a workaround that mitigates the linker error from Rust compiler (https://github.com/rust-lang/rust/issues/111888). + ## v0.12.0 ### Other Changes: + - Added Server-side Rendering Support. - Fixed a reference cycle between `Style` and `StyleManager`. - Added `StyleManager::new()` to create a style manager with default configuration. @@ -10,6 +15,7 @@ ## v0.11.0 ### Breaking Changes: + - Yew version is bumped to v0.20. - Remove `YieldStyle`. This API can be easily reproduced in user code, if need be, but often leads to clumsy code in struct components. Use alternative API and prefer @@ -24,6 +30,7 @@ runtime. ### Other Changes: + - The `Style::new_*` API is more open for accepted types of the `Css` parameter. - The name of styled components now defaults to the name of the function, like in `function_component`. @@ -31,15 +38,18 @@ ## v0.10.1 ### Other Changes: + - Added an impl of `IntoPropValue` for `Style` and `StyleSource` when the `yew_integration` feature is active. ## v0.10.0 ### Breaking Changes: + - Yew version is bumped to 0.19. ### Other Changes: + - Added an API to style Yew Function Component. - `random` features is now provided with `fastrand`. - Added Yew hooks for Media Query. @@ -48,16 +58,19 @@ ## v0.9.2 ### Other Changes: + - Fixed a misconfiguration causing documentation fails to build on `docs.rs`. ## v0.9.1 ### Other Changes: + - Removed an unused import. ## v0.9 ### Breaking Changes: + - `Style` and `GlobalStyle` no longer implements `FromStr`. - `Style` and `GlobalStyle` now takes any type that implements `Into` as a source for a stylesheet. @@ -67,6 +80,7 @@ `@media`. ### Other Changes: + - Added a Procedural Macro API that parses the Stylesheet at the compile time. - Parser will now check stylesheets more strictly. @@ -82,9 +96,10 @@ ## v0.8 ### Breaking Changes: + - `Style::new()` and `Style::create()` now takes a new trait `IntoSheet` for Stylesheet which is implemented by default for both -`stylist::ast::Sheet` and everything that implements `AsRef`. + `stylist::ast::Sheet` and everything that implements `AsRef`. - Feature `yew` has been renamed back to `yew_integration`. - Selectors list now gets a class name added for each selector. - `Style` is now `!Send` and `!Sync`. @@ -92,6 +107,7 @@ and styled-components. ### Other Changes: + - Added a `GlobalStyle` struct to register global styles. - Added a `` Component for global styling for yew applications. - Supported `@supports` CSS at-rule. @@ -107,6 +123,7 @@ ## v0.7 ### Breaking Changes: + - `Style::new()` now takes an `Into>` instead of `Into` and returns `stylist::Error` instead of `String` when encountering an error. @@ -116,6 +133,7 @@ - `Style` no longer implements `ToString`. ### Other Changes: + - Added a new API `YieldStyle`. - Added theming examples. - Styles are now cached by default. @@ -125,15 +143,16 @@ - Removed Unnecessary Clones. - Optimised for Performance. - ## v0.6 ### Breaking Changes: + - `style.get_class_name()` no longer consumes the style and returns a `&str` instead of an owned string. - Seed Integration is Removed. ### Other Changes: + - Added `Style::new` which does not require a component name. - Aesthetically pleasing Class Name. - Replaced `lazy_static` with `once_cell`. diff --git a/packages/stylist-core/src/error.rs b/packages/stylist-core/src/error.rs index cac05e7..ac24f6a 100644 --- a/packages/stylist-core/src/error.rs +++ b/packages/stylist-core/src/error.rs @@ -1,8 +1,8 @@ use thiserror::Error; -#[cfg(not(feature = "__proc_macro_workaround"))] +#[cfg(any(not(feature = "__proc_macro_workaround"), target_arch = "wasm32"))] type JsValue = wasm_bindgen::JsValue; -#[cfg(feature = "__proc_macro_workaround")] +#[cfg(all(feature = "__proc_macro_workaround", not(target_arch = "wasm32")))] type JsValue = (); #[derive(Debug, Error, PartialEq)] From 1cec6768b2022bb00ff6ed46fdf9d92138e13b4e Mon Sep 17 00:00:00 2001 From: Kaede Hoshikawa Date: Sat, 10 Jun 2023 17:16:05 +0900 Subject: [PATCH 06/11] Fix feature flags. --- packages/stylist-core/src/error.rs | 12 ++++++++++-- packages/stylist-macros/Cargo.toml | 8 ++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/stylist-core/src/error.rs b/packages/stylist-core/src/error.rs index ac24f6a..35333a4 100644 --- a/packages/stylist-core/src/error.rs +++ b/packages/stylist-core/src/error.rs @@ -1,8 +1,16 @@ use thiserror::Error; -#[cfg(any(not(feature = "__proc_macro_workaround"), target_arch = "wasm32"))] +// Feature `__proc_macro_workaround` is enabled for the workspace as `stylist-macros` enables it. +// To mitigate this, we do not enable this feature on stylist-macros for wasm32 targets to make sure +// tests can run with default feature merging behaviour. +// +// For users outside of this workspace, __proc_macro_workaround will not be enabled +// when they use version = "2021" or resolver = "2" as procedural macros can have different feature +// flags. This should be OK for all downstream crates as stylist requires Rust 1.60 which supports +// both. +#[cfg(not(feature = "__proc_macro_workaround"))] type JsValue = wasm_bindgen::JsValue; -#[cfg(all(feature = "__proc_macro_workaround", not(target_arch = "wasm32")))] +#[cfg(feature = "__proc_macro_workaround")] type JsValue = (); #[derive(Debug, Error, PartialEq)] diff --git a/packages/stylist-macros/Cargo.toml b/packages/stylist-macros/Cargo.toml index ba58f52..259b96a 100644 --- a/packages/stylist-macros/Cargo.toml +++ b/packages/stylist-macros/Cargo.toml @@ -25,8 +25,6 @@ rust-version = "1.60" proc-macro = true [dependencies] -stylist-core = { path = "../stylist-core", version = "0.12", features = ["parser", "__proc_macro_workaround"] } - litrs = "0.4.0" proc-macro-error = "1.0.4" proc-macro2 = "1.0.47" @@ -36,5 +34,11 @@ syn = { version = "1.0.105", features = ["full", "extra-traits"] } itertools = "0.10.5" log = "0.4.17" +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +stylist-core = { path = "../stylist-core", version = "0.12", features = ["parser", "__proc_macro_workaround"] } + +[target.'cfg(target_arch = "wasm32")'.dependencies] +stylist-core = { path = "../stylist-core", version = "0.12", features = ["parser"] } + [dev-dependencies] env_logger = "0.10.0" From c0d6e32bbeac15b57a7ce4fc5a1485d0f375e713 Mon Sep 17 00:00:00 2001 From: Kaede Hoshikawa Date: Sat, 10 Jun 2023 17:18:14 +0900 Subject: [PATCH 07/11] Update documentation. --- packages/stylist-core/src/error.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/stylist-core/src/error.rs b/packages/stylist-core/src/error.rs index 35333a4..f357470 100644 --- a/packages/stylist-core/src/error.rs +++ b/packages/stylist-core/src/error.rs @@ -1,6 +1,7 @@ use thiserror::Error; // Feature `__proc_macro_workaround` is enabled for the workspace as `stylist-macros` enables it. +// This is the workspace feature merging behaviour even if resolver 2 is enabled. // To mitigate this, we do not enable this feature on stylist-macros for wasm32 targets to make sure // tests can run with default feature merging behaviour. // From 9cb7171025049ea54bcf0d295e1b6812071ff26e Mon Sep 17 00:00:00 2001 From: Kaede Hoshikawa Date: Sat, 10 Jun 2023 17:19:31 +0900 Subject: [PATCH 08/11] Update documentation. --- packages/stylist-core/src/error.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/stylist-core/src/error.rs b/packages/stylist-core/src/error.rs index f357470..ca9c214 100644 --- a/packages/stylist-core/src/error.rs +++ b/packages/stylist-core/src/error.rs @@ -1,5 +1,7 @@ use thiserror::Error; +// This is a mitigation to a compiler bug: https://github.com/rust-lang/rust/issues/111888 +// // Feature `__proc_macro_workaround` is enabled for the workspace as `stylist-macros` enables it. // This is the workspace feature merging behaviour even if resolver 2 is enabled. // To mitigate this, we do not enable this feature on stylist-macros for wasm32 targets to make sure From 380840ff45e2acf984a3f181db535679f4c33a07 Mon Sep 17 00:00:00 2001 From: Kaede Hoshikawa Date: Sat, 10 Jun 2023 17:24:28 +0900 Subject: [PATCH 09/11] Adjust documentation. --- packages/stylist-core/src/error.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/stylist-core/src/error.rs b/packages/stylist-core/src/error.rs index ca9c214..7f41409 100644 --- a/packages/stylist-core/src/error.rs +++ b/packages/stylist-core/src/error.rs @@ -4,8 +4,10 @@ use thiserror::Error; // // Feature `__proc_macro_workaround` is enabled for the workspace as `stylist-macros` enables it. // This is the workspace feature merging behaviour even if resolver 2 is enabled. -// To mitigate this, we do not enable this feature on stylist-macros for wasm32 targets to make sure -// tests can run with default feature merging behaviour. +// Enabling this feature for workspace will render tests not to compile. +// +// To mitigate this side effect, we do not enable this feature on stylist-macros for wasm32 targets +// to make sure tests can run with default feature merging behaviour. // // For users outside of this workspace, __proc_macro_workaround will not be enabled // when they use version = "2021" or resolver = "2" as procedural macros can have different feature From 452b41d7ab3331c40987d6aca3b30956b62e34c2 Mon Sep 17 00:00:00 2001 From: Kaede Hoshikawa Date: Sat, 10 Jun 2023 17:28:44 +0900 Subject: [PATCH 10/11] Adjust documentation. --- packages/stylist-core/src/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/stylist-core/src/error.rs b/packages/stylist-core/src/error.rs index 7f41409..47c2bb2 100644 --- a/packages/stylist-core/src/error.rs +++ b/packages/stylist-core/src/error.rs @@ -9,7 +9,7 @@ use thiserror::Error; // To mitigate this side effect, we do not enable this feature on stylist-macros for wasm32 targets // to make sure tests can run with default feature merging behaviour. // -// For users outside of this workspace, __proc_macro_workaround will not be enabled +// For crates outside of this workspace, `__proc_macro_workaround` will not be enabled // when they use version = "2021" or resolver = "2" as procedural macros can have different feature // flags. This should be OK for all downstream crates as stylist requires Rust 1.60 which supports // both. From 56c77eb6b5b29bcbeea346d73e48744cf972d7dc Mon Sep 17 00:00:00 2001 From: Kaede Hoshikawa Date: Sat, 10 Jun 2023 17:32:40 +0900 Subject: [PATCH 11/11] Adjust documentation. --- packages/stylist-core/src/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/stylist-core/src/error.rs b/packages/stylist-core/src/error.rs index 47c2bb2..dabb9d4 100644 --- a/packages/stylist-core/src/error.rs +++ b/packages/stylist-core/src/error.rs @@ -4,7 +4,7 @@ use thiserror::Error; // // Feature `__proc_macro_workaround` is enabled for the workspace as `stylist-macros` enables it. // This is the workspace feature merging behaviour even if resolver 2 is enabled. -// Enabling this feature for workspace will render tests not to compile. +// Enabling this feature for workspace will render browser tests uncompilable. // // To mitigate this side effect, we do not enable this feature on stylist-macros for wasm32 targets // to make sure tests can run with default feature merging behaviour.