Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build.rs: Migrate to CARGO_ENCODED_RUSTFLAGS #159

Merged
merged 1 commit into from
Sep 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions hermit-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,30 +98,29 @@ fn build_hermit(src_dir: &Path, target_dir_opt: Option<&Path>) {
}

let mut rustflags = vec!["-Zmutable-noalias=no".to_string()];
let outer_rustflags = env::var("CARGO_ENCODED_RUSTFLAGS").unwrap();

#[cfg(feature = "instrument")]
{
rustflags.push("-Zinstrument-mcount".to_string());
// Add outer `RUSTFLAGS` to command
if let Ok(var) = env::var("RUSTFLAGS") {
rustflags.push(var);
}
// Add outer rustflags to command
rustflags.push(outer_rustflags);
}

#[cfg(not(feature = "instrument"))]
{
// If the `instrument` feature feature is not enabled,
// filter it from outer `RUSTFLAGS` before adding them to the command.
if let Ok(var) = env::var("RUSTFLAGS") {
let flags = var
.split(',')
// filter it from outer rustflags before adding them to the command.
if !outer_rustflags.is_empty() {
let flags = outer_rustflags
.split('\x1f')
.filter(|&flag| !flag.contains("instrument-mcount"))
.map(String::from);
rustflags.extend(flags);
}
}

cmd.env("RUSTFLAGS", rustflags.join(" "));
cmd.env("CARGO_ENCODED_RUSTFLAGS", rustflags.join("\x1f"));

let status = cmd.status().expect("failed to start kernel build");
assert!(status.success());
Expand Down