-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
45 lines (39 loc) · 1.67 KB
/
Copy pathbuild.rs
File metadata and controls
45 lines (39 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//! mod-alloc build script.
//!
//! Approved exception per `.dev/DIRECTIVES.md` section 2.1. The
//! crate does not generally use `build.rs`. This script exists
//! solely to detect whether the user's toolchain has frame
//! pointers enabled when the `backtraces` feature is on, and to
//! emit a `cargo:warning=` directive if not.
//!
//! Frame pointers are a prerequisite for the inline FP walker
//! shipped in `v0.9.1`. Without them the walker returns empty or
//! shallow traces on release builds; a build-time hint saves
//! users from debugging that downstream.
//!
//! This script never fails the build. The walker degrades
//! gracefully at runtime if FP support is absent.
use std::env;
fn main() {
println!("cargo:rerun-if-env-changed=RUSTFLAGS");
println!("cargo:rerun-if-env-changed=CARGO_ENCODED_RUSTFLAGS");
let backtraces_on = env::var_os("CARGO_FEATURE_BACKTRACES").is_some();
if !backtraces_on {
return;
}
let rustflags = env::var("CARGO_ENCODED_RUSTFLAGS")
.or_else(|_| env::var("RUSTFLAGS"))
.unwrap_or_default();
let has_fp = rustflags.contains("force-frame-pointers=yes")
|| rustflags.contains("force-frame-pointers=y")
|| rustflags.contains("force-frame-pointers=on");
if !has_fp {
println!(
"cargo:warning=mod-alloc: the `backtraces` feature is enabled but \
RUSTFLAGS does not include `-C force-frame-pointers=yes`. The inline \
FP walker requires frame pointers; without them traces will be empty \
or shallow on release builds. Add to .cargo/config.toml: [build] \
rustflags = [\"-C\", \"force-frame-pointers=yes\"]"
);
}
}