Skip to content

Commit a1a3157

Browse files
bors[bot]mkroening
andauthored
Merge #159
159: build.rs: Migrate to CARGO_ENCODED_RUSTFLAGS r=stlankes a=mkroening Fixes #158. Cargo introduced `CARGO_ENCODED_RUSTFLAGS` in rust-lang/cargo#9601 to make setting flags less error prone – it encodes arguments separated by `0x1f` (ASCII Unit Separator), instead of white spaces (old `RUSTFLAGS`). `CARGO_ENCODED_RUSTFLAGS` are preferred over the old `RUSTFLAGS` in cargo. For build scripts, cargo converts its `RUSTFLAGS` to `CARGO_ENCODED_RUSTFLAGS`. For unset `RUSTFLAGS` it is set to an empty string. Thus our build script would call cargo for building libhermit-rs with a set – but empty – `CARGO_ENCODED_RUSTFLAGS`, which takes precedence over our prepared `RUSTFLAGS`. Specifically this caused our `-Zmutable-noalias=no` flag to be ignored, causing the same network issue as #128 again. This PR adjusts our build script to make direct use of `CARGO_ENCODED_RUSTFLAGS`, the new and preferred way of handling flags in build scripts. This causes our flags to be correctly handled again. Co-authored-by: Martin Kröning <[email protected]>
2 parents fb1e44a + 5d332c9 commit a1a3157

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

hermit-sys/build.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,30 +98,29 @@ fn build_hermit(src_dir: &Path, target_dir_opt: Option<&Path>) {
9898
}
9999

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

102103
#[cfg(feature = "instrument")]
103104
{
104105
rustflags.push("-Zinstrument-mcount".to_string());
105-
// Add outer `RUSTFLAGS` to command
106-
if let Ok(var) = env::var("RUSTFLAGS") {
107-
rustflags.push(var);
108-
}
106+
// Add outer rustflags to command
107+
rustflags.push(outer_rustflags);
109108
}
110109

111110
#[cfg(not(feature = "instrument"))]
112111
{
113112
// If the `instrument` feature feature is not enabled,
114-
// filter it from outer `RUSTFLAGS` before adding them to the command.
115-
if let Ok(var) = env::var("RUSTFLAGS") {
116-
let flags = var
117-
.split(',')
113+
// filter it from outer rustflags before adding them to the command.
114+
if !outer_rustflags.is_empty() {
115+
let flags = outer_rustflags
116+
.split('\x1f')
118117
.filter(|&flag| !flag.contains("instrument-mcount"))
119118
.map(String::from);
120119
rustflags.extend(flags);
121120
}
122121
}
123122

124-
cmd.env("RUSTFLAGS", rustflags.join(" "));
123+
cmd.env("CARGO_ENCODED_RUSTFLAGS", rustflags.join("\x1f"));
125124

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

0 commit comments

Comments
 (0)