]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/tool.rs
Auto merge of #65459 - ecstatic-morse:graphviz-subgraph, r=estebank
[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, Cargo as CargoCommand};
12 use crate::util::{exe, add_lib_path, CiEnv};
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 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, 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 ) -> CargoCommand {
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     if source_type == SourceType::Submodule {
238         cargo.env("RUSTC_EXTERNAL_TOOL", "1");
239     }
240
241     let mut features = extra_features.iter().cloned().collect::<Vec<_>>();
242     if builder.build.config.cargo_native_static {
243         if path.ends_with("cargo") ||
244             path.ends_with("rls") ||
245             path.ends_with("clippy") ||
246             path.ends_with("miri") ||
247             path.ends_with("rustbook") ||
248             path.ends_with("rustfmt")
249         {
250             cargo.env("LIBZ_SYS_STATIC", "1");
251             features.push("rustc-workspace-hack/all-static".to_string());
252         }
253     }
254
255     // if tools are using lzma we want to force the build script to build its
256     // own copy
257     cargo.env("LZMA_API_STATIC", "1");
258
259     cargo.env("CFG_RELEASE_CHANNEL", &builder.config.channel);
260     cargo.env("CFG_VERSION", builder.rust_version());
261     cargo.env("CFG_RELEASE_NUM", channel::CFG_RELEASE_NUM);
262
263     let info = GitInfo::new(builder.config.ignore_git, &dir);
264     if let Some(sha) = info.sha() {
265         cargo.env("CFG_COMMIT_HASH", sha);
266     }
267     if let Some(sha_short) = info.sha_short() {
268         cargo.env("CFG_SHORT_COMMIT_HASH", sha_short);
269     }
270     if let Some(date) = info.commit_date() {
271         cargo.env("CFG_COMMIT_DATE", date);
272     }
273     if !features.is_empty() {
274         cargo.arg("--features").arg(&features.join(", "));
275     }
276     cargo
277 }
278
279 fn rustbook_features() -> Vec<String> {
280     let mut features = Vec::new();
281
282     // Due to CI budged and risk of spurious failures we want to limit jobs running this check.
283     // At same time local builds should run it regardless of the platform.
284     // `CiEnv::None` means it's local build and `CHECK_LINKS` is defined in x86_64-gnu-tools to
285     // explicitly enable it on single job
286     if CiEnv::current() == CiEnv::None || env::var("CHECK_LINKS").is_ok() {
287         features.push("linkcheck".to_string());
288     }
289
290     features
291 }
292
293 macro_rules! bootstrap_tool {
294     ($(
295         $name:ident, $path:expr, $tool_name:expr
296         $(,llvm_tools = $llvm:expr)*
297         $(,is_external_tool = $external:expr)*
298         $(,features = $features:expr)*
299         ;
300     )+) => {
301         #[derive(Copy, PartialEq, Eq, Clone)]
302         pub enum Tool {
303             $(
304                 $name,
305             )+
306         }
307
308         impl Tool {
309             /// Whether this tool requires LLVM to run
310             pub fn uses_llvm_tools(&self) -> bool {
311                 match self {
312                     $(Tool::$name => false $(|| $llvm)*,)+
313                 }
314             }
315         }
316
317         impl<'a> Builder<'a> {
318             pub fn tool_exe(&self, tool: Tool) -> PathBuf {
319                 match tool {
320                     $(Tool::$name =>
321                         self.ensure($name {
322                             compiler: self.compiler(0, self.config.build),
323                             target: self.config.build,
324                         }),
325                     )+
326                 }
327             }
328         }
329
330         $(
331             #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
332         pub struct $name {
333             pub compiler: Compiler,
334             pub target: Interned<String>,
335         }
336
337         impl Step for $name {
338             type Output = PathBuf;
339
340             fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
341                 run.path($path)
342             }
343
344             fn make_run(run: RunConfig<'_>) {
345                 run.builder.ensure($name {
346                     // snapshot compiler
347                     compiler: run.builder.compiler(0, run.builder.config.build),
348                     target: run.target,
349                 });
350             }
351
352             fn run(self, builder: &Builder<'_>) -> PathBuf {
353                 builder.ensure(ToolBuild {
354                     compiler: self.compiler,
355                     target: self.target,
356                     tool: $tool_name,
357                     mode: Mode::ToolBootstrap,
358                     path: $path,
359                     is_optional_tool: false,
360                     source_type: if false $(|| $external)* {
361                         SourceType::Submodule
362                     } else {
363                         SourceType::InTree
364                     },
365                     extra_features: {
366                         // FIXME(#60643): avoid this lint by using `_`
367                         let mut _tmp = Vec::new();
368                         $(_tmp.extend($features);)*
369                         _tmp
370                     },
371                 }).expect("expected to build -- essential tool")
372             }
373         }
374         )+
375     }
376 }
377
378 bootstrap_tool!(
379     Rustbook, "src/tools/rustbook", "rustbook", features = rustbook_features();
380     UnstableBookGen, "src/tools/unstable-book-gen", "unstable-book-gen";
381     Tidy, "src/tools/tidy", "tidy";
382     Linkchecker, "src/tools/linkchecker", "linkchecker";
383     CargoTest, "src/tools/cargotest", "cargotest";
384     Compiletest, "src/tools/compiletest", "compiletest", llvm_tools = true;
385     BuildManifest, "src/tools/build-manifest", "build-manifest";
386     RemoteTestClient, "src/tools/remote-test-client", "remote-test-client";
387     RustInstaller, "src/tools/rust-installer", "fabricate", is_external_tool = true;
388     RustdocTheme, "src/tools/rustdoc-themes", "rustdoc-themes";
389 );
390
391 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
392 pub struct ErrorIndex {
393     pub compiler: Compiler,
394 }
395
396 impl ErrorIndex {
397     pub fn command(builder: &Builder<'_>, compiler: Compiler) -> Command {
398         let mut cmd = Command::new(builder.ensure(ErrorIndex {
399             compiler
400         }));
401         add_lib_path(
402             vec![PathBuf::from(&builder.sysroot_libdir(compiler, compiler.host))],
403             &mut cmd,
404         );
405         cmd
406     }
407 }
408
409 impl Step for ErrorIndex {
410     type Output = PathBuf;
411
412     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
413         run.path("src/tools/error_index_generator")
414     }
415
416     fn make_run(run: RunConfig<'_>) {
417         // Compile the error-index in the same stage as rustdoc to avoid
418         // recompiling rustdoc twice if we can.
419         let stage = if run.builder.top_stage >= 2 { run.builder.top_stage } else { 0 };
420         run.builder.ensure(ErrorIndex {
421             compiler: run.builder.compiler(stage, run.builder.config.build),
422         });
423     }
424
425     fn run(self, builder: &Builder<'_>) -> PathBuf {
426         builder.ensure(ToolBuild {
427             compiler: self.compiler,
428             target: self.compiler.host,
429             tool: "error_index_generator",
430             mode: Mode::ToolRustc,
431             path: "src/tools/error_index_generator",
432             is_optional_tool: false,
433             source_type: SourceType::InTree,
434             extra_features: Vec::new(),
435         }).expect("expected to build -- essential tool")
436     }
437 }
438
439 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
440 pub struct RemoteTestServer {
441     pub compiler: Compiler,
442     pub target: Interned<String>,
443 }
444
445 impl Step for RemoteTestServer {
446     type Output = PathBuf;
447
448     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
449         run.path("src/tools/remote-test-server")
450     }
451
452     fn make_run(run: RunConfig<'_>) {
453         run.builder.ensure(RemoteTestServer {
454             compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
455             target: run.target,
456         });
457     }
458
459     fn run(self, builder: &Builder<'_>) -> PathBuf {
460         builder.ensure(ToolBuild {
461             compiler: self.compiler,
462             target: self.target,
463             tool: "remote-test-server",
464             mode: Mode::ToolStd,
465             path: "src/tools/remote-test-server",
466             is_optional_tool: false,
467             source_type: SourceType::InTree,
468             extra_features: Vec::new(),
469         }).expect("expected to build -- essential tool")
470     }
471 }
472
473 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
474 pub struct Rustdoc {
475     /// This should only ever be 0 or 2.
476     /// We sometimes want to reference the "bootstrap" rustdoc, which is why this option is here.
477     pub compiler: Compiler,
478 }
479
480 impl Step for Rustdoc {
481     type Output = PathBuf;
482     const DEFAULT: bool = true;
483     const ONLY_HOSTS: bool = true;
484
485     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
486         run.path("src/tools/rustdoc")
487     }
488
489     fn make_run(run: RunConfig<'_>) {
490         run.builder.ensure(Rustdoc {
491             compiler: run.builder.compiler(run.builder.top_stage, run.host),
492         });
493     }
494
495     fn run(self, builder: &Builder<'_>) -> PathBuf {
496         let target_compiler = self.compiler;
497         if target_compiler.stage == 0 {
498             if !target_compiler.is_snapshot(builder) {
499                 panic!("rustdoc in stage 0 must be snapshot rustdoc");
500             }
501             return builder.initial_rustc.with_file_name(exe("rustdoc", &target_compiler.host));
502         }
503         let target = target_compiler.host;
504         // Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
505         // we'd have stageN/bin/rustc and stageN/bin/rustdoc be effectively different stage
506         // compilers, which isn't what we want. Rustdoc should be linked in the same way as the
507         // rustc compiler it's paired with, so it must be built with the previous stage compiler.
508         let build_compiler = builder.compiler(target_compiler.stage - 1, builder.config.build);
509
510         // The presence of `target_compiler` ensures that the necessary libraries (codegen backends,
511         // compiler libraries, ...) are built. Rustdoc does not require the presence of any
512         // libraries within sysroot_libdir (i.e., rustlib), though doctests may want it (since
513         // they'll be linked to those libraries). As such, don't explicitly `ensure` any additional
514         // libraries here. The intuition here is that If we've built a compiler, we should be able
515         // to build rustdoc.
516
517         let cargo = prepare_tool_cargo(
518             builder,
519             build_compiler,
520             Mode::ToolRustc,
521             target,
522             "build",
523             "src/tools/rustdoc",
524             SourceType::InTree,
525             &[],
526         );
527
528         builder.info(&format!("Building rustdoc for stage{} ({})",
529             target_compiler.stage, target_compiler.host));
530         builder.run(&mut cargo.into());
531
532         // Cargo adds a number of paths to the dylib search path on windows, which results in
533         // the wrong rustdoc being executed. To avoid the conflicting rustdocs, we name the "tool"
534         // rustdoc a different name.
535         let tool_rustdoc = builder.cargo_out(build_compiler, Mode::ToolRustc, target)
536             .join(exe("rustdoc_tool_binary", &target_compiler.host));
537
538         // don't create a stage0-sysroot/bin directory.
539         if target_compiler.stage > 0 {
540             let sysroot = builder.sysroot(target_compiler);
541             let bindir = sysroot.join("bin");
542             t!(fs::create_dir_all(&bindir));
543             let bin_rustdoc = bindir.join(exe("rustdoc", &*target_compiler.host));
544             let _ = fs::remove_file(&bin_rustdoc);
545             builder.copy(&tool_rustdoc, &bin_rustdoc);
546             bin_rustdoc
547         } else {
548             tool_rustdoc
549         }
550     }
551 }
552
553 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
554 pub struct Cargo {
555     pub compiler: Compiler,
556     pub target: Interned<String>,
557 }
558
559 impl Step for Cargo {
560     type Output = PathBuf;
561     const DEFAULT: bool = true;
562     const ONLY_HOSTS: bool = true;
563
564     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
565         let builder = run.builder;
566         run.path("src/tools/cargo").default_condition(builder.config.extended)
567     }
568
569     fn make_run(run: RunConfig<'_>) {
570         run.builder.ensure(Cargo {
571             compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
572             target: run.target,
573         });
574     }
575
576     fn run(self, builder: &Builder<'_>) -> PathBuf {
577         builder.ensure(ToolBuild {
578             compiler: self.compiler,
579             target: self.target,
580             tool: "cargo",
581             mode: Mode::ToolRustc,
582             path: "src/tools/cargo",
583             is_optional_tool: false,
584             source_type: SourceType::Submodule,
585             extra_features: Vec::new(),
586         }).expect("expected to build -- essential tool")
587     }
588 }
589
590 macro_rules! tool_extended {
591     (($sel:ident, $builder:ident),
592        $($name:ident,
593        $toolstate:ident,
594        $path:expr,
595        $tool_name:expr,
596        $extra_deps:block;)+) => {
597         $(
598             #[derive(Debug, Clone, Hash, PartialEq, Eq)]
599         pub struct $name {
600             pub compiler: Compiler,
601             pub target: Interned<String>,
602             pub extra_features: Vec<String>,
603         }
604
605         impl Step for $name {
606             type Output = Option<PathBuf>;
607             const DEFAULT: bool = true;
608             const ONLY_HOSTS: bool = true;
609
610             fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
611                 let builder = run.builder;
612                 run.path($path).default_condition(builder.config.extended)
613             }
614
615             fn make_run(run: RunConfig<'_>) {
616                 run.builder.ensure($name {
617                     compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
618                     target: run.target,
619                     extra_features: Vec::new(),
620                 });
621             }
622
623             #[allow(unused_mut)]
624             fn run(mut $sel, $builder: &Builder<'_>) -> Option<PathBuf> {
625                 $extra_deps
626                 $builder.ensure(ToolBuild {
627                     compiler: $sel.compiler,
628                     target: $sel.target,
629                     tool: $tool_name,
630                     mode: Mode::ToolRustc,
631                     path: $path,
632                     extra_features: $sel.extra_features,
633                     is_optional_tool: true,
634                     source_type: SourceType::Submodule,
635                 })
636             }
637         }
638         )+
639     }
640 }
641
642 tool_extended!((self, builder),
643     Cargofmt, rustfmt, "src/tools/rustfmt", "cargo-fmt", {};
644     CargoClippy, clippy, "src/tools/clippy", "cargo-clippy", {};
645     Clippy, clippy, "src/tools/clippy", "clippy-driver", {};
646     Miri, miri, "src/tools/miri", "miri", {};
647     CargoMiri, miri, "src/tools/miri", "cargo-miri", {};
648     Rls, rls, "src/tools/rls", "rls", {
649         let clippy = builder.ensure(Clippy {
650             compiler: self.compiler,
651             target: self.target,
652             extra_features: Vec::new(),
653         });
654         if clippy.is_some() {
655             self.extra_features.push("clippy".to_owned());
656         }
657     };
658     Rustfmt, rustfmt, "src/tools/rustfmt", "rustfmt", {};
659 );
660
661 impl<'a> Builder<'a> {
662     /// Gets a `Command` which is ready to run `tool` in `stage` built for
663     /// `host`.
664     pub fn tool_cmd(&self, tool: Tool) -> Command {
665         let mut cmd = Command::new(self.tool_exe(tool));
666         let compiler = self.compiler(0, self.config.build);
667         let host = &compiler.host;
668         // Prepares the `cmd` provided to be able to run the `compiler` provided.
669         //
670         // Notably this munges the dynamic library lookup path to point to the
671         // right location to run `compiler`.
672         let mut lib_paths: Vec<PathBuf> = vec![
673             self.build.rustc_snapshot_libdir(),
674             self.cargo_out(compiler, Mode::ToolBootstrap, *host).join("deps"),
675         ];
676
677         // On MSVC a tool may invoke a C compiler (e.g., compiletest in run-make
678         // mode) and that C compiler may need some extra PATH modification. Do
679         // so here.
680         if compiler.host.contains("msvc") {
681             let curpaths = env::var_os("PATH").unwrap_or_default();
682             let curpaths = env::split_paths(&curpaths).collect::<Vec<_>>();
683             for &(ref k, ref v) in self.cc[&compiler.host].env() {
684                 if k != "PATH" {
685                     continue
686                 }
687                 for path in env::split_paths(v) {
688                     if !curpaths.contains(&path) {
689                         lib_paths.push(path);
690                     }
691                 }
692             }
693         }
694
695         add_lib_path(lib_paths, &mut cmd);
696         cmd
697     }
698 }