Skip to content

Commit

Permalink
Auto merge of #1093 - mcgoo:rustlib_path_windows, r=Diggsey
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed May 17, 2017
2 parents 156678f + 0555dbe commit 4bc7522
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
17 changes: 10 additions & 7 deletions src/rustup/env_var.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::ffi::OsString;
use std::env;
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use std::process::Command;

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

pub fn prepend_path(name: &str, value: &Path, cmd: &mut Command) {
pub fn prepend_path(name: &str, value: Vec<PathBuf>, cmd: &mut Command) {
let old_value = env::var_os(name);
let mut parts = vec![value.to_owned()];
let mut parts: Vec<PathBuf>;
if let Some(ref v) = old_value {
parts.extend(env::split_paths(v));
parts = value;
parts.extend(env::split_paths(v).collect::<Vec<_>>());
} else {
parts = value;
}
let new_value = env::join_paths(parts).unwrap_or_else(|_| OsString::from(value));

cmd.env(name, new_value);
if let Ok(new_value) = env::join_paths(parts) {
cmd.env(name, new_value);
}
}

pub fn inc(name: &str, cmd: &mut Command) {
Expand Down
11 changes: 9 additions & 2 deletions src/rustup/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,15 +407,22 @@ impl<'a> Toolchain<'a> {
mod sysenv {
pub const LOADER_PATH: &'static str = "DYLD_LIBRARY_PATH";
}
env_var::prepend_path(sysenv::LOADER_PATH, &new_path, cmd);
env_var::prepend_path(sysenv::LOADER_PATH, vec![new_path.clone()], cmd);

// Prepend CARGO_HOME/bin to the PATH variable so that we're sure to run
// cargo/rustc via the proxy bins. There is no fallback case for if the
// proxy bins don't exist. We'll just be running whatever happens to
// be on the PATH.
let mut path_entries = vec![];
if let Ok(cargo_home) = utils::cargo_home() {
env_var::prepend_path("PATH", &cargo_home.join("bin"), cmd);
path_entries.push(cargo_home.join("bin").to_path_buf());
}

if cfg!(target_os = "windows") {
path_entries.push(self.path.join("bin"));
}

env_var::prepend_path("PATH", path_entries, cmd);
}

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

0 comments on commit 4bc7522

Please sign in to comment.