Skip to content

Commit d0253ad

Browse files
bootstrap: Fix LLVM bin path setup for Windows.
1 parent 6a71143 commit d0253ad

File tree

2 files changed

+39
-14
lines changed

2 files changed

+39
-14
lines changed

src/bootstrap/test.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,17 +1030,6 @@ impl Step for Compiletest {
10301030
if let Some(ar) = builder.ar(target) {
10311031
cmd.arg("--ar").arg(ar);
10321032
}
1033-
1034-
// Add the llvm/bin directory to PATH since it contains lots of
1035-
// useful, platform-independent tools
1036-
let llvm_bin_path = llvm_config.parent()
1037-
.expect("Expected llvm-config to be contained in directory");
1038-
assert!(llvm_bin_path.is_dir());
1039-
let old_path = env::var_os("PATH").unwrap_or_default();
1040-
let new_path = env::join_paths(iter::once(llvm_bin_path.to_path_buf())
1041-
.chain(env::split_paths(&old_path)))
1042-
.expect("");
1043-
cmd.env("PATH", new_path);
10441033
}
10451034
}
10461035
if mode == "run-make" && !builder.config.llvm_enabled {

src/bootstrap/tool.rs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use std::fs;
1212
use std::env;
13+
use std::iter;
1314
use std::path::PathBuf;
1415
use std::process::{Command, exit};
1516

@@ -593,7 +594,7 @@ impl<'a> Builder<'a> {
593594
/// right location to run `compiler`.
594595
fn prepare_tool_cmd(&self, compiler: Compiler, cmd: &mut Command) {
595596
let host = &compiler.host;
596-
let mut paths: Vec<PathBuf> = vec![
597+
let mut lib_paths: Vec<PathBuf> = vec![
597598
PathBuf::from(&self.sysroot_libdir(compiler, compiler.host)),
598599
self.cargo_out(compiler, Mode::Tool, *host).join("deps"),
599600
];
@@ -610,11 +611,46 @@ impl<'a> Builder<'a> {
610611
}
611612
for path in env::split_paths(v) {
612613
if !curpaths.contains(&path) {
613-
paths.push(path);
614+
lib_paths.push(path);
614615
}
615616
}
616617
}
617618
}
618-
add_lib_path(paths, cmd);
619+
620+
// Add the llvm/bin directory to PATH since it contains lots of
621+
// useful, platform-independent tools
622+
if let Some(llvm_bin_path) = self.llvm_bin_path() {
623+
if host.contains("windows") {
624+
// On Windows, PATH and the dynamic library path are the same,
625+
// so we just add the LLVM bin path to lib_path
626+
lib_paths.push(llvm_bin_path);
627+
} else {
628+
let old_path = env::var_os("PATH").unwrap_or_default();
629+
let new_path = env::join_paths(iter::once(llvm_bin_path)
630+
.chain(env::split_paths(&old_path)))
631+
.expect("Could not add LLVM bin path to PATH");
632+
cmd.env("PATH", new_path);
633+
}
634+
}
635+
636+
add_lib_path(lib_paths, cmd);
637+
}
638+
639+
fn llvm_bin_path(&self) -> Option<PathBuf> {
640+
if self.config.llvm_enabled && !self.config.dry_run {
641+
let llvm_config = self.ensure(native::Llvm {
642+
target: self.config.build,
643+
emscripten: false,
644+
});
645+
646+
// Add the llvm/bin directory to PATH since it contains lots of
647+
// useful, platform-independent tools
648+
let llvm_bin_path = llvm_config.parent()
649+
.expect("Expected llvm-config to be contained in directory");
650+
assert!(llvm_bin_path.is_dir());
651+
Some(llvm_bin_path.to_path_buf())
652+
} else {
653+
None
654+
}
619655
}
620656
}

0 commit comments

Comments
 (0)