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

Mitigate linker error from Rust compiler #123

Merged
merged 11 commits into from
Jun 25, 2023
23 changes: 21 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# 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.

## 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
Expand All @@ -24,22 +30,26 @@
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`.

## v0.10.1

### Other Changes:

- Added an impl of `IntoPropValue<Classes>` 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.
Expand All @@ -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<StyleSource>` as a source for a stylesheet.
Expand All @@ -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.
Expand All @@ -82,16 +96,18 @@
## 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<str>`.
`stylist::ast::Sheet` and everything that implements `AsRef<str>`.
- 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`.
- Stylist now treats pseudo class selectors (e.g.:`:hover`) like emotion
and styled-components.

### Other Changes:

- Added a `GlobalStyle` struct to register global styles.
- Added a `<Global />` Component for global styling for yew applications.
- Supported `@supports` CSS at-rule.
Expand All @@ -107,6 +123,7 @@
## v0.7

### Breaking Changes:

- `Style::new()` now takes an `Into<Cow<'static, str>>` instead of
`Into<String>` and returns `stylist::Error` instead of `String` when
encountering an error.
Expand All @@ -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.
Expand All @@ -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`.
Expand Down
1 change: 1 addition & 0 deletions packages/stylist-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ wasm-bindgen-test = "0.3.33"

[features]
parser = ["dep:nom"]
__proc_macro_workaround = []
4 changes: 1 addition & 3 deletions packages/stylist-core/src/ast/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = &str> {
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
Expand Down
20 changes: 19 additions & 1 deletion packages/stylist-core/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
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.
// 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.
//
// 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.
#[cfg(not(feature = "__proc_macro_workaround"))]
type JsValue = wasm_bindgen::JsValue;
#[cfg(feature = "__proc_macro_workaround")]
type JsValue = ();

#[derive(Debug, Error, PartialEq)]
pub enum Error {
/// Failed to parse CSS.
Expand All @@ -16,7 +34,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?")]
Web(Option<wasm_bindgen::JsValue>),
Web(Option<JsValue>),

/// Failed to read styles from the StyleManager.
///
Expand Down
8 changes: 6 additions & 2 deletions packages/stylist-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ rust-version = "1.60"
proc-macro = true

[dependencies]
stylist-core = { path = "../stylist-core", version = "0.12", features = ["parser"] }

litrs = "0.4.0"
proc-macro-error = "1.0.4"
proc-macro2 = "1.0.47"
Expand All @@ -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"