From a4e70914ac8468300588b48493df942a6e930f8a Mon Sep 17 00:00:00 2001 From: Muhammad Hamza Date: Mon, 15 Aug 2022 00:03:45 +0500 Subject: [PATCH] Convert nightly from a feature flag to a compiler flag (#2827) * `nightly_yew` compiler flag instead of `nightly` feature * update ci * update ci: 2 * fmt & nightly_yew for examples * update size-cmp too --- .github/workflows/main-checks.yml | 14 ++++++++++++-- .github/workflows/size-cmp.yml | 1 + ci/build-examples.sh | 3 ++- packages/yew-macro/Cargo.toml | 1 - packages/yew-macro/src/html_tree/html_element.rs | 4 ++-- packages/yew-macro/src/lib.rs | 2 +- packages/yew-macro/src/use_prepared_state.rs | 4 ++-- packages/yew/Cargo.toml | 1 - .../yew/src/functional/hooks/use_force_update.rs | 4 ++-- packages/yew/src/lib.rs | 5 +---- packages/yew/tests/use_prepared_state.rs | 2 +- 11 files changed, 24 insertions(+), 17 deletions(-) diff --git a/.github/workflows/main-checks.yml b/.github/workflows/main-checks.yml index 887cae5b063..02c339e4b0d 100644 --- a/.github/workflows/main-checks.yml +++ b/.github/workflows/main-checks.yml @@ -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' @@ -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' || '' }} 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 @@ -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 diff --git a/.github/workflows/size-cmp.yml b/.github/workflows/size-cmp.yml index df24fd60710..2d4053602d5 100644 --- a/.github/workflows/size-cmp.yml +++ b/.github/workflows/size-cmp.yml @@ -66,6 +66,7 @@ jobs: working-directory: current-pr/examples env: RUSTUP_TOOLCHAIN: nightly + RUSTFLAGS: --cfg nightly_yew - name: Collect size information run: python3 current-pr/ci/collect_sizes.py diff --git a/ci/build-examples.sh b/ci/build-examples.sh index 072d88ffeca..2bc3f56b184 100755 --- a/ci/build-examples.sh +++ b/ci/build-examples.sh @@ -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" diff --git a/packages/yew-macro/Cargo.toml b/packages/yew-macro/Cargo.toml index 875fb88cde6..51d3adccfe2 100644 --- a/packages/yew-macro/Cargo.toml +++ b/packages/yew-macro/Cargo.toml @@ -34,4 +34,3 @@ yew = { path = "../yew" } [features] lints = [] -nightly = [] diff --git a/packages/yew-macro/src/html_tree/html_element.rs b/packages/yew-macro/src/html_tree/html_element.rs index db4dfae77fb..d9a5059c678 100644 --- a/packages/yew-macro/src/html_tree/html_element.rs +++ b/packages/yew-macro/src/html_tree/html_element.rs @@ -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(); @@ -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 diff --git a/packages/yew-macro/src/lib.rs b/packages/yew-macro/src/lib.rs index 5822f0325ff..6cfbaf630b2 100644 --- a/packages/yew-macro/src/lib.rs +++ b/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 diff --git a/packages/yew-macro/src/use_prepared_state.rs b/packages/yew-macro/src/use_prepared_state.rs index a65dab70099..737c2368c19 100644 --- a/packages/yew-macro/src/use_prepared_state.rs +++ b/packages/yew-macro/src/use_prepared_state.rs @@ -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; @@ -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() } diff --git a/packages/yew/Cargo.toml b/packages/yew/Cargo.toml index 3aa8b30f068..5652a613b74 100644 --- a/packages/yew/Cargo.toml +++ b/packages/yew/Cargo.toml @@ -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] diff --git a/packages/yew/src/functional/hooks/use_force_update.rs b/packages/yew/src/functional/hooks/use_force_update.rs index 417273a015b..d3e1c485623 100644 --- a/packages/yew/src/functional/hooks/use_force_update.rs +++ b/packages/yew/src/functional/hooks/use_force_update.rs @@ -23,7 +23,7 @@ impl UseForceUpdateHandle { } } -#[cfg(feature = "nightly")] +#[cfg(nightly_yew)] mod feat_nightly { use super::*; @@ -112,7 +112,7 @@ pub fn use_force_update() -> impl Hook { UseRerenderHook } -#[cfg(all(test, feature = "nightly"))] +#[cfg(all(test, nightly_yew))] mod nightly_test { use yew::prelude::*; diff --git a/packages/yew/src/lib.rs b/packages/yew/src/lib.rs index d387edd950a..878eda98d7d 100644 --- a/packages/yew/src/lib.rs +++ b/packages/yew/src/lib.rs @@ -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 //! diff --git a/packages/yew/tests/use_prepared_state.rs b/packages/yew/tests/use_prepared_state.rs index d3cb4ea3856..8081c3014a4 100644 --- a/packages/yew/tests/use_prepared_state.rs +++ b/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;