Skip to content

Commit b1e7ea0

Browse files
committed
Rework the available Cargo profiles
Currently the default release profile enables LTO and single CGU builds, which is very slow to build. Most tests are better run with optimizations enabled since it allows testing a much larger number of inputs, so it is inconvenient that building can sometimes take significantly longer than the tests. Remedy this by doing the following: * Move the existing `release` profile to `release-opt`. * With the above, the default `release` profile is untouched (16 CGUs and thin local LTO). * `release-checked` inherits `release`, so no LTO or single CGU. This means that the simple `cargo test --release` becomes much faster for local development. We are able to enable the other profiles as needed in CI. Tests should ideally still be run with `--profile release-checked` to ensure there are no debug assetions or unexpected wrapping math hit. `no-panic` still needs a single CGU, so must be run with `--profile release-opt`. Since it is not possible to detect CGU or profilel configuration from within build scripts, the `ENSURE_NO_PANIC` environment variable must now always be set.
1 parent a2074e5 commit b1e7ea0

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

Cargo.toml

+8-6
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,20 @@ exclude = [
6161
[dev-dependencies]
6262
no-panic = "0.1.33"
6363

64-
[profile.release]
65-
# Options for no-panic to correctly detect the lack of panics
66-
codegen-units = 1
67-
lto = "fat"
64+
# The default release profile is unchanged.
6865

6966
# Release mode with debug assertions
7067
[profile.release-checked]
71-
codegen-units = 1
68+
inherits = "release"
7269
debug-assertions = true
70+
overflow-checks = true
71+
72+
# Release with maximum optimizations, which is very slow to build. This is also
73+
# what is needed to check `no-panic`.
74+
[profile.release-opt]
7375
inherits = "release"
76+
codegen-units = 1
7477
lto = "fat"
75-
overflow-checks = true
7678

7779
[profile.bench]
7880
# Required for iai-callgrind

build.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@ fn main() {
88
println!("cargo:rerun-if-changed=build.rs");
99
println!("cargo:rustc-check-cfg=cfg(assert_no_panic)");
1010

11-
let lvl = env::var("OPT_LEVEL").unwrap();
12-
if lvl != "0" && !cfg!(debug_assertions) {
11+
// If set, enable `no-panic`. Requires LTO (`release-opt` profile).
12+
if env::var("ENSURE_NO_PANIC").is_ok() {
1313
println!("cargo:rustc-cfg=assert_no_panic");
14-
} else if env::var("ENSURE_NO_PANIC").is_ok() {
15-
// Give us a defensive way of ensureing that no-panic is checked when we
16-
// expect it to be.
17-
panic!("`assert_no_panic `was not enabled");
1814
}
1915

2016
configure::emit_libm_config(&cfg);

ci/run.sh

+11-1
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,14 @@ $cmd "$profile" release-checked --features unstable-intrinsics
117117
$cmd "$profile" release-checked --features unstable-intrinsics --benches
118118

119119
# Ensure that the routines do not panic.
120-
ENSURE_NO_PANIC=1 cargo build -p libm --target "$target" --no-default-features --release
120+
#
121+
# `--tests` must be passed because no-panic is only enabled as a dev
122+
# dependency. The `release-opt` profile must be used to enable LTO and a
123+
# single CGU.
124+
ENSURE_NO_PANIC=1 cargo build \
125+
-p libm \
126+
--target "$target" \
127+
--no-default-features \
128+
--features unstable-float \
129+
--tests \
130+
--profile release-opt

0 commit comments

Comments
 (0)