]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/tool.rs
Auto merge of #75936 - sdroege:chunks-exact-construction-bounds-check, r=nagisa
[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             for (id, cur, prev) in duplicates.drain_filter(|(_, cur, prev)| cur.2 == prev.2) {
166                 println!("  {}", id);
167                 // same features
168                 println!("    `{}` ({:?})\n    `{}` ({:?})", cur.0, cur.1, prev.0, prev.1);
169             }
170             println!("the following dependencies have different features:");
171             for (id, cur, prev) in duplicates {
172                 println!("  {}", id);
173                 let cur_features: HashSet<_> = cur.2.into_iter().collect();
174                 let prev_features: HashSet<_> = prev.2.into_iter().collect();
175                 println!(
176                     "    `{}` additionally enabled features {:?} at {:?}",
177                     cur.0,
178                     &cur_features - &prev_features,
179                     cur.1
180                 );
181                 println!(
182                     "    `{}` additionally enabled features {:?} at {:?}",
183                     prev.0,
184                     &prev_features - &cur_features,
185                     prev.1
186                 );
187             }
188             println!();
189             println!(
190                 "to fix this you will probably want to edit the local \
191                       src/tools/rustc-workspace-hack/Cargo.toml crate, as \
192                       that will update the dependency graph to ensure that \
193                       these crates all share the same feature set"
194             );
195             panic!("tools should not compile multiple copies of the same crate");
196         }
197
198         builder.save_toolstate(
199             tool,
200             if is_expected { ToolState::TestFail } else { ToolState::BuildFail },
201         );
202
203         if !is_expected {
204             if !is_optional_tool {
205                 exit(1);
206             } else {
207                 None
208             }
209         } else {
210             let cargo_out =
211                 builder.cargo_out(compiler, self.mode, target).join(exe(tool, compiler.host));
212             let bin = builder.tools_dir(compiler).join(exe(tool, compiler.host));
213             builder.copy(&cargo_out, &bin);
214             Some(bin)
215         }
216     }
217 }
218
219 pub fn prepare_tool_cargo(
220     builder: &Builder<'_>,
221     compiler: Compiler,
222     mode: Mode,
223     target: TargetSelection,
224     command: &'static str,
225     path: &'static str,
226     source_type: SourceType,
227     extra_features: &[String],
228 ) -> CargoCommand {
229     let mut cargo = builder.cargo(compiler, mode, source_type, target, command);
230     let dir = builder.src.join(path);
231     cargo.arg("--manifest-path").arg(dir.join("Cargo.toml"));
232
233     let mut features = extra_features.to_vec();
234     if builder.build.config.cargo_native_static {
235         if path.ends_with("cargo")
236             || path.ends_with("rls")
237             || path.ends_with("clippy")
238             || path.ends_with("miri")
239             || path.ends_with("rustfmt")
240         {
241             cargo.env("LIBZ_SYS_STATIC", "1");
242             features.push("rustc-workspace-hack/all-static".to_string());
243         }
244     }
245
246     // if tools are using lzma we want to force the build script to build its
247     // own copy
248     cargo.env("LZMA_API_STATIC", "1");
249
250     // CFG_RELEASE is needed by rustfmt (and possibly other tools) which
251     // import rustc-ap-rustc_attr which requires this to be set for the
252     // `#[cfg(version(...))]` attribute.
253     cargo.env("CFG_RELEASE", builder.rust_release());
254     cargo.env("CFG_RELEASE_CHANNEL", &builder.config.channel);
255     cargo.env("CFG_VERSION", builder.rust_version());
256     cargo.env("CFG_RELEASE_NUM", channel::CFG_RELEASE_NUM);
257
258     let info = GitInfo::new(builder.config.ignore_git, &dir);
259     if let Some(sha) = info.sha() {
260         cargo.env("CFG_COMMIT_HASH", sha);
261     }
262     if let Some(sha_short) = info.sha_short() {
263         cargo.env("CFG_SHORT_COMMIT_HASH", sha_short);
264     }
265     if let Some(date) = info.commit_date() {
266         cargo.env("CFG_COMMIT_DATE", date);
267     }
268     if !features.is_empty() {
269         cargo.arg("--features").arg(&features.join(", "));
270     }
271     cargo
272 }
273
274 macro_rules! bootstrap_tool {
275     ($(
276         $name:ident, $path:expr, $tool_name:expr
277         $(,is_external_tool = $external:expr)*
278         $(,is_unstable_tool = $unstable:expr)*
279         $(,features = $features:expr)*
280         ;
281     )+) => {
282         #[derive(Copy, PartialEq, Eq, Clone)]
283         pub enum Tool {
284             $(
285                 $name,
286             )+
287         }
288
289         impl<'a> Builder<'a> {
290             pub fn tool_exe(&self, tool: Tool) -> PathBuf {
291                 match tool {
292                     $(Tool::$name =>
293                         self.ensure($name {
294                             compiler: self.compiler(0, self.config.build),
295                             target: self.config.build,
296                         }),
297                     )+
298                 }
299             }
300         }
301
302         $(
303             #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
304         pub struct $name {
305             pub compiler: Compiler,
306             pub target: TargetSelection,
307         }
308
309         impl Step for $name {
310             type Output = PathBuf;
311
312             fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
313                 run.path($path)
314             }
315
316             fn make_run(run: RunConfig<'_>) {
317                 run.builder.ensure($name {
318                     // snapshot compiler
319                     compiler: run.builder.compiler(0, run.builder.config.build),
320                     target: run.target,
321                 });
322             }
323
324             fn run(self, builder: &Builder<'_>) -> PathBuf {
325                 builder.ensure(ToolBuild {
326                     compiler: self.compiler,
327                     target: self.target,
328                     tool: $tool_name,
329                     mode: if false $(|| $unstable)* {
330                         // use in-tree libraries for unstable features
331                         Mode::ToolStd
332                     } else {
333                         Mode::ToolBootstrap
334                     },
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: {
343                         // FIXME(#60643): avoid this lint by using `_`
344                         let mut _tmp = Vec::new();
345                         $(_tmp.extend($features);)*
346                         _tmp
347                     },
348                 }).expect("expected to build -- essential tool")
349             }
350         }
351         )+
352     }
353 }
354
355 bootstrap_tool!(
356     Rustbook, "src/tools/rustbook", "rustbook";
357     UnstableBookGen, "src/tools/unstable-book-gen", "unstable-book-gen";
358     Tidy, "src/tools/tidy", "tidy";
359     Linkchecker, "src/tools/linkchecker", "linkchecker";
360     CargoTest, "src/tools/cargotest", "cargotest";
361     Compiletest, "src/tools/compiletest", "compiletest", is_unstable_tool = true;
362     BuildManifest, "src/tools/build-manifest", "build-manifest";
363     RemoteTestClient, "src/tools/remote-test-client", "remote-test-client";
364     RustDemangler, "src/tools/rust-demangler", "rust-demangler";
365     RustInstaller, "src/tools/rust-installer", "fabricate", is_external_tool = true;
366     RustdocTheme, "src/tools/rustdoc-themes", "rustdoc-themes";
367     ExpandYamlAnchors, "src/tools/expand-yaml-anchors", "expand-yaml-anchors";
368 );
369
370 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
371 pub struct ErrorIndex {
372     pub compiler: Compiler,
373 }
374
375 impl ErrorIndex {
376     pub fn command(builder: &Builder<'_>, compiler: Compiler) -> Command {
377         let mut cmd = Command::new(builder.ensure(ErrorIndex { compiler }));
378         add_dylib_path(
379             vec![PathBuf::from(&builder.sysroot_libdir(compiler, compiler.host))],
380             &mut cmd,
381         );
382         cmd
383     }
384 }
385
386 impl Step for ErrorIndex {
387     type Output = PathBuf;
388
389     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
390         run.path("src/tools/error_index_generator")
391     }
392
393     fn make_run(run: RunConfig<'_>) {
394         // Compile the error-index in the same stage as rustdoc to avoid
395         // recompiling rustdoc twice if we can.
396         let host = run.builder.config.build;
397         let compiler = run.builder.compiler_for(run.builder.top_stage, host, host);
398         run.builder.ensure(ErrorIndex { compiler });
399     }
400
401     fn run(self, builder: &Builder<'_>) -> PathBuf {
402         builder
403             .ensure(ToolBuild {
404                 compiler: self.compiler,
405                 target: self.compiler.host,
406                 tool: "error_index_generator",
407                 mode: Mode::ToolRustc,
408                 path: "src/tools/error_index_generator",
409                 is_optional_tool: false,
410                 source_type: SourceType::InTree,
411                 extra_features: Vec::new(),
412             })
413             .expect("expected to build -- essential tool")
414     }
415 }
416
417 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
418 pub struct RemoteTestServer {
419     pub compiler: Compiler,
420     pub target: TargetSelection,
421 }
422
423 impl Step for RemoteTestServer {
424     type Output = PathBuf;
425
426     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
427         run.path("src/tools/remote-test-server")
428     }
429
430     fn make_run(run: RunConfig<'_>) {
431         run.builder.ensure(RemoteTestServer {
432             compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
433             target: run.target,
434         });
435     }
436
437     fn run(self, builder: &Builder<'_>) -> PathBuf {
438         builder
439             .ensure(ToolBuild {
440                 compiler: self.compiler,
441                 target: self.target,
442                 tool: "remote-test-server",
443                 mode: Mode::ToolStd,
444                 path: "src/tools/remote-test-server",
445                 is_optional_tool: false,
446                 source_type: SourceType::InTree,
447                 extra_features: Vec::new(),
448             })
449             .expect("expected to build -- essential tool")
450     }
451 }
452
453 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
454 pub struct Rustdoc {
455     /// This should only ever be 0 or 2.
456     /// We sometimes want to reference the "bootstrap" rustdoc, which is why this option is here.
457     pub compiler: Compiler,
458 }
459
460 impl Step for Rustdoc {
461     type Output = PathBuf;
462     const DEFAULT: bool = true;
463     const ONLY_HOSTS: bool = true;
464
465     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
466         run.path("src/tools/rustdoc").path("src/librustdoc")
467     }
468
469     fn make_run(run: RunConfig<'_>) {
470         run.builder
471             .ensure(Rustdoc { compiler: run.builder.compiler(run.builder.top_stage, run.host) });
472     }
473
474     fn run(self, builder: &Builder<'_>) -> PathBuf {
475         let target_compiler = self.compiler;
476         if target_compiler.stage == 0 {
477             if !target_compiler.is_snapshot(builder) {
478                 panic!("rustdoc in stage 0 must be snapshot rustdoc");
479             }
480             return builder.initial_rustc.with_file_name(exe("rustdoc", target_compiler.host));
481         }
482         let target = target_compiler.host;
483         // Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
484         // we'd have stageN/bin/rustc and stageN/bin/rustdoc be effectively different stage
485         // compilers, which isn't what we want. Rustdoc should be linked in the same way as the
486         // rustc compiler it's paired with, so it must be built with the previous stage compiler.
487         let build_compiler = builder.compiler(target_compiler.stage - 1, builder.config.build);
488
489         // The presence of `target_compiler` ensures that the necessary libraries (codegen backends,
490         // compiler libraries, ...) are built. Rustdoc does not require the presence of any
491         // libraries within sysroot_libdir (i.e., rustlib), though doctests may want it (since
492         // they'll be linked to those libraries). As such, don't explicitly `ensure` any additional
493         // libraries here. The intuition here is that If we've built a compiler, we should be able
494         // to build rustdoc.
495
496         let cargo = prepare_tool_cargo(
497             builder,
498             build_compiler,
499             Mode::ToolRustc,
500             target,
501             "build",
502             "src/tools/rustdoc",
503             SourceType::InTree,
504             &[],
505         );
506
507         builder.info(&format!(
508             "Building rustdoc for stage{} ({})",
509             target_compiler.stage, target_compiler.host
510         ));
511         builder.run(&mut cargo.into());
512
513         // Cargo adds a number of paths to the dylib search path on windows, which results in
514         // the wrong rustdoc being executed. To avoid the conflicting rustdocs, we name the "tool"
515         // rustdoc a different name.
516         let tool_rustdoc = builder
517             .cargo_out(build_compiler, Mode::ToolRustc, target)
518             .join(exe("rustdoc_tool_binary", target_compiler.host));
519
520         // don't create a stage0-sysroot/bin directory.
521         if target_compiler.stage > 0 {
522             let sysroot = builder.sysroot(target_compiler);
523             let bindir = sysroot.join("bin");
524             t!(fs::create_dir_all(&bindir));
525             let bin_rustdoc = bindir.join(exe("rustdoc", target_compiler.host));
526             let _ = fs::remove_file(&bin_rustdoc);
527             builder.copy(&tool_rustdoc, &bin_rustdoc);
528             bin_rustdoc
529         } else {
530             tool_rustdoc
531         }
532     }
533 }
534
535 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
536 pub struct Cargo {
537     pub compiler: Compiler,
538     pub target: TargetSelection,
539 }
540
541 impl Step for Cargo {
542     type Output = PathBuf;
543     const DEFAULT: bool = true;
544     const ONLY_HOSTS: bool = true;
545
546     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
547         let builder = run.builder;
548         run.path("src/tools/cargo").default_condition(builder.config.extended)
549     }
550
551     fn make_run(run: RunConfig<'_>) {
552         run.builder.ensure(Cargo {
553             compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
554             target: run.target,
555         });
556     }
557
558     fn run(self, builder: &Builder<'_>) -> PathBuf {
559         builder
560             .ensure(ToolBuild {
561                 compiler: self.compiler,
562                 target: self.target,
563                 tool: "cargo",
564                 mode: Mode::ToolRustc,
565                 path: "src/tools/cargo",
566                 is_optional_tool: false,
567                 source_type: SourceType::Submodule,
568                 extra_features: Vec::new(),
569             })
570             .expect("expected to build -- essential tool")
571     }
572 }
573
574 macro_rules! tool_extended {
575     (($sel:ident, $builder:ident),
576        $($name:ident,
577        $toolstate:ident,
578        $path:expr,
579        $tool_name:expr,
580        stable = $stable:expr,
581        $(in_tree = $in_tree:expr,)*
582        $extra_deps:block;)+) => {
583         $(
584             #[derive(Debug, Clone, Hash, PartialEq, Eq)]
585         pub struct $name {
586             pub compiler: Compiler,
587             pub target: TargetSelection,
588             pub extra_features: Vec<String>,
589         }
590
591         impl Step for $name {
592             type Output = Option<PathBuf>;
593             const DEFAULT: bool = true; // Overwritten below
594             const ONLY_HOSTS: bool = true;
595
596             fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
597                 let builder = run.builder;
598                 run.path($path).default_condition(
599                     builder.config.extended
600                         && builder.config.tools.as_ref().map_or(
601                             // By default, on nightly/dev enable all tools, else only
602                             // build stable tools.
603                             $stable || builder.build.unstable_features(),
604                             // If `tools` is set, search list for this tool.
605                             |tools| {
606                                 tools.iter().any(|tool| match tool.as_ref() {
607                                     "clippy" => $tool_name == "clippy-driver",
608                                     x => $tool_name == x,
609                             })
610                         }),
611                 )
612             }
613
614             fn make_run(run: RunConfig<'_>) {
615                 run.builder.ensure($name {
616                     compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
617                     target: run.target,
618                     extra_features: Vec::new(),
619                 });
620             }
621
622             #[allow(unused_mut)]
623             fn run(mut $sel, $builder: &Builder<'_>) -> Option<PathBuf> {
624                 $extra_deps
625                 $builder.ensure(ToolBuild {
626                     compiler: $sel.compiler,
627                     target: $sel.target,
628                     tool: $tool_name,
629                     mode: Mode::ToolRustc,
630                     path: $path,
631                     extra_features: $sel.extra_features,
632                     is_optional_tool: true,
633                     source_type: if false $(|| $in_tree)* {
634                         SourceType::InTree
635                     } else {
636                         SourceType::Submodule
637                     },
638                 })
639             }
640         }
641         )+
642     }
643 }
644
645 // Note: tools need to be also added to `Builder::get_step_descriptions` in `builder.rs`
646 // to make `./x.py build <tool>` work.
647 tool_extended!((self, builder),
648     Cargofmt, rustfmt, "src/tools/rustfmt", "cargo-fmt", stable=true, {};
649     CargoClippy, clippy, "src/tools/clippy", "cargo-clippy", stable=true, in_tree=true, {};
650     Clippy, clippy, "src/tools/clippy", "clippy-driver", stable=true, in_tree=true, {};
651     Miri, miri, "src/tools/miri", "miri", stable=false, {};
652     CargoMiri, miri, "src/tools/miri/cargo-miri", "cargo-miri", stable=false, {};
653     Rls, rls, "src/tools/rls", "rls", stable=true, {
654         builder.ensure(Clippy {
655             compiler: self.compiler,
656             target: self.target,
657             extra_features: Vec::new(),
658         });
659         self.extra_features.push("clippy".to_owned());
660     };
661     Rustfmt, rustfmt, "src/tools/rustfmt", "rustfmt", stable=true, {};
662     RustAnalyzer, rust_analyzer, "src/tools/rust-analyzer/crates/rust-analyzer", "rust-analyzer", stable=false, {};
663 );
664
665 impl<'a> Builder<'a> {
666     /// Gets a `Command` which is ready to run `tool` in `stage` built for
667     /// `host`.
668     pub fn tool_cmd(&self, tool: Tool) -> Command {
669         let mut cmd = Command::new(self.tool_exe(tool));
670         let compiler = self.compiler(0, self.config.build);
671         let host = &compiler.host;
672         // Prepares the `cmd` provided to be able to run the `compiler` provided.
673         //
674         // Notably this munges the dynamic library lookup path to point to the
675         // right location to run `compiler`.
676         let mut lib_paths: Vec<PathBuf> = vec![
677             self.build.rustc_snapshot_libdir(),
678             self.cargo_out(compiler, Mode::ToolBootstrap, *host).join("deps"),
679         ];
680
681         // On MSVC a tool may invoke a C compiler (e.g., compiletest in run-make
682         // mode) and that C compiler may need some extra PATH modification. Do
683         // so here.
684         if compiler.host.contains("msvc") {
685             let curpaths = env::var_os("PATH").unwrap_or_default();
686             let curpaths = env::split_paths(&curpaths).collect::<Vec<_>>();
687             for &(ref k, ref v) in self.cc[&compiler.host].env() {
688                 if k != "PATH" {
689                     continue;
690                 }
691                 for path in env::split_paths(v) {
692                     if !curpaths.contains(&path) {
693                         lib_paths.push(path);
694                     }
695                 }
696             }
697         }
698
699         add_dylib_path(lib_paths, &mut cmd);
700         cmd
701     }
702 }