Maintain some nightly features and CI (#3934)

* remove `doc_auto_cfg`

removed in favor of `doc_cfg` which is already present

* fix optimization flags

the fix targets the change to panic_abort in rust-lang/rust#146974
Incidentally, this led me to realize that some RUSTFLAGS were being
ignored, due to the exclusivity of env variables vs config options (see ref).
With this change, all config options are read from toml files instead of
env variables.

reference: https://doc.rust-lang.org/cargo/reference/config.html#buildrustflags

use old optimization flags for master branch before this change

* skip example paths that don't contain a Cargo.toml
This commit is contained in:
WorldSEnder 2025-10-22 13:08:44 +02:00 committed by GitHub
parent 85050f50fb
commit bb031eb68f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 34 additions and 36 deletions

View File

@ -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]

View File

@ -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

View File

@ -4,6 +4,7 @@ members = [
"tools/*",
"examples/*",
]
exclude = ["examples/.cargo"]
default-members = [
"packages/*",
]

2
ci/write-min-size-flags.sh Executable file
View File

@ -0,0 +1,2 @@
#!/usr/bin/env bash
cat examples/.cargo/min-size-config.toml >> examples/.cargo/dummy-min-size-config.toml

View File

@ -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

View File

@ -0,0 +1,2 @@
# This file is intentionally left empty.
# It gets filled by `min-size-config.toml` in some cases by CI

View File

@ -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"]

View File

@ -0,0 +1,2 @@
[target.wasm32-unknown-unknown]
rustflags = ["--cfg", "nightly_yew"]

View File

@ -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

View File

@ -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,
}
}