Skip to content

Commit 0555dbe

Browse files
committed
Add the rust lib dir (containing std-<hash>.dll) to the path on windows
Adds sysroot/bin to the path on Windows which fixes finding libstd in dynamic builds. This fixes a load of dylib tests in the cargo testsuite on Windows. This will result in rustc.exe being directly in the path although it is after CARGO_HOME/bin so the shim should be found first.
1 parent 7b3e8fb commit 0555dbe

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/rustup/env_var.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use std::ffi::OsString;
21
use std::env;
3-
use std::path::{Path, PathBuf};
2+
use std::path::PathBuf;
43
use std::process::Command;
54

65
pub const RUST_RECURSION_COUNT_MAX: u32 = 5;
@@ -20,15 +19,19 @@ pub fn append_path(name: &str, value: Vec<PathBuf>, cmd: &mut Command) {
2019
}
2120
}
2221

23-
pub fn prepend_path(name: &str, value: &Path, cmd: &mut Command) {
22+
pub fn prepend_path(name: &str, value: Vec<PathBuf>, cmd: &mut Command) {
2423
let old_value = env::var_os(name);
25-
let mut parts = vec![value.to_owned()];
24+
let mut parts: Vec<PathBuf>;
2625
if let Some(ref v) = old_value {
27-
parts.extend(env::split_paths(v));
26+
parts = value;
27+
parts.extend(env::split_paths(v).collect::<Vec<_>>());
28+
} else {
29+
parts = value;
2830
}
29-
let new_value = env::join_paths(parts).unwrap_or_else(|_| OsString::from(value));
3031

31-
cmd.env(name, new_value);
32+
if let Ok(new_value) = env::join_paths(parts) {
33+
cmd.env(name, new_value);
34+
}
3235
}
3336

3437
pub fn inc(name: &str, cmd: &mut Command) {

src/rustup/toolchain.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,15 +397,22 @@ impl<'a> Toolchain<'a> {
397397
mod sysenv {
398398
pub const LOADER_PATH: &'static str = "DYLD_LIBRARY_PATH";
399399
}
400-
env_var::prepend_path(sysenv::LOADER_PATH, &new_path, cmd);
400+
env_var::prepend_path(sysenv::LOADER_PATH, vec![new_path.clone()], cmd);
401401

402402
// Prepend CARGO_HOME/bin to the PATH variable so that we're sure to run
403403
// cargo/rustc via the proxy bins. There is no fallback case for if the
404404
// proxy bins don't exist. We'll just be running whatever happens to
405405
// be on the PATH.
406+
let mut path_entries = vec![];
406407
if let Ok(cargo_home) = utils::cargo_home() {
407-
env_var::prepend_path("PATH", &cargo_home.join("bin"), cmd);
408+
path_entries.push(cargo_home.join("bin").to_path_buf());
408409
}
410+
411+
if cfg!(target_os = "windows") {
412+
path_entries.push(self.path.join("bin"));
413+
}
414+
415+
env_var::prepend_path("PATH", path_entries, cmd);
409416
}
410417

411418
pub fn doc_path(&self, relative: &str) -> Result<PathBuf> {

0 commit comments

Comments
 (0)