Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit d5ebe5d

Browse files
committed
Add a release-checked profile with debug and overflow assertions
A failing debug assertion or overflow without correctly wrapping or saturating is a bug, but the `debug` profile that has these enabled does not run enough test cases to hit edge cases that may trigger these. Add a new `release-checked` profile that enables debug assertions and overflow checks. This seems to only extend per-function test time by a few seconds (or around a minute on longer extensive tests), so enable this as the default on CI. In order to ensure `no_panic` still gets checked, add a build-only step to CI.
1 parent 8940fbf commit d5ebe5d

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

.github/workflows/main.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ jobs:
238238
239239
LIBM_EXTENSIVE_TESTS="$CHANGED" cargo t \
240240
--features test-multiprecision,unstable \
241-
--release -- extensive
241+
--profile release-checked \
242+
-- extensive
242243
- name: Print test logs if available
243244
run: if [ -f "target/test-log.txt" ]; then cat target/test-log.txt; fi
244245
shell: bash

Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,10 @@ no-panic = "0.1.30"
6161
# This is needed for no-panic to correctly detect the lack of panics
6262
[profile.release]
6363
lto = "fat"
64+
65+
# Release mode with debug assertions
66+
[profile.release-checked]
67+
inherits = "release"
68+
debug-assertions = true
69+
lto = "fat"
70+
overflow-checks = true

build.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ fn main() {
1313
#[allow(unexpected_cfgs)]
1414
if !cfg!(feature = "checked") {
1515
let lvl = env::var("OPT_LEVEL").unwrap();
16-
if lvl != "0" {
16+
if lvl != "0" && !cfg!(debug_assertions) {
1717
println!("cargo:rustc-cfg=assert_no_panic");
18+
} else if env::var("ENSURE_NO_PANIC").is_ok() {
19+
// Give us a defensive way of ensureing that no-panic is checked when we
20+
// expect it to be.
21+
panic!("`assert_no_panic `was not enabled");
1822
}
1923
}
2024

ci/run.sh

+5-3
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ else
8181
$cmd --features unstable-intrinsics --benches
8282

8383
# Test the same in release mode, which also increases coverage.
84-
$cmd --release
85-
$cmd --release --features unstable-intrinsics
86-
$cmd --release --features unstable-intrinsics --benches
84+
$cmd --profile release-checked
85+
$cmd --profile release-checked --features unstable-intrinsics
86+
$cmd --profile release-checked --features unstable-intrinsics --benches
87+
88+
ENSURE_NO_PANIC=1 cargo build --target "$target" --release
8789
fi
8890

0 commit comments

Comments
 (0)