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