Skip to content

Commit

Permalink
Account for optimization levels other than numbers
Browse files Browse the repository at this point in the history
The build script currently panics with `opt-level=z` or `opt-level=s`.
Account for this here.

This is the `compiler-builtins` version of [1].

Fixes: #742

[1]: rust-lang/libm#417
  • Loading branch information
tgross35 committed Jan 7, 2025
1 parent ad26150 commit 4e3cc6d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn configure_libm(target: &Target) {
}

println!("cargo:rustc-check-cfg=cfg(optimizations_enabled)");
if target.opt_level >= 2 {
if !matches!(target.opt_level.as_str(), "0" | "1") {
println!("cargo:rustc-cfg=optimizations_enabled");
}

Expand Down
4 changes: 2 additions & 2 deletions configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::env;
#[allow(dead_code)]
pub struct Target {
pub triple: String,
pub opt_level: u8,
pub opt_level: String,
pub cargo_features: Vec<String>,
pub os: String,
pub arch: String,
Expand All @@ -32,7 +32,7 @@ impl Target {
Self {
triple: env::var("TARGET").unwrap(),
os: env::var("CARGO_CFG_TARGET_OS").unwrap(),
opt_level: env::var("OPT_LEVEL").unwrap().parse().unwrap(),
opt_level: env::var("OPT_LEVEL").unwrap(),
cargo_features,
arch: env::var("CARGO_CFG_TARGET_ARCH").unwrap(),
vendor: env::var("CARGO_CFG_TARGET_VENDOR").unwrap(),
Expand Down

0 comments on commit 4e3cc6d

Please sign in to comment.