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