Skip to content

Commit 4bc7522

Browse files
committed
Auto merge of #1093 - mcgoo:rustlib_path_windows, r=Diggsey
Add the rust lib dir (containing std-<hash>.dll) to the path on windows I'm not sure if this is the right thing or not, but this fixes some of rust-lang/cargo#3394. My apologies if it undoes earlier path related fixes. The dylib tests in the cargo testsuite work. `cargo test` of a dylib crate works. It does nothing for the `cargo install` case. It adds sysroot/bin to the path on Windows which fixes finding libstd. A side effect of this is that rustc.exe is directly in the path although it is after CARGO_HOME/bin so the shim should be found first. The behavior of prepend_path in case of a corrupt path is changed - it used to clobber the existing path with the new path, and now it will leave leave the existing path unchanged. It leaves LD_LIBRARY_PATH set on Windows also as I believe it is used by MinGW.
2 parents 156678f + 0555dbe commit 4bc7522

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
@@ -407,15 +407,22 @@ impl<'a> Toolchain<'a> {
407407
mod sysenv {
408408
pub const LOADER_PATH: &'static str = "DYLD_LIBRARY_PATH";
409409
}
410-
env_var::prepend_path(sysenv::LOADER_PATH, &new_path, cmd);
410+
env_var::prepend_path(sysenv::LOADER_PATH, vec![new_path.clone()], cmd);
411411

412412
// Prepend CARGO_HOME/bin to the PATH variable so that we're sure to run
413413
// cargo/rustc via the proxy bins. There is no fallback case for if the
414414
// proxy bins don't exist. We'll just be running whatever happens to
415415
// be on the PATH.
416+
let mut path_entries = vec![];
416417
if let Ok(cargo_home) = utils::cargo_home() {
417-
env_var::prepend_path("PATH", &cargo_home.join("bin"), cmd);
418+
path_entries.push(cargo_home.join("bin").to_path_buf());
418419
}
420+
421+
if cfg!(target_os = "windows") {
422+
path_entries.push(self.path.join("bin"));
423+
}
424+
425+
env_var::prepend_path("PATH", path_entries, cmd);
419426
}
420427

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

0 commit comments

Comments
 (0)