Skip to content

Commit 204578e

Browse files
bors[bot]mkroening
andauthored
Merge #135
135: Disable `mutable-noalias` r=stlankes a=mkroening Fixes #128. What do you think? Co-authored-by: Martin Kröning <[email protected]>
2 parents 86af428 + af41820 commit 204578e

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

hermit-sys/build.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,33 @@ fn build_hermit(src_dir: &Path, target_dir_opt: Option<&Path>) {
8989
cmd.arg("vga");
9090
}
9191

92+
let mut rustflags = Vec::new();
93+
rustflags.push("-Zmutable-noalias=no".to_string());
94+
9295
#[cfg(feature = "instrument")]
9396
{
94-
cmd.env("RUSTFLAGS", "-Z instrument-mcount");
95-
// if instrument is not set, ensure that instrument is not in environment variables!
96-
cmd.env(
97-
"RUSTFLAGS",
98-
env::var("RUSTFLAGS")
99-
.unwrap_or_else(|_| "".into())
100-
.replace("-Z instrument-mcount", ""),
101-
);
97+
rustflags.push("-Zinstrument-mcount".to_string());
98+
// Add outer `RUSTFLAGS` to command
99+
if let Ok(var) = env::var("RUSTFLAGS") {
100+
rustflags.push(var);
101+
}
102102
}
103103

104+
#[cfg(not(feature = "instrument"))]
105+
{
106+
// If the `instrument` feature feature is not enabled,
107+
// filter it from outer `RUSTFLAGS` before adding them to the command.
108+
if let Ok(var) = env::var("RUSTFLAGS") {
109+
let flags = var
110+
.split(',')
111+
.filter(|&flag| !flag.contains("instrument-mcount"))
112+
.map(String::from);
113+
rustflags.extend(flags);
114+
}
115+
}
116+
117+
cmd.env("RUSTFLAGS", rustflags.join(","));
118+
104119
let output = cmd.output().expect("Unable to build kernel");
105120
let stdout = std::string::String::from_utf8(output.stdout);
106121
let stderr = std::string::String::from_utf8(output.stderr);

0 commit comments

Comments
 (0)