|
1 | 1 | use std::fs; |
2 | 2 | use std::env; |
3 | | -use std::iter; |
4 | 3 | use std::path::PathBuf; |
5 | 4 | use std::process::{Command, exit}; |
6 | 5 | use std::collections::HashSet; |
@@ -666,27 +665,41 @@ impl<'a> Builder<'a> { |
666 | 665 |
|
667 | 666 | // Add the llvm/bin directory to PATH since it contains lots of |
668 | 667 | // useful, platform-independent tools |
669 | | - if tool.uses_llvm_tools() { |
| 668 | + if tool.uses_llvm_tools() && !self.config.dry_run { |
| 669 | + let mut additional_paths = vec![]; |
| 670 | + |
670 | 671 | if let Some(llvm_bin_path) = self.llvm_bin_path() { |
671 | | - if host.contains("windows") { |
672 | | - // On Windows, PATH and the dynamic library path are the same, |
673 | | - // so we just add the LLVM bin path to lib_path |
674 | | - lib_paths.push(llvm_bin_path); |
675 | | - } else { |
676 | | - let old_path = env::var_os("PATH").unwrap_or_default(); |
677 | | - let new_path = env::join_paths(iter::once(llvm_bin_path) |
678 | | - .chain(env::split_paths(&old_path))) |
679 | | - .expect("Could not add LLVM bin path to PATH"); |
680 | | - cmd.env("PATH", new_path); |
681 | | - } |
| 672 | + additional_paths.push(llvm_bin_path); |
| 673 | + } |
| 674 | + |
| 675 | + // If LLD is available, add that too. |
| 676 | + if self.config.lld_enabled { |
| 677 | + let lld_install_root = self.ensure(native::Lld { |
| 678 | + target: self.config.build, |
| 679 | + }); |
| 680 | + |
| 681 | + let lld_bin_path = lld_install_root.join("bin"); |
| 682 | + additional_paths.push(lld_bin_path); |
| 683 | + } |
| 684 | + |
| 685 | + if host.contains("windows") { |
| 686 | + // On Windows, PATH and the dynamic library path are the same, |
| 687 | + // so we just add the LLVM bin path to lib_path |
| 688 | + lib_paths.extend(additional_paths); |
| 689 | + } else { |
| 690 | + let old_path = env::var_os("PATH").unwrap_or_default(); |
| 691 | + let new_path = env::join_paths(additional_paths.into_iter() |
| 692 | + .chain(env::split_paths(&old_path))) |
| 693 | + .expect("Could not add LLVM bin path to PATH"); |
| 694 | + cmd.env("PATH", new_path); |
682 | 695 | } |
683 | 696 | } |
684 | 697 |
|
685 | 698 | add_lib_path(lib_paths, cmd); |
686 | 699 | } |
687 | 700 |
|
688 | 701 | fn llvm_bin_path(&self) -> Option<PathBuf> { |
689 | | - if self.config.llvm_enabled && !self.config.dry_run { |
| 702 | + if self.config.llvm_enabled { |
690 | 703 | let llvm_config = self.ensure(native::Llvm { |
691 | 704 | target: self.config.build, |
692 | 705 | emscripten: false, |
|
0 commit comments