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.
This commit is contained in:
parent
4a98907b8a
commit
f0b932e723
3 changed files with 22 additions and 14 deletions
|
|
@ -61,19 +61,21 @@ exclude = [
|
|||
[dev-dependencies]
|
||||
no-panic = "0.1.33"
|
||||
|
||||
[profile.release]
|
||||
# Options for no-panic to correctly detect the lack of panics
|
||||
codegen-units = 1
|
||||
lto = "fat"
|
||||
# The default release profile is unchanged.
|
||||
|
||||
# Release mode with debug assertions
|
||||
[profile.release-checked]
|
||||
codegen-units = 1
|
||||
debug-assertions = true
|
||||
inherits = "release"
|
||||
lto = "fat"
|
||||
debug-assertions = true
|
||||
overflow-checks = true
|
||||
|
||||
# Release with maximum optimizations, which is very slow to build. This is also
|
||||
# what is needed to check `no-panic`.
|
||||
[profile.release-opt]
|
||||
inherits = "release"
|
||||
codegen-units = 1
|
||||
lto = "fat"
|
||||
|
||||
[profile.bench]
|
||||
# Required for iai-callgrind
|
||||
debug = true
|
||||
|
|
|
|||
|
|
@ -8,13 +8,9 @@ fn main() {
|
|||
println!("cargo:rerun-if-changed=build.rs");
|
||||
println!("cargo:rustc-check-cfg=cfg(assert_no_panic)");
|
||||
|
||||
let lvl = env::var("OPT_LEVEL").unwrap();
|
||||
if lvl != "0" && !cfg!(debug_assertions) {
|
||||
// If set, enable `no-panic`. Requires LTO (`release-opt` profile).
|
||||
if env::var("ENSURE_NO_PANIC").is_ok() {
|
||||
println!("cargo:rustc-cfg=assert_no_panic");
|
||||
} else if env::var("ENSURE_NO_PANIC").is_ok() {
|
||||
// Give us a defensive way of ensureing that no-panic is checked when we
|
||||
// expect it to be.
|
||||
panic!("`assert_no_panic `was not enabled");
|
||||
}
|
||||
|
||||
configure::emit_libm_config(&cfg);
|
||||
|
|
|
|||
|
|
@ -117,4 +117,14 @@ $cmd "$profile" release-checked --features unstable-intrinsics
|
|||
$cmd "$profile" release-checked --features unstable-intrinsics --benches
|
||||
|
||||
# Ensure that the routines do not panic.
|
||||
ENSURE_NO_PANIC=1 cargo build -p libm --target "$target" --no-default-features --release
|
||||
#
|
||||
# `--tests` must be passed because no-panic is only enabled as a dev
|
||||
# dependency. The `release-opt` profile must be used to enable LTO and a
|
||||
# single CGU.
|
||||
ENSURE_NO_PANIC=1 cargo build \
|
||||
-p libm \
|
||||
--target "$target" \
|
||||
--no-default-features \
|
||||
--features unstable-float \
|
||||
--tests \
|
||||
--profile release-opt
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue