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

Convert nightly from a feature flag to a compiler flag #2827

Merged
merged 6 commits into from Aug 14, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions .github/workflows/main-checks.yml
Expand Up @@ -35,7 +35,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets --features "csr,ssr,hydration,tokio" --profile ${{ matrix.profile }} -- -D warnings
args: --all-targets --all-features --profile ${{ matrix.profile }} -- -D warnings

- name: Lint feature soundness
if: matrix.profile == 'dev'
Expand Down Expand Up @@ -181,15 +181,23 @@ jobs:

- name: Run native tests
uses: actions-rs/cargo@v1
env:
# workaround for lack of ternary operator
# see https://github.com/orgs/community/discussions/25725
RUSTFLAGS: ${{ matrix.toolchain == 'nightly && '--cfg nightly_yew' || '' }}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
RUSTFLAGS: ${{ matrix.toolchain == 'nightly && '--cfg nightly_yew' || '' }}
RUSTFLAGS: ${{ matrix.toolchain == 'nightly' && '--cfg nightly_yew' || '' }}

Oops, didn't find this during the review.

with:
command: test
args: --all-targets --workspace --exclude yew

- name: Run native tests for yew
uses: actions-rs/cargo@v1
env:
# workaround for lack of ternary operator
# see https://github.com/orgs/community/discussions/25725
RUSTFLAGS: ${{ matrix.toolchain == 'nightly && '--cfg nightly_yew' || '' }}
with:
command: test
args: -p yew --features "csr,ssr,hydration,tokio"
args: -p yew --all-features

test-lints:
name: Test lints on nightly
Expand All @@ -207,6 +215,8 @@ jobs:

- name: Run tests
uses: actions-rs/cargo@v1
env:
RUSTFLAGS: --cfg nightly_yew
with:
command: test
args: -p yew-macro test_html_lints --features lints
3 changes: 2 additions & 1 deletion ci/build-examples.sh
Expand Up @@ -24,12 +24,13 @@ for path in examples/*; do
# shellcheck disable=SC2164
cd "$path"
dist_dir="$output/$example"
export RUSTFLAGS="--cfg nightly_yew"
if [[ "$example" == "boids" || "$example" == "password_strength" ]]; then
# works around issue rust-lang/rust#96486
# where the compiler forgets to link some symbols connected to const_eval
# only an issue on nightly and with build-std enabled which we do for code size
# this deoptimizes only the examples that otherwise fail to build
export RUSTFLAGS="-Zshare-generics=n -Clto=thin"
export RUSTFLAGS="-Zshare-generics=n -Clto=thin $RUSTFLAGS"
fi

trunk build --release --dist "$dist_dir" --public-url "$PUBLIC_URL_PREFIX$example"
Expand Down
1 change: 0 additions & 1 deletion packages/yew-macro/Cargo.toml
Expand Up @@ -34,4 +34,3 @@ yew = { path = "../yew" }

[features]
lints = []
nightly = []
4 changes: 2 additions & 2 deletions packages/yew-macro/src/html_tree/html_element.rs
Expand Up @@ -360,7 +360,7 @@ impl ToTokens for HtmlElement {
}}
});

#[cfg(feature = "nightly")]
#[cfg(nightly_yew)]
let invalid_void_tag_msg_start = {
let span = vtag.span().unwrap();
let source_file = span.source_file().path();
Expand All @@ -369,7 +369,7 @@ impl ToTokens for HtmlElement {
format!("[{}:{}:{}] ", source_file, start.line, start.column)
};

#[cfg(not(feature = "nightly"))]
#[cfg(not(nightly_yew))]
let invalid_void_tag_msg_start = "";

// this way we get a nice error message (with the correct span) when the expression
Expand Down
2 changes: 1 addition & 1 deletion packages/yew-macro/src/lib.rs
@@ -1,4 +1,4 @@
#![cfg_attr(feature = "nightly", feature(proc_macro_span))]
#![cfg_attr(nightly_yew, feature(proc_macro_span))]

//! This crate provides Yew's procedural macro `html!` which allows using JSX-like syntax
//! for generating html and the `Properties` derive macro for deriving the `Properties` trait
Expand Down
4 changes: 2 additions & 2 deletions packages/yew-macro/src/use_prepared_state.rs
Expand Up @@ -59,7 +59,7 @@ impl Parse for PreparedState {

impl PreparedState {
// Async closure is not stable, so we rewrite it to closure + async block
#[cfg(not(feature = "nightly"))]
#[cfg(not(nightly_yew))]
pub fn rewrite_to_closure_with_async_block(&self) -> ExprClosure {
use proc_macro2::Span;
use syn::parse_quote;
Expand Down Expand Up @@ -95,7 +95,7 @@ impl PreparedState {
closure
}

#[cfg(feature = "nightly")]
#[cfg(nightly_yew)]
pub fn rewrite_to_closure_with_async_block(&self) -> ExprClosure {
self.closure.clone()
}
Expand Down
1 change: 0 additions & 1 deletion packages/yew/Cargo.toml
Expand Up @@ -99,7 +99,6 @@ tokio = ["tokio/rt", "tokio/time", "dep:num_cpus", "dep:tokio-util"]
ssr = ["dep:html-escape", "dep:base64ct", "dep:bincode"]
csr = []
hydration = ["csr", "dep:bincode"]
nightly = ["yew-macro/nightly"]
default = []

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions packages/yew/src/functional/hooks/use_force_update.rs
Expand Up @@ -23,7 +23,7 @@ impl UseForceUpdateHandle {
}
}

#[cfg(feature = "nightly")]
#[cfg(nightly_yew)]
mod feat_nightly {
use super::*;

Expand Down Expand Up @@ -112,7 +112,7 @@ pub fn use_force_update() -> impl Hook<Output = UseForceUpdateHandle> {
UseRerenderHook
}

#[cfg(all(test, feature = "nightly"))]
#[cfg(all(test, nightly_yew))]
mod nightly_test {
use yew::prelude::*;

Expand Down
5 changes: 1 addition & 4 deletions packages/yew/src/lib.rs
Expand Up @@ -2,10 +2,7 @@
#![doc(html_logo_url = "https://yew.rs/img/logo.png")]
#![cfg_attr(documenting, feature(doc_cfg))]
#![cfg_attr(documenting, feature(doc_auto_cfg))]
#![cfg_attr(
feature = "nightly",
feature(fn_traits, async_closure, unboxed_closures)
)]
#![cfg_attr(nightly_yew, feature(fn_traits, async_closure, unboxed_closures))]

//! # Yew Framework - API Documentation
//!
Expand Down
2 changes: 1 addition & 1 deletion packages/yew/tests/use_prepared_state.rs
@@ -1,6 +1,6 @@
#![cfg(target_arch = "wasm32")]
#![cfg(feature = "hydration")]
#![cfg_attr(feature = "nightly", feature(async_closure))]
#![cfg_attr(nightly_yew, feature(async_closure))]

use std::time::Duration;

Expand Down