]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/tool.rs
6383a2ecc75832a2498fe45d66ef8c55923648f1
[rust.git] / src / bootstrap / tool.rs
1 use std::fs;
2 use std::env;
3 use std::path::PathBuf;
4 use std::process::{Command, exit};
5 use std::collections::HashSet;
6
7 use crate::Mode;
8 use crate::Compiler;
9 use crate::builder::{Step, RunConfig, ShouldRun, Builder};
10 use crate::util::{exe, add_lib_path};
11 use crate::compile;
12 use crate::native;
13 use crate::channel::GitInfo;
14 use crate::channel;
15 use crate::cache::Interned;
16 use crate::toolstate::ToolState;
17
18 #[derive(Debug, Clone, Hash, PartialEq, Eq)]
19 pub enum SourceType {
20     InTree,
21     Submodule,
22 }
23
24 #[derive(Debug, Clone, Hash, PartialEq, Eq)]
25 struct ToolBuild {
26     compiler: Compiler,
27     target: Interned<String>,
28     tool: &'static str,
29     path: &'static str,
30     mode: Mode,
31     is_optional_tool: bool,
32     source_type: SourceType,
33     extra_features: Vec<String>,
34 }
35
36 impl Step for ToolBuild {
37     type Output = Option<PathBuf>;
38
39     fn should_run(run: ShouldRun) -> ShouldRun {
40         run.never()
41     }
42
43     /// Builds a tool in `src/tools`
44     ///
45     /// This will build the specified tool with the specified `host` compiler in
46     /// `stage` into the normal cargo output directory.
47     fn run(self, builder: &Builder) -> Option<PathBuf> {
48         let compiler = self.compiler;
49         let target = self.target;
50         let tool = self.tool;
51         let path = self.path;
52         let is_optional_tool = self.is_optional_tool;
53
54         match self.mode {
55             Mode::ToolRustc => {
56                 builder.ensure(compile::Rustc { compiler, target })
57             }
58             Mode::ToolStd => {
59                 builder.ensure(compile::Std { compiler, target })
60             }
61             Mode::ToolBootstrap => {} // uses downloaded stage0 compiler libs
62             _ => panic!("unexpected Mode for tool build")
63         }
64
65         let mut cargo = prepare_tool_cargo(
66             builder,
67             compiler,
68             self.mode,
69             target,
70             "build",
71             path,
72             self.source_type,
73             &self.extra_features,
74         );
75
76         let _folder = builder.fold_output(|| format!("stage{}-{}", compiler.stage, tool));
77         builder.info(&format!("Building stage{} tool {} ({})", compiler.stage, tool, target));
78         let mut duplicates = Vec::new();
79         let is_expected = compile::stream_cargo(builder, &mut cargo, &mut |msg| {
80             // Only care about big things like the RLS/Cargo for now
81             match tool {
82                 | "rls"
83                 | "cargo"
84                 | "clippy-driver"
85                 | "miri"
86                 => {}
87
88                 _ => return,
89             }
90             let (id, features, filenames) = match msg {
91                 compile::CargoMessage::CompilerArtifact {
92                     package_id,
93                     features,
94                     filenames
95                 } => {
96                     (package_id, features, filenames)
97                 }
98                 _ => return,
99             };
100             let features = features.iter().map(|s| s.to_string()).collect::<Vec<_>>();
101
102             for path in filenames {
103                 let val = (tool, PathBuf::from(&*path), features.clone());
104                 // we're only interested in deduplicating rlibs for now
105                 if val.1.extension().and_then(|s| s.to_str()) != Some("rlib") {
106                     continue
107                 }
108
109                 // Don't worry about libs that turn out to be host dependencies
110                 // or build scripts, we only care about target dependencies that
111                 // are in `deps`.
112                 if let Some(maybe_target) = val.1
113                     .parent()                   // chop off file name
114                     .and_then(|p| p.parent())   // chop off `deps`
115                     .and_then(|p| p.parent())   // chop off `release`
116                     .and_then(|p| p.file_name())
117                     .and_then(|p| p.to_str())
118                 {
119                     if maybe_target != &*target {
120                         continue
121                     }
122                 }
123
124                 let mut artifacts = builder.tool_artifacts.borrow_mut();
125                 let prev_artifacts = artifacts
126                     .entry(target)
127                     .or_default();
128                 if let Some(prev) = prev_artifacts.get(&*id) {
129                     if prev.1 != val.1 {
130                         duplicates.push((
131                             id.to_string(),
132                             val,
133                             prev.clone(),
134                         ));
135                     }
136                     return
137                 }
138                 prev_artifacts.insert(id.to_string(), val);
139             }
140         });
141
142         if is_expected && !duplicates.is_empty() {
143             println!("duplicate artifacts found when compiling a tool, this \
144                       typically means that something was recompiled because \
145                       a transitive dependency has different features activated \
146                       than in a previous build:\n");
147             println!("the following dependencies are duplicated although they \
148                       have the same features enabled:");
149             for (id, cur, prev) in duplicates.drain_filter(|(_, cur, prev)| cur.2 == prev.2) {
150                 println!("  {}", id);
151                 // same features
152                 println!("    `{}` ({:?})\n    `{}` ({:?})", cur.0, cur.1, prev.0, prev.1);
153             }
154             println!("the following dependencies have different features:");
155             for (id, cur, prev) in duplicates {
156                 println!("  {}", id);
157                 let cur_features: HashSet<_> = cur.2.into_iter().collect();
158                 let prev_features: HashSet<_> = prev.2.into_iter().collect();
159                 println!("    `{}` additionally enabled features {:?} at {:?}",
160                          cur.0, &cur_features - &prev_features, cur.1);
161                 println!("    `{}` additionally enabled features {:?} at {:?}",
162                          prev.0, &prev_features - &cur_features, prev.1);
163             }
164             println!();
165             println!("to fix this you will probably want to edit the local \
166                       src/tools/rustc-workspace-hack/Cargo.toml crate, as \
167                       that will update the dependency graph to ensure that \
168                       these crates all share the same feature set");
169             panic!("tools should not compile multiple copies of the same crate");
170         }
171
172         builder.save_toolstate(tool, if is_expected {
173             ToolState::TestFail
174         } else {
175             ToolState::BuildFail
176         });
177
178         if !is_expected {
179             if !is_optional_tool {
180                 exit(1);
181             } else {
182                 None
183             }
184         } else {
185             let cargo_out = builder.cargo_out(compiler, self.mode, target)
186                 .join(exe(tool, &compiler.host));
187             let bin = builder.tools_dir(compiler).join(exe(tool, &compiler.host));
188             builder.copy(&cargo_out, &bin);
189             Some(bin)
190         }
191     }
192 }
193
194 pub fn prepare_tool_cargo(
195     builder: &Builder,
196     compiler: Compiler,
197     mode: Mode,
198     target: Interned<String>,
199     command: &'static str,
200     path: &'static str,
201     source_type: SourceType,
202     extra_features: &[String],
203 ) -> Command {
204     let mut cargo = builder.cargo(compiler, mode, target, command);
205     let dir = builder.src.join(path);
206     cargo.arg("--manifest-path").arg(dir.join("Cargo.toml"));
207
208     // We don't want to build tools dynamically as they'll be running across
209     // stages and such and it's just easier if they're not dynamically linked.
210     cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
211
212     if source_type == SourceType::Submodule {
213         cargo.env("RUSTC_EXTERNAL_TOOL", "1");
214     }
215
216     let mut features = extra_features.iter().cloned().collect::<Vec<_>>();
217     if builder.build.config.cargo_native_static {
218         if path.ends_with("cargo") ||
219             path.ends_with("rls") ||
220             path.ends_with("clippy") ||
221             path.ends_with("miri") ||
222             path.ends_with("rustfmt")
223         {
224             cargo.env("LIBZ_SYS_STATIC", "1");
225             features.push("rustc-workspace-hack/all-static".to_string());
226         }
227     }
228
229     // if tools are using lzma we want to force the build script to build its
230     // own copy
231     cargo.env("LZMA_API_STATIC", "1");
232
233     cargo.env("CFG_RELEASE_CHANNEL", &builder.config.channel);
234     cargo.env("CFG_VERSION", builder.rust_version());
235     cargo.env("CFG_RELEASE_NUM", channel::CFG_RELEASE_NUM);
236
237     let info = GitInfo::new(&builder.config, &dir);
238     if let Some(sha) = info.sha() {
239         cargo.env("CFG_COMMIT_HASH", sha);
240     }
241     if let Some(sha_short) = info.sha_short() {
242         cargo.env("CFG_SHORT_COMMIT_HASH", sha_short);
243     }
244     if let Some(date) = info.commit_date() {
245         cargo.env("CFG_COMMIT_DATE", date);
246     }
247     if !features.is_empty() {
248         cargo.arg("--features").arg(&features.join(", "));
249     }
250     cargo
251 }
252
253 macro_rules! tool {
254     ($(
255         $name:ident, $path:expr, $tool_name:expr, $mode:expr
256         $(,llvm_tools = $llvm:expr)*
257         $(,is_external_tool = $external:expr)*
258         ;
259     )+) => {
260         #[derive(Copy, PartialEq, Eq, Clone)]
261         pub enum Tool {
262             $(
263                 $name,
264             )+
265         }
266
267         impl Tool {
268             pub fn get_mode(&self) -> Mode {
269                 let mode = match self {
270                     $(Tool::$name => $mode,)+
271                 };
272                 mode
273             }
274
275             /// Whether this tool requires LLVM to run
276             pub fn uses_llvm_tools(&self) -> bool {
277                 match self {
278                     $(Tool::$name => false $(|| $llvm)*,)+
279                 }
280             }
281         }
282
283         impl<'a> Builder<'a> {
284             pub fn tool_exe(&self, tool: Tool) -> PathBuf {
285                 let stage = self.tool_default_stage(tool);
286                 match tool {
287                     $(Tool::$name =>
288                         self.ensure($name {
289                             compiler: self.compiler(stage, self.config.build),
290                             target: self.config.build,
291                         }),
292                     )+
293                 }
294             }
295
296             pub fn tool_default_stage(&self, tool: Tool) -> u32 {
297                 // Compile the error-index in the same stage as rustdoc to avoid
298                 // recompiling rustdoc twice if we can. Otherwise compile
299                 // everything else in stage0 as there's no need to rebootstrap
300                 // everything.
301                 match tool {
302                     Tool::ErrorIndex if self.top_stage >= 2 => self.top_stage,
303                     _ => 0,
304                 }
305             }
306         }
307
308         $(
309             #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
310         pub struct $name {
311             pub compiler: Compiler,
312             pub target: Interned<String>,
313         }
314
315         impl Step for $name {
316             type Output = PathBuf;
317
318             fn should_run(run: ShouldRun) -> ShouldRun {
319                 run.path($path)
320             }
321
322             fn make_run(run: RunConfig) {
323                 run.builder.ensure($name {
324                     compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
325                     target: run.target,
326                 });
327             }
328
329             fn run(self, builder: &Builder) -> PathBuf {
330                 builder.ensure(ToolBuild {
331                     compiler: self.compiler,
332                     target: self.target,
333                     tool: $tool_name,
334                     mode: $mode,
335                     path: $path,
336                     is_optional_tool: false,
337                     source_type: if false $(|| $external)* {
338                         SourceType::Submodule
339                     } else {
340                         SourceType::InTree
341                     },
342                     extra_features: Vec::new(),
343                 }).expect("expected to build -- essential tool")
344             }
345         }
346         )+
347     }
348 }
349
350 tool!(
351     Rustbook, "src/tools/rustbook", "rustbook", Mode::ToolBootstrap;
352     ErrorIndex, "src/tools/error_index_generator", "error_index_generator", Mode::ToolRustc;
353     UnstableBookGen, "src/tools/unstable-book-gen", "unstable-book-gen", Mode::ToolBootstrap;
354     Tidy, "src/tools/tidy", "tidy", Mode::ToolBootstrap;
355     Linkchecker, "src/tools/linkchecker", "linkchecker", Mode::ToolBootstrap;
356     CargoTest, "src/tools/cargotest", "cargotest", Mode::ToolBootstrap;
357     Compiletest, "src/tools/compiletest", "compiletest", Mode::ToolBootstrap, llvm_tools = true;
358     BuildManifest, "src/tools/build-manifest", "build-manifest", Mode::ToolBootstrap;
359     RemoteTestClient, "src/tools/remote-test-client", "remote-test-client", Mode::ToolBootstrap;
360     RustInstaller, "src/tools/rust-installer", "fabricate", Mode::ToolBootstrap,
361         is_external_tool = true;
362     RustdocTheme, "src/tools/rustdoc-themes", "rustdoc-themes", Mode::ToolBootstrap;
363 );
364
365 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
366 pub struct RemoteTestServer {
367     pub compiler: Compiler,
368     pub target: Interned<String>,
369 }
370
371 impl Step for RemoteTestServer {
372     type Output = PathBuf;
373
374     fn should_run(run: ShouldRun) -> ShouldRun {
375         run.path("src/tools/remote-test-server")
376     }
377
378     fn make_run(run: RunConfig) {
379         run.builder.ensure(RemoteTestServer {
380             compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
381             target: run.target,
382         });
383     }
384
385     fn run(self, builder: &Builder) -> PathBuf {
386         builder.ensure(ToolBuild {
387             compiler: self.compiler,
388             target: self.target,
389             tool: "remote-test-server",
390             mode: Mode::ToolStd,
391             path: "src/tools/remote-test-server",
392             is_optional_tool: false,
393             source_type: SourceType::InTree,
394             extra_features: Vec::new(),
395         }).expect("expected to build -- essential tool")
396     }
397 }
398
399 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
400 pub struct Rustdoc {
401     pub host: Interned<String>,
402 }
403
404 impl Step for Rustdoc {
405     type Output = PathBuf;
406     const DEFAULT: bool = true;
407     const ONLY_HOSTS: bool = true;
408
409     fn should_run(run: ShouldRun) -> ShouldRun {
410         run.path("src/tools/rustdoc")
411     }
412
413     fn make_run(run: RunConfig) {
414         run.builder.ensure(Rustdoc {
415             host: run.host,
416         });
417     }
418
419     fn run(self, builder: &Builder) -> PathBuf {
420         let target_compiler = builder.compiler(builder.top_stage, self.host);
421         if target_compiler.stage == 0 {
422             if !target_compiler.is_snapshot(builder) {
423                 panic!("rustdoc in stage 0 must be snapshot rustdoc");
424             }
425             return builder.initial_rustc.with_file_name(exe("rustdoc", &target_compiler.host));
426         }
427         let target = target_compiler.host;
428         // Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
429         // we'd have stageN/bin/rustc and stageN/bin/rustdoc be effectively different stage
430         // compilers, which isn't what we want. Rustdoc should be linked in the same way as the
431         // rustc compiler it's paired with, so it must be built with the previous stage compiler.
432         let build_compiler = builder.compiler(target_compiler.stage - 1, builder.config.build);
433
434         // The presence of `target_compiler` ensures that the necessary libraries (codegen backends,
435         // compiler libraries, ...) are built. Rustdoc does not require the presence of any
436         // libraries within sysroot_libdir (i.e., rustlib), though doctests may want it (since
437         // they'll be linked to those libraries). As such, don't explicitly `ensure` any additional
438         // libraries here. The intuition here is that If we've built a compiler, we should be able
439         // to build rustdoc.
440
441         let mut cargo = prepare_tool_cargo(
442             builder,
443             build_compiler,
444             Mode::ToolRustc,
445             target,
446             "build",
447             "src/tools/rustdoc",
448             SourceType::InTree,
449             &[],
450         );
451
452         // Most tools don't get debuginfo, but rustdoc should.
453         cargo.env("RUSTC_DEBUGINFO", builder.config.rust_debuginfo.to_string())
454              .env("RUSTC_DEBUGINFO_LINES", builder.config.rust_debuginfo_lines.to_string());
455
456         let _folder = builder.fold_output(|| format!("stage{}-rustdoc", target_compiler.stage));
457         builder.info(&format!("Building rustdoc for stage{} ({})",
458             target_compiler.stage, target_compiler.host));
459         builder.run(&mut cargo);
460
461         // Cargo adds a number of paths to the dylib search path on windows, which results in
462         // the wrong rustdoc being executed. To avoid the conflicting rustdocs, we name the "tool"
463         // rustdoc a different name.
464         let tool_rustdoc = builder.cargo_out(build_compiler, Mode::ToolRustc, target)
465             .join(exe("rustdoc_tool_binary", &target_compiler.host));
466
467         // don't create a stage0-sysroot/bin directory.
468         if target_compiler.stage > 0 {
469             let sysroot = builder.sysroot(target_compiler);
470             let bindir = sysroot.join("bin");
471             t!(fs::create_dir_all(&bindir));
472             let bin_rustdoc = bindir.join(exe("rustdoc", &*target_compiler.host));
473             let _ = fs::remove_file(&bin_rustdoc);
474             builder.copy(&tool_rustdoc, &bin_rustdoc);
475             bin_rustdoc
476         } else {
477             tool_rustdoc
478         }
479     }
480 }
481
482 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
483 pub struct Cargo {
484     pub compiler: Compiler,
485     pub target: Interned<String>,
486 }
487
488 impl Step for Cargo {
489     type Output = PathBuf;
490     const DEFAULT: bool = true;
491     const ONLY_HOSTS: bool = true;
492
493     fn should_run(run: ShouldRun) -> ShouldRun {
494         let builder = run.builder;
495         run.path("src/tools/cargo").default_condition(builder.config.extended)
496     }
497
498     fn make_run(run: RunConfig) {
499         run.builder.ensure(Cargo {
500             compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
501             target: run.target,
502         });
503     }
504
505     fn run(self, builder: &Builder) -> PathBuf {
506         // Cargo depends on procedural macros, which requires a full host
507         // compiler to be available, so we need to depend on that.
508         builder.ensure(compile::Rustc {
509             compiler: self.compiler,
510             target: builder.config.build,
511         });
512         builder.ensure(ToolBuild {
513             compiler: self.compiler,
514             target: self.target,
515             tool: "cargo",
516             mode: Mode::ToolRustc,
517             path: "src/tools/cargo",
518             is_optional_tool: false,
519             source_type: SourceType::Submodule,
520             extra_features: Vec::new(),
521         }).expect("expected to build -- essential tool")
522     }
523 }
524
525 macro_rules! tool_extended {
526     (($sel:ident, $builder:ident),
527        $($name:ident,
528        $toolstate:ident,
529        $path:expr,
530        $tool_name:expr,
531        $extra_deps:block;)+) => {
532         $(
533             #[derive(Debug, Clone, Hash, PartialEq, Eq)]
534         pub struct $name {
535             pub compiler: Compiler,
536             pub target: Interned<String>,
537             pub extra_features: Vec<String>,
538         }
539
540         impl Step for $name {
541             type Output = Option<PathBuf>;
542             const DEFAULT: bool = true;
543             const ONLY_HOSTS: bool = true;
544
545             fn should_run(run: ShouldRun) -> ShouldRun {
546                 let builder = run.builder;
547                 run.path($path).default_condition(builder.config.extended)
548             }
549
550             fn make_run(run: RunConfig) {
551                 run.builder.ensure($name {
552                     compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
553                     target: run.target,
554                     extra_features: Vec::new(),
555                 });
556             }
557
558             #[allow(unused_mut)]
559             fn run(mut $sel, $builder: &Builder) -> Option<PathBuf> {
560                 $extra_deps
561                 $builder.ensure(ToolBuild {
562                     compiler: $sel.compiler,
563                     target: $sel.target,
564                     tool: $tool_name,
565                     mode: Mode::ToolRustc,
566                     path: $path,
567                     extra_features: $sel.extra_features,
568                     is_optional_tool: true,
569                     source_type: SourceType::Submodule,
570                 })
571             }
572         }
573         )+
574     }
575 }
576
577 tool_extended!((self, builder),
578     Cargofmt, rustfmt, "src/tools/rustfmt", "cargo-fmt", {};
579     CargoClippy, clippy, "src/tools/clippy", "cargo-clippy", {
580         // Clippy depends on procedural macros (serde), which requires a full host
581         // compiler to be available, so we need to depend on that.
582         builder.ensure(compile::Rustc {
583             compiler: self.compiler,
584             target: builder.config.build,
585         });
586     };
587     Clippy, clippy, "src/tools/clippy", "clippy-driver", {
588         // Clippy depends on procedural macros (serde), which requires a full host
589         // compiler to be available, so we need to depend on that.
590         builder.ensure(compile::Rustc {
591             compiler: self.compiler,
592             target: builder.config.build,
593         });
594     };
595     Miri, miri, "src/tools/miri", "miri", {};
596     CargoMiri, miri, "src/tools/miri", "cargo-miri", {
597         // Miri depends on procedural macros (serde), which requires a full host
598         // compiler to be available, so we need to depend on that.
599         builder.ensure(compile::Rustc {
600             compiler: self.compiler,
601             target: builder.config.build,
602         });
603     };
604     Rls, rls, "src/tools/rls", "rls", {
605         let clippy = builder.ensure(Clippy {
606             compiler: self.compiler,
607             target: self.target,
608             extra_features: Vec::new(),
609         });
610         if clippy.is_some() {
611             self.extra_features.push("clippy".to_owned());
612         }
613         // RLS depends on procedural macros, which requires a full host
614         // compiler to be available, so we need to depend on that.
615         builder.ensure(compile::Rustc {
616             compiler: self.compiler,
617             target: builder.config.build,
618         });
619     };
620     Rustfmt, rustfmt, "src/tools/rustfmt", "rustfmt", {};
621 );
622
623 impl<'a> Builder<'a> {
624     /// Gets a `Command` which is ready to run `tool` in `stage` built for
625     /// `host`.
626     pub fn tool_cmd(&self, tool: Tool) -> Command {
627         let mut cmd = Command::new(self.tool_exe(tool));
628         let compiler = self.compiler(self.tool_default_stage(tool), self.config.build);
629         self.prepare_tool_cmd(compiler, tool, &mut cmd);
630         cmd
631     }
632
633     /// Prepares the `cmd` provided to be able to run the `compiler` provided.
634     ///
635     /// Notably this munges the dynamic library lookup path to point to the
636     /// right location to run `compiler`.
637     fn prepare_tool_cmd(&self, compiler: Compiler, tool: Tool, cmd: &mut Command) {
638         let host = &compiler.host;
639         let mut lib_paths: Vec<PathBuf> = vec![
640             if compiler.stage == 0 && tool != Tool::ErrorIndex {
641                 self.build.rustc_snapshot_libdir()
642             } else {
643                 PathBuf::from(&self.sysroot_libdir(compiler, compiler.host))
644             },
645             self.cargo_out(compiler, tool.get_mode(), *host).join("deps"),
646         ];
647
648         // On MSVC a tool may invoke a C compiler (e.g., compiletest in run-make
649         // mode) and that C compiler may need some extra PATH modification. Do
650         // so here.
651         if compiler.host.contains("msvc") {
652             let curpaths = env::var_os("PATH").unwrap_or_default();
653             let curpaths = env::split_paths(&curpaths).collect::<Vec<_>>();
654             for &(ref k, ref v) in self.cc[&compiler.host].env() {
655                 if k != "PATH" {
656                     continue
657                 }
658                 for path in env::split_paths(v) {
659                     if !curpaths.contains(&path) {
660                         lib_paths.push(path);
661                     }
662                 }
663             }
664         }
665
666         // Add the llvm/bin directory to PATH since it contains lots of
667         // useful, platform-independent tools
668         if tool.uses_llvm_tools() && !self.config.dry_run {
669             let mut additional_paths = vec![];
670
671             if let Some(llvm_bin_path) = self.llvm_bin_path() {
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);
695             }
696         }
697
698         add_lib_path(lib_paths, cmd);
699     }
700
701     fn llvm_bin_path(&self) -> Option<PathBuf> {
702         if self.config.llvm_enabled {
703             let llvm_config = self.ensure(native::Llvm {
704                 target: self.config.build,
705                 emscripten: false,
706             });
707
708             // Add the llvm/bin directory to PATH since it contains lots of
709             // useful, platform-independent tools
710             let llvm_bin_path = llvm_config.parent()
711                 .expect("Expected llvm-config to be contained in directory");
712             assert!(llvm_bin_path.is_dir());
713             Some(llvm_bin_path.to_path_buf())
714         } else {
715             None
716         }
717     }
718 }