Skip to content

Commit

Permalink
Convert nightly from a feature flag to a compiler flag (#2827)
Browse files Browse the repository at this point in the history
* `nightly_yew` compiler flag instead of `nightly` feature

* update ci

* update ci: 2

* fmt & nightly_yew for examples

* update size-cmp too
  • Loading branch information
hamza1311 committed Aug 14, 2022
1 parent 9e602b9 commit a4e7091
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 17 deletions.
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' || '' }}
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
1 change: 1 addition & 0 deletions .github/workflows/size-cmp.yml
Expand Up @@ -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
Expand Down
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

0 comments on commit a4e7091

Please sign in to comment.