Skip to content

Commit fccd826

Browse files
committed
test-float-parse: Be more accurate about optimization warning
Currently we warn if `debug_assertions` is set, but this isn't always accurate because debug assertions can be on at higher optimization levels. Forward some information from the build script and print it to tell a better story, and update the warning to act on opt-level and profile rather than `debug_assertions`.
1 parent 0aec5ff commit fccd826

3 files changed

Lines changed: 25 additions & 4 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ strip = true
7777
debug = 0
7878
strip = true
7979

80-
# Bigint libraries are slow without optimization, speed up testing
80+
# Bigint libraries are slow without optimization, speed up testing. Note that this doesn't affect
81+
# its dependencies, it should still be run in release mode where possible.
8182
[profile.dev.package.test-float-parse]
8283
opt-level = 3
8384

@@ -92,4 +93,3 @@ codegen-units = 1
9293
# If you want to use a crate with local modifications, you can set a path or git dependency here.
9394
# For git dependencies, also add your source to ALLOWED_SOURCES in src/tools/tidy/src/extdeps.rs.
9495
#[patch.crates-io]
95-
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use std::env;
2+
3+
fn main() {
4+
// Forward the opt level so we can warn if the tests are going to be slow.
5+
let opt = env::var("OPT_LEVEL").expect("OPT_LEVEL unset");
6+
let profile = env::var("PROFILE").expect("PROFILE unset");
7+
println!("cargo::rustc-env=OPT_LEVEL={opt}");
8+
println!("cargo::rustc-env=PROFILE={profile}");
9+
}

src/tools/test-float-parse/src/main.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,24 @@ enum ArgMode {
3939
}
4040

4141
fn main() -> ExitCode {
42-
if cfg!(debug_assertions) {
42+
let opt = env!("OPT_LEVEL");
43+
let profile = env!("PROFILE");
44+
45+
println!("Crate config:");
46+
println!(" opt level: {opt}");
47+
println!(" profile: {profile}");
48+
println!(" debug assertions: {}", cfg!(debug_assertions));
49+
50+
if !matches!(opt, "2" | "3") || profile != "release" {
51+
// Warn for `profile != release` because optimizations being on for this crate (always,
52+
// via the workspace Cargo.toml) may not mean they are on for dependencies.
4353
println!(
44-
"WARNING: running in debug mode. Release mode is recommended to reduce test duration."
54+
"WARNING: test-float-parse may be running unoptimized or with unoptimized \
55+
dependencies. Release mode is recommended to reduce test duration."
4556
);
4657
std::thread::sleep(Duration::from_secs(2));
4758
}
59+
println!("Running with debug assertions={}", cfg!(debug_assertions));
4860

4961
let args: Vec<_> = std::env::args().skip(1).collect();
5062
if args.iter().any(|arg| arg == "--help" || arg == "-h") {

0 commit comments

Comments
 (0)