Skip to content

Commit 22519d3

Browse files
committed
Do not overwrite the value of RUSTC_ADDITIONAL_SYSROOT_PATHS
1 parent 814b8e6 commit 22519d3

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/bootstrap/src/core/build_steps/check.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,10 @@ impl RmetaSysroot {
191191
/// Configure the given cargo invocation so that the compiled crate will be able to use
192192
/// rustc .rmeta artifacts that were previously generated.
193193
fn configure_cargo(&self, cargo: &mut Cargo) {
194-
cargo.env(
194+
cargo.append_to_env(
195195
"RUSTC_ADDITIONAL_SYSROOT_PATHS",
196196
format!("{},{}", self.host_dir.display(), self.target_dir.display()),
197+
",",
197198
);
198199
}
199200
}

src/bootstrap/src/core/builder/cargo.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,32 @@ impl Cargo {
186186
self
187187
}
188188

189+
/// Append a value to an env var of the cargo command instance.
190+
/// If the variable was unset previously, this is equivalent to [`Cargo::env`].
191+
/// If the variable was already set, this will append `delimiter` and then `value` to it.
192+
///
193+
/// Note that this only considers the existence of the env. var. configured on this `Cargo`
194+
/// instance. It does not look at the environment of this process.
195+
pub fn append_to_env(
196+
&mut self,
197+
key: impl AsRef<OsStr>,
198+
value: impl AsRef<OsStr>,
199+
delimiter: impl AsRef<OsStr>,
200+
) -> &mut Cargo {
201+
assert_ne!(key.as_ref(), "RUSTFLAGS");
202+
assert_ne!(key.as_ref(), "RUSTDOCFLAGS");
203+
204+
let key = key.as_ref();
205+
if let Some((_, Some(previous_value))) = self.command.get_envs().find(|(k, _)| *k == key) {
206+
let mut combined: OsString = previous_value.to_os_string();
207+
combined.push(delimiter.as_ref());
208+
combined.push(value.as_ref());
209+
self.env(key, combined)
210+
} else {
211+
self.env(key, value)
212+
}
213+
}
214+
189215
pub fn add_rustc_lib_path(&mut self, builder: &Builder<'_>) {
190216
builder.add_rustc_lib_path(self.compiler, &mut self.command);
191217
}

0 commit comments

Comments
 (0)