Skip to content

Commit

Permalink
bootstrap: Fix LLVM bin path setup for Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwoerister committed May 4, 2018
1 parent 6a71143 commit d0253ad
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
11 changes: 0 additions & 11 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1030,17 +1030,6 @@ impl Step for Compiletest {
if let Some(ar) = builder.ar(target) {
cmd.arg("--ar").arg(ar);
}

// Add the llvm/bin directory to PATH since it contains lots of
// useful, platform-independent tools
let llvm_bin_path = llvm_config.parent()
.expect("Expected llvm-config to be contained in directory");
assert!(llvm_bin_path.is_dir());
let old_path = env::var_os("PATH").unwrap_or_default();
let new_path = env::join_paths(iter::once(llvm_bin_path.to_path_buf())
.chain(env::split_paths(&old_path)))
.expect("");
cmd.env("PATH", new_path);
}
}
if mode == "run-make" && !builder.config.llvm_enabled {
Expand Down
42 changes: 39 additions & 3 deletions src/bootstrap/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use std::fs;
use std::env;
use std::iter;
use std::path::PathBuf;
use std::process::{Command, exit};

Expand Down Expand Up @@ -593,7 +594,7 @@ impl<'a> Builder<'a> {
/// right location to run `compiler`.
fn prepare_tool_cmd(&self, compiler: Compiler, cmd: &mut Command) {
let host = &compiler.host;
let mut paths: Vec<PathBuf> = vec![
let mut lib_paths: Vec<PathBuf> = vec![
PathBuf::from(&self.sysroot_libdir(compiler, compiler.host)),
self.cargo_out(compiler, Mode::Tool, *host).join("deps"),
];
Expand All @@ -610,11 +611,46 @@ impl<'a> Builder<'a> {
}
for path in env::split_paths(v) {
if !curpaths.contains(&path) {
paths.push(path);
lib_paths.push(path);
}
}
}
}
add_lib_path(paths, cmd);

// Add the llvm/bin directory to PATH since it contains lots of
// useful, platform-independent tools
if let Some(llvm_bin_path) = self.llvm_bin_path() {
if host.contains("windows") {
// On Windows, PATH and the dynamic library path are the same,
// so we just add the LLVM bin path to lib_path
lib_paths.push(llvm_bin_path);
} else {
let old_path = env::var_os("PATH").unwrap_or_default();
let new_path = env::join_paths(iter::once(llvm_bin_path)
.chain(env::split_paths(&old_path)))
.expect("Could not add LLVM bin path to PATH");
cmd.env("PATH", new_path);
}
}

add_lib_path(lib_paths, cmd);
}

fn llvm_bin_path(&self) -> Option<PathBuf> {
if self.config.llvm_enabled && !self.config.dry_run {
let llvm_config = self.ensure(native::Llvm {
target: self.config.build,
emscripten: false,
});

// Add the llvm/bin directory to PATH since it contains lots of
// useful, platform-independent tools
let llvm_bin_path = llvm_config.parent()
.expect("Expected llvm-config to be contained in directory");
assert!(llvm_bin_path.is_dir());
Some(llvm_bin_path.to_path_buf())
} else {
None
}
}
}

0 comments on commit d0253ad

Please sign in to comment.