diff --git a/.cargo/config.toml b/.cargo/config.toml index 3d13ac886..00a77d805 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -6,7 +6,3 @@ runner = 'wasmtime -W unknown-imports-trap=y' [target.wasm32-unknown-unknown] rustflags = ['--cfg', 'getrandom_backend="wasm_js"'] - -# This section needs to be last. -# GitHub Actions modifies this section. -[unstable] diff --git a/.github/workflows/size-cmp.yml b/.github/workflows/size-cmp.yml index 4cfdd9b50..1f9cc10fa 100644 --- a/.github/workflows/size-cmp.yml +++ b/.github/workflows/size-cmp.yml @@ -32,10 +32,15 @@ jobs: - name: Write Optimisation Flags run: | - echo 'build-std = ["std", "panic_abort"]' >> .cargo/config.toml - echo 'build-std-features = ["panic_immediate_abort"]' >> .cargo/config.toml - echo '[build]' >> .cargo/config.toml - echo 'rustflags = ["-Cpanic=abort"]' >> .cargo/config.toml + if [ -x ci/write-min-size-flags.sh ] ; then + ci/write-min-size-flags.sh + else + # this branch is a fallback used only for compatibility with earlier commits + # in the repository and other branches and can be removed in the future. + echo 'build-std = ["std", "panic_abort"]' >> .cargo/config.toml + echo '[build]' >> .cargo/config.toml + echo 'rustflags = ["-Cpanic=abort"]' >> .cargo/config.toml + fi - name: Setup toolchain uses: dtolnay/rust-toolchain@master diff --git a/Cargo.toml b/Cargo.toml index 28d75d73b..78f436f7f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ members = [ "tools/*", "examples/*", ] +exclude = ["examples/.cargo"] default-members = [ "packages/*", ] diff --git a/ci/write-min-size-flags.sh b/ci/write-min-size-flags.sh new file mode 100755 index 000000000..30dde0dd6 --- /dev/null +++ b/ci/write-min-size-flags.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +cat examples/.cargo/min-size-config.toml >> examples/.cargo/dummy-min-size-config.toml diff --git a/examples/.cargo/config.toml b/examples/.cargo/config.toml new file mode 100644 index 000000000..6e5172afd --- /dev/null +++ b/examples/.cargo/config.toml @@ -0,0 +1,7 @@ +# this include is a bit of a hack: due to the unstable nature of the feature, +# this file only gets included on nightly, hence it can specify "nightly only" +# rustflags and options +include = ["unstable.toml", "dummy-min-size-config.toml"] + +[unstable] +config-include = true diff --git a/examples/.cargo/dummy-min-size-config.toml b/examples/.cargo/dummy-min-size-config.toml new file mode 100644 index 000000000..e04e63ef8 --- /dev/null +++ b/examples/.cargo/dummy-min-size-config.toml @@ -0,0 +1,2 @@ +# This file is intentionally left empty. +# It gets filled by `min-size-config.toml` in some cases by CI diff --git a/examples/.cargo/min-size-config.toml b/examples/.cargo/min-size-config.toml new file mode 100644 index 000000000..aefd82e64 --- /dev/null +++ b/examples/.cargo/min-size-config.toml @@ -0,0 +1,6 @@ +[unstable] +build-std = ["core", "std", "panic_abort"] +build-std-features = ["optimize_for_size"] + +[target.'cfg(target_arch = "wasm32")'] +rustflags = ["-Zunstable-options", "-Cpanic=immediate-abort", "--cfg", "nightly_yew"] diff --git a/examples/.cargo/unstable.toml b/examples/.cargo/unstable.toml new file mode 100644 index 000000000..4a9f16521 --- /dev/null +++ b/examples/.cargo/unstable.toml @@ -0,0 +1,2 @@ +[target.wasm32-unknown-unknown] +rustflags = ["--cfg", "nightly_yew"] diff --git a/packages/yew/src/lib.rs b/packages/yew/src/lib.rs index e53544b0a..e6aff0a95 100644 --- a/packages/yew/src/lib.rs +++ b/packages/yew/src/lib.rs @@ -1,7 +1,6 @@ #![allow(clippy::needless_doctest_main)] #![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(nightly_yew, feature(fn_traits, unboxed_closures))] //! # Yew Framework - API Documentation diff --git a/tools/build-examples/src/main.rs b/tools/build-examples/src/main.rs index e25817c29..02dbe231b 100644 --- a/tools/build-examples/src/main.rs +++ b/tools/build-examples/src/main.rs @@ -33,7 +33,7 @@ fn main() -> ExitCode { let path = entry.path(); // Skip if not a directory - if !path.is_dir() { + if should_skip_path(&path) { continue; } @@ -81,27 +81,19 @@ fn main() -> ExitCode { } } +fn should_skip_path(path: &Path) -> bool { + !path.is_dir() || !path.join("Cargo.toml").exists() +} + fn build_example(path: &Path, output_dir: &Path, example: &str) -> bool { let public_url_prefix = env::var("PUBLIC_URL_PREFIX").unwrap_or_default(); let dist_dir = output_dir.join(example); - let uses_rand = has_rand_dependency(path); - - let rustflags = format!( - "--cfg nightly_yew{}", - if uses_rand { - " --cfg getrandom_backend=\"wasm_js\"" - } else { - "" - } - ); - // Run trunk build command let status = Command::new("trunk") .current_dir(path) .arg("build") - .env("RUSTFLAGS", rustflags) .arg("--release") .arg("--dist") .arg(&dist_dir) @@ -137,17 +129,3 @@ fn build_example(path: &Path, output_dir: &Path, example: &str) -> bool { _ => false, } } - -// Function to check if the crate has a rand dependency -fn has_rand_dependency(path: &Path) -> bool { - let cargo_toml_path = path.join("Cargo.toml"); - - if !cargo_toml_path.exists() { - return false; - } - - match fs::read_to_string(&cargo_toml_path) { - Ok(content) => content.contains("rand = ") || content.contains("rand =\n"), - Err(_) => false, - } -}