Skip to content

Commit bb031eb

Browse files
authored
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
1 parent 85050f5 commit bb031eb

File tree

10 files changed

+34
-36
lines changed

10 files changed

+34
-36
lines changed

.cargo/config.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,3 @@ runner = 'wasmtime -W unknown-imports-trap=y'
66

77
[target.wasm32-unknown-unknown]
88
rustflags = ['--cfg', 'getrandom_backend="wasm_js"']
9-
10-
# This section needs to be last.
11-
# GitHub Actions modifies this section.
12-
[unstable]

.github/workflows/size-cmp.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@ jobs:
3232

3333
- name: Write Optimisation Flags
3434
run: |
35-
echo 'build-std = ["std", "panic_abort"]' >> .cargo/config.toml
36-
echo 'build-std-features = ["panic_immediate_abort"]' >> .cargo/config.toml
37-
echo '[build]' >> .cargo/config.toml
38-
echo 'rustflags = ["-Cpanic=abort"]' >> .cargo/config.toml
35+
if [ -x ci/write-min-size-flags.sh ] ; then
36+
ci/write-min-size-flags.sh
37+
else
38+
# this branch is a fallback used only for compatibility with earlier commits
39+
# in the repository and other branches and can be removed in the future.
40+
echo 'build-std = ["std", "panic_abort"]' >> .cargo/config.toml
41+
echo '[build]' >> .cargo/config.toml
42+
echo 'rustflags = ["-Cpanic=abort"]' >> .cargo/config.toml
43+
fi
3944
4045
- name: Setup toolchain
4146
uses: dtolnay/rust-toolchain@master

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ members = [
44
"tools/*",
55
"examples/*",
66
]
7+
exclude = ["examples/.cargo"]
78
default-members = [
89
"packages/*",
910
]

ci/write-min-size-flags.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env bash
2+
cat examples/.cargo/min-size-config.toml >> examples/.cargo/dummy-min-size-config.toml

examples/.cargo/config.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# this include is a bit of a hack: due to the unstable nature of the feature,
2+
# this file only gets included on nightly, hence it can specify "nightly only"
3+
# rustflags and options
4+
include = ["unstable.toml", "dummy-min-size-config.toml"]
5+
6+
[unstable]
7+
config-include = true
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This file is intentionally left empty.
2+
# It gets filled by `min-size-config.toml` in some cases by CI
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[unstable]
2+
build-std = ["core", "std", "panic_abort"]
3+
build-std-features = ["optimize_for_size"]
4+
5+
[target.'cfg(target_arch = "wasm32")']
6+
rustflags = ["-Zunstable-options", "-Cpanic=immediate-abort", "--cfg", "nightly_yew"]

examples/.cargo/unstable.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[target.wasm32-unknown-unknown]
2+
rustflags = ["--cfg", "nightly_yew"]

packages/yew/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![allow(clippy::needless_doctest_main)]
22
#![doc(html_logo_url = "https://yew.rs/img/logo.png")]
33
#![cfg_attr(documenting, feature(doc_cfg))]
4-
#![cfg_attr(documenting, feature(doc_auto_cfg))]
54
#![cfg_attr(nightly_yew, feature(fn_traits, unboxed_closures))]
65

76
//! # Yew Framework - API Documentation

tools/build-examples/src/main.rs

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn main() -> ExitCode {
3333
let path = entry.path();
3434

3535
// Skip if not a directory
36-
if !path.is_dir() {
36+
if should_skip_path(&path) {
3737
continue;
3838
}
3939

@@ -81,27 +81,19 @@ fn main() -> ExitCode {
8181
}
8282
}
8383

84+
fn should_skip_path(path: &Path) -> bool {
85+
!path.is_dir() || !path.join("Cargo.toml").exists()
86+
}
87+
8488
fn build_example(path: &Path, output_dir: &Path, example: &str) -> bool {
8589
let public_url_prefix = env::var("PUBLIC_URL_PREFIX").unwrap_or_default();
8690

8791
let dist_dir = output_dir.join(example);
8892

89-
let uses_rand = has_rand_dependency(path);
90-
91-
let rustflags = format!(
92-
"--cfg nightly_yew{}",
93-
if uses_rand {
94-
" --cfg getrandom_backend=\"wasm_js\""
95-
} else {
96-
""
97-
}
98-
);
99-
10093
// Run trunk build command
10194
let status = Command::new("trunk")
10295
.current_dir(path)
10396
.arg("build")
104-
.env("RUSTFLAGS", rustflags)
10597
.arg("--release")
10698
.arg("--dist")
10799
.arg(&dist_dir)
@@ -137,17 +129,3 @@ fn build_example(path: &Path, output_dir: &Path, example: &str) -> bool {
137129
_ => false,
138130
}
139131
}
140-
141-
// Function to check if the crate has a rand dependency
142-
fn has_rand_dependency(path: &Path) -> bool {
143-
let cargo_toml_path = path.join("Cargo.toml");
144-
145-
if !cargo_toml_path.exists() {
146-
return false;
147-
}
148-
149-
match fs::read_to_string(&cargo_toml_path) {
150-
Ok(content) => content.contains("rand = ") || content.contains("rand =\n"),
151-
Err(_) => false,
152-
}
153-
}

0 commit comments

Comments
 (0)