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