1use std::ffi::OsStr;
13use std::path::PathBuf;
14use std::{env, fs};
15
16use crate::core::build_steps::compile::is_lto_stage;
17use crate::core::build_steps::toolstate::ToolState;
18use crate::core::build_steps::{compile, llvm};
19use crate::core::builder;
20use crate::core::builder::{
21 Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step, StepMetadata, cargo_profile_var,
22};
23use crate::core::config::{DebuginfoLevel, RustcLto, TargetSelection};
24use crate::utils::exec::{BootstrapCommand, command};
25use crate::utils::helpers::{add_dylib_path, exe, t};
26use crate::{Compiler, FileType, Kind, Mode};
27
28#[derive(Debug, Clone, Hash, PartialEq, Eq)]
29pub enum SourceType {
30 InTree,
31 Submodule,
32}
33
34#[derive(Debug, Clone, Hash, PartialEq, Eq)]
35pub enum ToolArtifactKind {
36 Binary,
37 Library,
38}
39
40#[derive(Debug, Clone, Hash, PartialEq, Eq)]
41struct ToolBuild {
42 build_compiler: Compiler,
44 target: TargetSelection,
45 tool: &'static str,
46 path: &'static str,
47 mode: Mode,
48 source_type: SourceType,
49 extra_features: Vec<String>,
50 allow_features: &'static str,
52 cargo_args: Vec<String>,
54 artifact_kind: ToolArtifactKind,
56}
57
58#[derive(Clone)]
61pub struct ToolBuildResult {
62 pub tool_path: PathBuf,
64 pub build_compiler: Compiler,
66}
67
68impl Step for ToolBuild {
69 type Output = ToolBuildResult;
70
71 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
72 run.never()
73 }
74
75 fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
80 let target = self.target;
81 let mut tool = self.tool;
82 let path = self.path;
83
84 match self.mode {
85 Mode::ToolRustcPrivate => {
86 if !self.build_compiler.is_forced_compiler() && builder.download_rustc() {
88 builder.std(self.build_compiler, self.build_compiler.host);
89 builder.ensure(compile::Rustc::new(self.build_compiler, target));
90 }
91 }
92 Mode::ToolStd => {
93 if !self.build_compiler.is_forced_compiler() {
95 builder.std(self.build_compiler, target);
96 }
97 }
98 Mode::ToolBootstrap | Mode::ToolTarget => {} _ => panic!("unexpected Mode for tool build"),
100 }
101
102 let mut cargo = prepare_tool_cargo(
103 builder,
104 self.build_compiler,
105 self.mode,
106 target,
107 Kind::Build,
108 path,
109 self.source_type,
110 &self.extra_features,
111 );
112
113 if let Some(ref ccache) = builder.config.ccache
118 && matches!(self.mode, Mode::ToolBootstrap)
119 && !builder.config.incremental
120 {
121 cargo.env("RUSTC_WRAPPER", ccache);
122 }
123
124 if is_lto_stage(&self.build_compiler)
127 && (self.mode == Mode::ToolRustcPrivate || self.path == "src/tools/cargo")
128 {
129 let lto = match builder.config.rust_lto {
130 RustcLto::Off => Some("off"),
131 RustcLto::Thin => Some("thin"),
132 RustcLto::Fat => Some("fat"),
133 RustcLto::ThinLocal => None,
134 };
135 if let Some(lto) = lto {
136 cargo.env(cargo_profile_var("LTO", &builder.config), lto);
137 }
138 }
139
140 if !self.allow_features.is_empty() {
141 cargo.allow_features(self.allow_features);
142 }
143
144 cargo.args(self.cargo_args);
145
146 let _guard =
147 builder.msg(Kind::Build, self.tool, self.mode, self.build_compiler, self.target);
148
149 let build_success = compile::stream_cargo(builder, cargo, vec![], &mut |_| {});
151
152 builder.save_toolstate(
153 tool,
154 if build_success { ToolState::TestFail } else { ToolState::BuildFail },
155 );
156
157 if !build_success {
158 crate::exit!(1);
159 } else {
160 if tool == "tidy" {
164 tool = "rust-tidy";
165 }
166 let tool_path = match self.artifact_kind {
167 ToolArtifactKind::Binary => {
168 copy_link_tool_bin(builder, self.build_compiler, self.target, self.mode, tool)
169 }
170 ToolArtifactKind::Library => builder
171 .cargo_out(self.build_compiler, self.mode, self.target)
172 .join(format!("lib{tool}.rlib")),
173 };
174
175 ToolBuildResult { tool_path, build_compiler: self.build_compiler }
176 }
177 }
178}
179
180#[expect(clippy::too_many_arguments)] pub fn prepare_tool_cargo(
182 builder: &Builder<'_>,
183 compiler: Compiler,
184 mode: Mode,
185 target: TargetSelection,
186 cmd_kind: Kind,
187 path: &str,
188 source_type: SourceType,
189 extra_features: &[String],
190) -> CargoCommand {
191 let mut cargo = builder::Cargo::new(builder, compiler, mode, source_type, target, cmd_kind);
192
193 let path = PathBuf::from(path);
194 let dir = builder.src.join(&path);
195 cargo.arg("--manifest-path").arg(dir.join("Cargo.toml"));
196
197 let mut features = extra_features.to_vec();
198 if builder.build.config.cargo_native_static {
199 if path.ends_with("cargo")
200 || path.ends_with("clippy")
201 || path.ends_with("miri")
202 || path.ends_with("rustfmt")
203 {
204 cargo.env("LIBZ_SYS_STATIC", "1");
205 }
206 if path.ends_with("cargo") {
207 features.push("all-static".to_string());
208 }
209 }
210
211 builder
217 .config
218 .tool
219 .iter()
220 .filter(|(tool_name, _)| path.file_name().and_then(OsStr::to_str) == Some(tool_name))
221 .for_each(|(_, tool)| features.extend(tool.features.clone().unwrap_or_default()));
222
223 cargo.env("SYSROOT", builder.sysroot(compiler));
226
227 cargo.env("LZMA_API_STATIC", "1");
230
231 if env::var_os("JEMALLOC_SYS_WITH_LG_PAGE").is_none() {
234 if target.starts_with("aarch64") {
237 cargo.env("JEMALLOC_SYS_WITH_LG_PAGE", "16");
238 }
239 else if target.starts_with("loongarch") {
241 cargo.env("JEMALLOC_SYS_WITH_LG_PAGE", "14");
242 }
243 }
244
245 cargo.env("CFG_RELEASE", builder.rust_release());
249 cargo.env("CFG_RELEASE_CHANNEL", &builder.config.channel);
250 cargo.env("CFG_VERSION", builder.rust_version());
251 cargo.env("CFG_RELEASE_NUM", &builder.version);
252 cargo.env("DOC_RUST_LANG_ORG_CHANNEL", builder.doc_rust_lang_org_channel());
253
254 if let Some(ref ver_date) = builder.rust_info().commit_date() {
255 cargo.env("CFG_VER_DATE", ver_date);
256 }
257
258 if let Some(ref ver_hash) = builder.rust_info().sha() {
259 cargo.env("CFG_VER_HASH", ver_hash);
260 }
261
262 if let Some(description) = &builder.config.description {
263 cargo.env("CFG_VER_DESCRIPTION", description);
264 }
265
266 let info = builder.config.git_info(builder.config.omit_git_hash, &dir);
267 if let Some(sha) = info.sha() {
268 cargo.env("CFG_COMMIT_HASH", sha);
269 }
270
271 if let Some(sha_short) = info.sha_short() {
272 cargo.env("CFG_SHORT_COMMIT_HASH", sha_short);
273 }
274
275 if let Some(date) = info.commit_date() {
276 cargo.env("CFG_COMMIT_DATE", date);
277 }
278
279 if !features.is_empty() {
280 cargo.arg("--features").arg(features.join(", "));
281 }
282
283 cargo.rustflag("-Zunstable-options");
291
292 if !path.ends_with("cargo") {
309 cargo.env("FORCE_ON_BROKEN_PIPE_KILL", "-Zon-broken-pipe=kill");
314 }
315
316 cargo
317}
318
319pub enum ToolTargetBuildMode {
322 Build(TargetSelection),
325 Dist(Compiler),
329}
330
331pub(crate) fn get_tool_target_compiler(
333 builder: &Builder<'_>,
334 mode: ToolTargetBuildMode,
335) -> Compiler {
336 let (target, build_compiler_stage) = match mode {
337 ToolTargetBuildMode::Build(target) => {
338 assert!(builder.top_stage > 0);
339 (target, builder.top_stage - 1)
341 }
342 ToolTargetBuildMode::Dist(target_compiler) => {
343 assert!(target_compiler.stage > 0);
344 (target_compiler.host, target_compiler.stage - 1)
347 }
348 };
349
350 let compiler = if builder.host_target == target {
351 builder.compiler(build_compiler_stage, builder.host_target)
352 } else {
353 let build_compiler = builder.compiler(build_compiler_stage.max(1), builder.host_target);
356 builder.std(build_compiler, builder.host_target);
358 build_compiler
359 };
360 builder.std(compiler, target);
361 compiler
362}
363
364fn copy_link_tool_bin(
367 builder: &Builder<'_>,
368 build_compiler: Compiler,
369 target: TargetSelection,
370 mode: Mode,
371 name: &str,
372) -> PathBuf {
373 let cargo_out = builder.cargo_out(build_compiler, mode, target).join(exe(name, target));
374 let bin = builder.tools_dir(build_compiler).join(exe(name, target));
375 builder.copy_link(&cargo_out, &bin, FileType::Executable);
376 bin
377}
378
379macro_rules! bootstrap_tool {
380 ($(
381 $name:ident, $path:expr, $tool_name:expr
382 $(,is_external_tool = $external:expr)*
383 $(,allow_features = $allow_features:expr)?
384 $(,submodules = $submodules:expr)?
385 $(,artifact_kind = $artifact_kind:expr)?
386 ;
387 )+) => {
388 #[derive(PartialEq, Eq, Clone)]
389 pub enum Tool {
390 $(
391 $name,
392 )+
393 }
394
395 impl<'a> Builder<'a> {
396 pub fn tool_exe(&self, tool: Tool) -> PathBuf {
400 match tool {
401 $(Tool::$name =>
402 self.ensure($name {
403 compiler: self.compiler(0, self.config.host_target),
404 target: self.config.host_target,
405 }).tool_path,
406 )+
407 }
408 }
409 }
410
411 $(
412 #[derive(Debug, Clone, Hash, PartialEq, Eq)]
413 pub struct $name {
414 pub compiler: Compiler,
415 pub target: TargetSelection,
416 }
417
418 impl Step for $name {
419 type Output = ToolBuildResult;
420
421 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
422 run.path($path)
423 }
424
425 fn make_run(run: RunConfig<'_>) {
426 run.builder.ensure($name {
427 compiler: run.builder.compiler(0, run.builder.config.host_target),
429 target: run.target,
430 });
431 }
432
433 fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
434 $(
435 for submodule in $submodules {
436 builder.require_submodule(submodule, None);
437 }
438 )*
439
440 builder.ensure(ToolBuild {
441 build_compiler: self.compiler,
442 target: self.target,
443 tool: $tool_name,
444 mode: Mode::ToolBootstrap,
445 path: $path,
446 source_type: if false $(|| $external)* {
447 SourceType::Submodule
448 } else {
449 SourceType::InTree
450 },
451 extra_features: vec![],
452 allow_features: {
453 let mut _value = "";
454 $( _value = $allow_features; )?
455 _value
456 },
457 cargo_args: vec![],
458 artifact_kind: if false $(|| $artifact_kind == ToolArtifactKind::Library)* {
459 ToolArtifactKind::Library
460 } else {
461 ToolArtifactKind::Binary
462 }
463 })
464 }
465
466 fn metadata(&self) -> Option<StepMetadata> {
467 Some(
468 StepMetadata::build(stringify!($name), self.target)
469 .built_by(self.compiler)
470 )
471 }
472 }
473 )+
474 }
475}
476
477bootstrap_tool!(
478 Rustbook, "src/tools/rustbook", "rustbook", is_external_tool = true, submodules = SUBMODULES_FOR_RUSTBOOK;
483 UnstableBookGen, "src/tools/unstable-book-gen", "unstable-book-gen";
484 Tidy, "src/tools/tidy", "tidy";
485 Linkchecker, "src/tools/linkchecker", "linkchecker";
486 CargoTest, "src/tools/cargotest", "cargotest";
487 Compiletest, "src/tools/compiletest", "compiletest";
488 RemoteTestClient, "src/tools/remote-test-client", "remote-test-client";
489 RustInstaller, "src/tools/rust-installer", "rust-installer";
490 RustdocTheme, "src/tools/rustdoc-themes", "rustdoc-themes";
491 LintDocs, "src/tools/lint-docs", "lint-docs";
492 JsonDocCk, "src/tools/jsondocck", "jsondocck";
493 JsonDocLint, "src/tools/jsondoclint", "jsondoclint";
494 HtmlChecker, "src/tools/html-checker", "html-checker";
495 BumpStage0, "src/tools/bump-stage0", "bump-stage0";
496 ReplaceVersionPlaceholder, "src/tools/replace-version-placeholder", "replace-version-placeholder";
497 CollectLicenseMetadata, "src/tools/collect-license-metadata", "collect-license-metadata";
498 GenerateCopyright, "src/tools/generate-copyright", "generate-copyright";
499 GenerateWindowsSys, "src/tools/generate-windows-sys", "generate-windows-sys";
500 RustdocGUITest, "src/tools/rustdoc-gui-test", "rustdoc-gui-test";
501 CoverageDump, "src/tools/coverage-dump", "coverage-dump";
502 UnicodeTableGenerator, "src/tools/unicode-table-generator", "unicode-table-generator";
503 FeaturesStatusDump, "src/tools/features-status-dump", "features-status-dump";
504 OptimizedDist, "src/tools/opt-dist", "opt-dist", submodules = &["src/tools/rustc-perf"];
505 RunMakeSupport, "src/tools/run-make-support", "run_make_support", artifact_kind = ToolArtifactKind::Library;
506);
507
508pub static SUBMODULES_FOR_RUSTBOOK: &[&str] = &["src/doc/book", "src/doc/reference"];
511
512#[derive(Debug, Clone, Hash, PartialEq, Eq)]
515pub struct RustcPerf {
516 pub compiler: Compiler,
517 pub target: TargetSelection,
518}
519
520impl Step for RustcPerf {
521 type Output = ToolBuildResult;
523
524 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
525 run.path("src/tools/rustc-perf")
526 }
527
528 fn make_run(run: RunConfig<'_>) {
529 run.builder.ensure(RustcPerf {
530 compiler: run.builder.compiler(0, run.builder.config.host_target),
531 target: run.target,
532 });
533 }
534
535 fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
536 builder.require_submodule("src/tools/rustc-perf", None);
538
539 let tool = ToolBuild {
540 build_compiler: self.compiler,
541 target: self.target,
542 tool: "collector",
543 mode: Mode::ToolBootstrap,
544 path: "src/tools/rustc-perf",
545 source_type: SourceType::Submodule,
546 extra_features: Vec::new(),
547 allow_features: "",
548 cargo_args: vec!["-p".to_string(), "collector".to_string()],
551 artifact_kind: ToolArtifactKind::Binary,
552 };
553 let res = builder.ensure(tool.clone());
554 copy_link_tool_bin(builder, tool.build_compiler, tool.target, tool.mode, "rustc-fake");
557
558 res
559 }
560}
561
562#[derive(Debug, Clone, Hash, PartialEq, Eq)]
563pub struct ErrorIndex {
564 compilers: RustcPrivateCompilers,
565}
566
567impl ErrorIndex {
568 pub fn command(builder: &Builder<'_>, compilers: RustcPrivateCompilers) -> BootstrapCommand {
569 let mut cmd = command(builder.ensure(ErrorIndex { compilers }).tool_path);
572
573 let target_compiler = compilers.target_compiler();
574 let mut dylib_paths = builder.rustc_lib_paths(target_compiler);
575 dylib_paths.push(builder.sysroot_target_libdir(target_compiler, target_compiler.host));
576 add_dylib_path(dylib_paths, &mut cmd);
577 cmd
578 }
579}
580
581impl Step for ErrorIndex {
582 type Output = ToolBuildResult;
583
584 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
585 run.path("src/tools/error_index_generator")
586 }
587
588 fn make_run(run: RunConfig<'_>) {
589 run.builder.ensure(ErrorIndex {
595 compilers: RustcPrivateCompilers::new(
596 run.builder,
597 run.builder.top_stage,
598 run.builder.host_target,
599 ),
600 });
601 }
602
603 fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
604 builder.ensure(ToolBuild {
605 build_compiler: self.compilers.build_compiler,
606 target: self.compilers.target(),
607 tool: "error_index_generator",
608 mode: Mode::ToolRustcPrivate,
609 path: "src/tools/error_index_generator",
610 source_type: SourceType::InTree,
611 extra_features: Vec::new(),
612 allow_features: "",
613 cargo_args: Vec::new(),
614 artifact_kind: ToolArtifactKind::Binary,
615 })
616 }
617
618 fn metadata(&self) -> Option<StepMetadata> {
619 Some(
620 StepMetadata::build("error-index", self.compilers.target())
621 .built_by(self.compilers.build_compiler),
622 )
623 }
624}
625
626#[derive(Debug, Clone, Hash, PartialEq, Eq)]
627pub struct RemoteTestServer {
628 pub build_compiler: Compiler,
629 pub target: TargetSelection,
630}
631
632impl Step for RemoteTestServer {
633 type Output = ToolBuildResult;
634
635 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
636 run.path("src/tools/remote-test-server")
637 }
638
639 fn make_run(run: RunConfig<'_>) {
640 run.builder.ensure(RemoteTestServer {
641 build_compiler: get_tool_target_compiler(
642 run.builder,
643 ToolTargetBuildMode::Build(run.target),
644 ),
645 target: run.target,
646 });
647 }
648
649 fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
650 builder.ensure(ToolBuild {
651 build_compiler: self.build_compiler,
652 target: self.target,
653 tool: "remote-test-server",
654 mode: Mode::ToolTarget,
655 path: "src/tools/remote-test-server",
656 source_type: SourceType::InTree,
657 extra_features: Vec::new(),
658 allow_features: "",
659 cargo_args: Vec::new(),
660 artifact_kind: ToolArtifactKind::Binary,
661 })
662 }
663
664 fn metadata(&self) -> Option<StepMetadata> {
665 Some(StepMetadata::build("remote-test-server", self.target).built_by(self.build_compiler))
666 }
667}
668
669#[derive(Debug, Clone, Hash, PartialEq, Eq)]
674pub struct Rustdoc {
675 pub target_compiler: Compiler,
678}
679
680impl Step for Rustdoc {
681 type Output = PathBuf;
683
684 const DEFAULT: bool = true;
685 const IS_HOST: bool = true;
686
687 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
688 run.path("src/tools/rustdoc").path("src/librustdoc")
689 }
690
691 fn make_run(run: RunConfig<'_>) {
692 run.builder.ensure(Rustdoc {
693 target_compiler: run.builder.compiler(run.builder.top_stage, run.target),
694 });
695 }
696
697 fn run(self, builder: &Builder<'_>) -> Self::Output {
698 let target_compiler = self.target_compiler;
699 let target = target_compiler.host;
700
701 if target_compiler.stage == 0 {
703 if !target_compiler.is_snapshot(builder) {
704 panic!("rustdoc in stage 0 must be snapshot rustdoc");
705 }
706
707 return builder.initial_rustdoc.clone();
708 }
709
710 let bin_rustdoc = || {
712 let sysroot = builder.sysroot(target_compiler);
713 let bindir = sysroot.join("bin");
714 t!(fs::create_dir_all(&bindir));
715 let bin_rustdoc = bindir.join(exe("rustdoc", target_compiler.host));
716 let _ = fs::remove_file(&bin_rustdoc);
717 bin_rustdoc
718 };
719
720 if builder.download_rustc() && builder.rust_info().is_managed_git_subrepository() {
723 let files_to_track = &["src/librustdoc", "src/tools/rustdoc", "src/rustdoc-json-types"];
724
725 if !builder.config.has_changes_from_upstream(files_to_track) {
727 let precompiled_rustdoc = builder
728 .config
729 .ci_rustc_dir()
730 .join("bin")
731 .join(exe("rustdoc", target_compiler.host));
732
733 let bin_rustdoc = bin_rustdoc();
734 builder.copy_link(&precompiled_rustdoc, &bin_rustdoc, FileType::Executable);
735 return bin_rustdoc;
736 }
737 }
738
739 let mut extra_features = Vec::new();
747 if builder.config.jemalloc(target) {
748 extra_features.push("jemalloc".to_string());
749 }
750
751 let compilers = RustcPrivateCompilers::from_target_compiler(builder, target_compiler);
752 let tool_path = builder
753 .ensure(ToolBuild {
754 build_compiler: compilers.build_compiler,
755 target,
756 tool: "rustdoc_tool_binary",
760 mode: Mode::ToolRustcPrivate,
761 path: "src/tools/rustdoc",
762 source_type: SourceType::InTree,
763 extra_features,
764 allow_features: "",
765 cargo_args: Vec::new(),
766 artifact_kind: ToolArtifactKind::Binary,
767 })
768 .tool_path;
769
770 if builder.config.rust_debuginfo_level_tools == DebuginfoLevel::None {
771 compile::strip_debug(builder, target, &tool_path);
774 }
775 let bin_rustdoc = bin_rustdoc();
776 builder.copy_link(&tool_path, &bin_rustdoc, FileType::Executable);
777 bin_rustdoc
778 }
779
780 fn metadata(&self) -> Option<StepMetadata> {
781 Some(
782 StepMetadata::build("rustdoc", self.target_compiler.host)
783 .stage(self.target_compiler.stage),
784 )
785 }
786}
787
788#[derive(Debug, Clone, Hash, PartialEq, Eq)]
791pub struct Cargo {
792 build_compiler: Compiler,
793 target: TargetSelection,
794}
795
796impl Cargo {
797 pub fn from_build_compiler(build_compiler: Compiler, target: TargetSelection) -> Self {
800 Self { build_compiler, target }
801 }
802}
803
804impl Step for Cargo {
805 type Output = ToolBuildResult;
806 const DEFAULT: bool = true;
807 const IS_HOST: bool = true;
808
809 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
810 let builder = run.builder;
811 run.path("src/tools/cargo").default_condition(builder.tool_enabled("cargo"))
812 }
813
814 fn make_run(run: RunConfig<'_>) {
815 run.builder.ensure(Cargo {
816 build_compiler: get_tool_target_compiler(
817 run.builder,
818 ToolTargetBuildMode::Build(run.target),
819 ),
820 target: run.target,
821 });
822 }
823
824 fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
825 builder.build.require_submodule("src/tools/cargo", None);
826
827 builder.std(self.build_compiler, builder.host_target);
828 builder.std(self.build_compiler, self.target);
829
830 builder.ensure(ToolBuild {
831 build_compiler: self.build_compiler,
832 target: self.target,
833 tool: "cargo",
834 mode: Mode::ToolTarget,
835 path: "src/tools/cargo",
836 source_type: SourceType::Submodule,
837 extra_features: Vec::new(),
838 allow_features: "min_specialization,specialization",
843 cargo_args: Vec::new(),
844 artifact_kind: ToolArtifactKind::Binary,
845 })
846 }
847
848 fn metadata(&self) -> Option<StepMetadata> {
849 Some(StepMetadata::build("cargo", self.target).built_by(self.build_compiler))
850 }
851}
852
853#[derive(Clone)]
856pub struct BuiltLldWrapper {
857 tool: ToolBuildResult,
858 lld_dir: PathBuf,
859}
860
861#[derive(Debug, Clone, Hash, PartialEq, Eq)]
862pub struct LldWrapper {
863 pub build_compiler: Compiler,
864 pub target: TargetSelection,
865}
866
867impl LldWrapper {
868 pub fn for_use_by_compiler(builder: &Builder<'_>, target_compiler: Compiler) -> Self {
870 Self {
871 build_compiler: get_tool_target_compiler(
872 builder,
873 ToolTargetBuildMode::Dist(target_compiler),
874 ),
875 target: target_compiler.host,
876 }
877 }
878}
879
880impl Step for LldWrapper {
881 type Output = BuiltLldWrapper;
882
883 const IS_HOST: bool = true;
884
885 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
886 run.path("src/tools/lld-wrapper")
887 }
888
889 fn make_run(run: RunConfig<'_>) {
890 run.builder.ensure(LldWrapper {
891 build_compiler: get_tool_target_compiler(
892 run.builder,
893 ToolTargetBuildMode::Build(run.target),
894 ),
895 target: run.target,
896 });
897 }
898
899 fn run(self, builder: &Builder<'_>) -> Self::Output {
900 let lld_dir = builder.ensure(llvm::Lld { target: self.target });
901 let tool = builder.ensure(ToolBuild {
902 build_compiler: self.build_compiler,
903 target: self.target,
904 tool: "lld-wrapper",
905 mode: Mode::ToolTarget,
906 path: "src/tools/lld-wrapper",
907 source_type: SourceType::InTree,
908 extra_features: Vec::new(),
909 allow_features: "",
910 cargo_args: Vec::new(),
911 artifact_kind: ToolArtifactKind::Binary,
912 });
913 BuiltLldWrapper { tool, lld_dir }
914 }
915
916 fn metadata(&self) -> Option<StepMetadata> {
917 Some(StepMetadata::build("LldWrapper", self.target).built_by(self.build_compiler))
918 }
919}
920
921pub(crate) fn copy_lld_artifacts(
922 builder: &Builder<'_>,
923 lld_wrapper: BuiltLldWrapper,
924 target_compiler: Compiler,
925) {
926 let target = target_compiler.host;
927
928 let libdir_bin = builder.sysroot_target_bindir(target_compiler, target);
929 t!(fs::create_dir_all(&libdir_bin));
930
931 let src_exe = exe("lld", target);
932 let dst_exe = exe("rust-lld", target);
933
934 builder.copy_link(
935 &lld_wrapper.lld_dir.join("bin").join(src_exe),
936 &libdir_bin.join(dst_exe),
937 FileType::Executable,
938 );
939 let self_contained_lld_dir = libdir_bin.join("gcc-ld");
940 t!(fs::create_dir_all(&self_contained_lld_dir));
941
942 for name in crate::LLD_FILE_NAMES {
943 builder.copy_link(
944 &lld_wrapper.tool.tool_path,
945 &self_contained_lld_dir.join(exe(name, target)),
946 FileType::Executable,
947 );
948 }
949}
950
951#[derive(Debug, Clone, Hash, PartialEq, Eq)]
954pub struct WasmComponentLd {
955 build_compiler: Compiler,
956 target: TargetSelection,
957}
958
959impl WasmComponentLd {
960 pub fn for_use_by_compiler(builder: &Builder<'_>, target_compiler: Compiler) -> Self {
962 Self {
963 build_compiler: get_tool_target_compiler(
964 builder,
965 ToolTargetBuildMode::Dist(target_compiler),
966 ),
967 target: target_compiler.host,
968 }
969 }
970}
971
972impl Step for WasmComponentLd {
973 type Output = ToolBuildResult;
974
975 const IS_HOST: bool = true;
976
977 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
978 run.path("src/tools/wasm-component-ld")
979 }
980
981 fn make_run(run: RunConfig<'_>) {
982 run.builder.ensure(WasmComponentLd {
983 build_compiler: get_tool_target_compiler(
984 run.builder,
985 ToolTargetBuildMode::Build(run.target),
986 ),
987 target: run.target,
988 });
989 }
990
991 fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
992 builder.ensure(ToolBuild {
993 build_compiler: self.build_compiler,
994 target: self.target,
995 tool: "wasm-component-ld",
996 mode: Mode::ToolTarget,
997 path: "src/tools/wasm-component-ld",
998 source_type: SourceType::InTree,
999 extra_features: vec![],
1000 allow_features: "",
1001 cargo_args: vec![],
1002 artifact_kind: ToolArtifactKind::Binary,
1003 })
1004 }
1005
1006 fn metadata(&self) -> Option<StepMetadata> {
1007 Some(StepMetadata::build("WasmComponentLd", self.target).built_by(self.build_compiler))
1008 }
1009}
1010
1011#[derive(Debug, Clone, Hash, PartialEq, Eq)]
1012pub struct RustAnalyzer {
1013 compilers: RustcPrivateCompilers,
1014}
1015
1016impl RustAnalyzer {
1017 pub fn from_compilers(compilers: RustcPrivateCompilers) -> Self {
1018 Self { compilers }
1019 }
1020}
1021
1022impl RustAnalyzer {
1023 pub const ALLOW_FEATURES: &'static str = "rustc_private,proc_macro_internals,proc_macro_diagnostic,proc_macro_span,proc_macro_span_shrink,proc_macro_def_site,new_zeroed_alloc";
1024}
1025
1026impl Step for RustAnalyzer {
1027 type Output = ToolBuildResult;
1028 const DEFAULT: bool = true;
1029 const IS_HOST: bool = true;
1030
1031 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1032 let builder = run.builder;
1033 run.path("src/tools/rust-analyzer").default_condition(builder.tool_enabled("rust-analyzer"))
1034 }
1035
1036 fn make_run(run: RunConfig<'_>) {
1037 run.builder.ensure(RustAnalyzer {
1038 compilers: RustcPrivateCompilers::new(run.builder, run.builder.top_stage, run.target),
1039 });
1040 }
1041
1042 fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
1043 let build_compiler = self.compilers.build_compiler;
1044 let target = self.compilers.target();
1045 builder.ensure(ToolBuild {
1046 build_compiler,
1047 target,
1048 tool: "rust-analyzer",
1049 mode: Mode::ToolRustcPrivate,
1050 path: "src/tools/rust-analyzer",
1051 extra_features: vec!["in-rust-tree".to_owned()],
1052 source_type: SourceType::InTree,
1053 allow_features: RustAnalyzer::ALLOW_FEATURES,
1054 cargo_args: Vec::new(),
1055 artifact_kind: ToolArtifactKind::Binary,
1056 })
1057 }
1058
1059 fn metadata(&self) -> Option<StepMetadata> {
1060 Some(
1061 StepMetadata::build("rust-analyzer", self.compilers.target())
1062 .built_by(self.compilers.build_compiler),
1063 )
1064 }
1065}
1066
1067#[derive(Debug, Clone, Hash, PartialEq, Eq)]
1068pub struct RustAnalyzerProcMacroSrv {
1069 compilers: RustcPrivateCompilers,
1070}
1071
1072impl RustAnalyzerProcMacroSrv {
1073 pub fn from_compilers(compilers: RustcPrivateCompilers) -> Self {
1074 Self { compilers }
1075 }
1076}
1077
1078impl Step for RustAnalyzerProcMacroSrv {
1079 type Output = ToolBuildResult;
1080
1081 const DEFAULT: bool = true;
1082 const IS_HOST: bool = true;
1083
1084 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1085 let builder = run.builder;
1086 run.path("src/tools/rust-analyzer")
1088 .path("src/tools/rust-analyzer/crates/proc-macro-srv-cli")
1089 .default_condition(
1090 builder.tool_enabled("rust-analyzer")
1091 || builder.tool_enabled("rust-analyzer-proc-macro-srv"),
1092 )
1093 }
1094
1095 fn make_run(run: RunConfig<'_>) {
1096 run.builder.ensure(RustAnalyzerProcMacroSrv {
1097 compilers: RustcPrivateCompilers::new(run.builder, run.builder.top_stage, run.target),
1098 });
1099 }
1100
1101 fn run(self, builder: &Builder<'_>) -> Self::Output {
1102 let tool_result = builder.ensure(ToolBuild {
1103 build_compiler: self.compilers.build_compiler,
1104 target: self.compilers.target(),
1105 tool: "rust-analyzer-proc-macro-srv",
1106 mode: Mode::ToolRustcPrivate,
1107 path: "src/tools/rust-analyzer/crates/proc-macro-srv-cli",
1108 extra_features: vec!["in-rust-tree".to_owned()],
1109 source_type: SourceType::InTree,
1110 allow_features: RustAnalyzer::ALLOW_FEATURES,
1111 cargo_args: Vec::new(),
1112 artifact_kind: ToolArtifactKind::Binary,
1113 });
1114
1115 let libexec_path = builder.sysroot(self.compilers.target_compiler).join("libexec");
1118 t!(fs::create_dir_all(&libexec_path));
1119 builder.copy_link(
1120 &tool_result.tool_path,
1121 &libexec_path.join("rust-analyzer-proc-macro-srv"),
1122 FileType::Executable,
1123 );
1124
1125 tool_result
1126 }
1127
1128 fn metadata(&self) -> Option<StepMetadata> {
1129 Some(
1130 StepMetadata::build("rust-analyzer-proc-macro-srv", self.compilers.target())
1131 .built_by(self.compilers.build_compiler),
1132 )
1133 }
1134}
1135
1136#[derive(Debug, Clone, Hash, PartialEq, Eq)]
1137pub struct LlvmBitcodeLinker {
1138 build_compiler: Compiler,
1139 target: TargetSelection,
1140}
1141
1142impl LlvmBitcodeLinker {
1143 pub fn from_build_compiler(build_compiler: Compiler, target: TargetSelection) -> Self {
1146 Self { build_compiler, target }
1147 }
1148
1149 pub fn from_target_compiler(builder: &Builder<'_>, target_compiler: Compiler) -> Self {
1151 Self {
1152 build_compiler: get_tool_target_compiler(
1153 builder,
1154 ToolTargetBuildMode::Dist(target_compiler),
1155 ),
1156 target: target_compiler.host,
1157 }
1158 }
1159
1160 pub fn get_build_compiler_for_target(
1162 builder: &Builder<'_>,
1163 target: TargetSelection,
1164 ) -> Compiler {
1165 get_tool_target_compiler(builder, ToolTargetBuildMode::Build(target))
1166 }
1167}
1168
1169impl Step for LlvmBitcodeLinker {
1170 type Output = ToolBuildResult;
1171 const DEFAULT: bool = true;
1172 const IS_HOST: bool = true;
1173
1174 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1175 let builder = run.builder;
1176 run.path("src/tools/llvm-bitcode-linker")
1177 .default_condition(builder.tool_enabled("llvm-bitcode-linker"))
1178 }
1179
1180 fn make_run(run: RunConfig<'_>) {
1181 run.builder.ensure(LlvmBitcodeLinker {
1182 build_compiler: Self::get_build_compiler_for_target(run.builder, run.target),
1183 target: run.target,
1184 });
1185 }
1186
1187 fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
1188 builder.ensure(ToolBuild {
1189 build_compiler: self.build_compiler,
1190 target: self.target,
1191 tool: "llvm-bitcode-linker",
1192 mode: Mode::ToolTarget,
1193 path: "src/tools/llvm-bitcode-linker",
1194 source_type: SourceType::InTree,
1195 extra_features: vec![],
1196 allow_features: "",
1197 cargo_args: Vec::new(),
1198 artifact_kind: ToolArtifactKind::Binary,
1199 })
1200 }
1201
1202 fn metadata(&self) -> Option<StepMetadata> {
1203 Some(StepMetadata::build("LlvmBitcodeLinker", self.target).built_by(self.build_compiler))
1204 }
1205}
1206
1207#[derive(Debug, Clone, Hash, PartialEq, Eq)]
1208pub struct LibcxxVersionTool {
1209 pub target: TargetSelection,
1210}
1211
1212#[expect(dead_code)]
1213#[derive(Debug, Clone)]
1214pub enum LibcxxVersion {
1215 Gnu(usize),
1216 Llvm(usize),
1217}
1218
1219impl Step for LibcxxVersionTool {
1220 type Output = LibcxxVersion;
1221 const DEFAULT: bool = false;
1222 const IS_HOST: bool = true;
1223
1224 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1225 run.never()
1226 }
1227
1228 fn run(self, builder: &Builder<'_>) -> LibcxxVersion {
1229 let out_dir = builder.out.join(self.target.to_string()).join("libcxx-version");
1230 let executable = out_dir.join(exe("libcxx-version", self.target));
1231
1232 if !executable.exists() {
1237 if !out_dir.exists() {
1238 t!(fs::create_dir_all(&out_dir));
1239 }
1240
1241 let compiler = builder.cxx(self.target).unwrap();
1242 let mut cmd = command(compiler);
1243
1244 cmd.arg("-o")
1245 .arg(&executable)
1246 .arg(builder.src.join("src/tools/libcxx-version/main.cpp"));
1247
1248 cmd.run(builder);
1249
1250 if !executable.exists() {
1251 panic!("Something went wrong. {} is not present", executable.display());
1252 }
1253 }
1254
1255 let version_output = command(executable).run_capture_stdout(builder).stdout();
1256
1257 let version_str = version_output.split_once("version:").unwrap().1;
1258 let version = version_str.trim().parse::<usize>().unwrap();
1259
1260 if version_output.starts_with("libstdc++") {
1261 LibcxxVersion::Gnu(version)
1262 } else if version_output.starts_with("libc++") {
1263 LibcxxVersion::Llvm(version)
1264 } else {
1265 panic!("Coudln't recognize the standard library version.");
1266 }
1267 }
1268}
1269
1270#[derive(Debug, Clone, Hash, PartialEq, Eq)]
1271pub struct BuildManifest {
1272 compiler: Compiler,
1273 target: TargetSelection,
1274}
1275
1276impl BuildManifest {
1277 pub fn new(builder: &Builder<'_>, target: TargetSelection) -> Self {
1278 BuildManifest { compiler: builder.compiler(1, builder.config.host_target), target }
1279 }
1280}
1281
1282impl Step for BuildManifest {
1283 type Output = ToolBuildResult;
1284
1285 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1286 run.path("src/tools/build-manifest")
1287 }
1288
1289 fn make_run(run: RunConfig<'_>) {
1290 run.builder.ensure(BuildManifest::new(run.builder, run.target));
1291 }
1292
1293 fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
1294 assert!(self.compiler.stage != 0);
1297 builder.ensure(ToolBuild {
1298 build_compiler: self.compiler,
1299 target: self.target,
1300 tool: "build-manifest",
1301 mode: Mode::ToolStd,
1302 path: "src/tools/build-manifest",
1303 source_type: SourceType::InTree,
1304 extra_features: vec![],
1305 allow_features: "",
1306 cargo_args: vec![],
1307 artifact_kind: ToolArtifactKind::Binary,
1308 })
1309 }
1310
1311 fn metadata(&self) -> Option<StepMetadata> {
1312 Some(StepMetadata::build("build-manifest", self.target).built_by(self.compiler))
1313 }
1314}
1315
1316#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
1328pub struct RustcPrivateCompilers {
1329 build_compiler: Compiler,
1331 target_compiler: Compiler,
1334}
1335
1336impl RustcPrivateCompilers {
1337 pub fn new(builder: &Builder<'_>, stage: u32, target: TargetSelection) -> Self {
1340 let build_compiler = Self::build_compiler_from_stage(builder, stage);
1341
1342 let target_compiler = builder.compiler(build_compiler.stage + 1, target);
1345
1346 Self { build_compiler, target_compiler }
1347 }
1348
1349 pub fn from_build_and_target_compiler(
1350 build_compiler: Compiler,
1351 target_compiler: Compiler,
1352 ) -> Self {
1353 Self { build_compiler, target_compiler }
1354 }
1355
1356 pub fn from_build_compiler(
1358 builder: &Builder<'_>,
1359 build_compiler: Compiler,
1360 target: TargetSelection,
1361 ) -> Self {
1362 let target_compiler = builder.compiler(build_compiler.stage + 1, target);
1363 Self { build_compiler, target_compiler }
1364 }
1365
1366 pub fn from_target_compiler(builder: &Builder<'_>, target_compiler: Compiler) -> Self {
1368 Self {
1369 build_compiler: Self::build_compiler_from_stage(builder, target_compiler.stage),
1370 target_compiler,
1371 }
1372 }
1373
1374 fn build_compiler_from_stage(builder: &Builder<'_>, stage: u32) -> Compiler {
1375 assert!(stage > 0);
1376
1377 if builder.download_rustc() && stage == 1 {
1378 builder.compiler(1, builder.config.host_target)
1380 } else {
1381 builder.compiler(stage - 1, builder.config.host_target)
1382 }
1383 }
1384
1385 pub fn build_compiler(&self) -> Compiler {
1386 self.build_compiler
1387 }
1388
1389 pub fn target_compiler(&self) -> Compiler {
1390 self.target_compiler
1391 }
1392
1393 pub fn target(&self) -> TargetSelection {
1395 self.target_compiler.host
1396 }
1397}
1398
1399macro_rules! tool_rustc_extended {
1402 (
1403 $name:ident {
1404 path: $path:expr,
1405 tool_name: $tool_name:expr,
1406 stable: $stable:expr
1407 $( , add_bins_to_sysroot: $add_bins_to_sysroot:expr )?
1408 $( , add_features: $add_features:expr )?
1409 $( , cargo_args: $cargo_args:expr )?
1410 $( , )?
1411 }
1412 ) => {
1413 #[derive(Debug, Clone, Hash, PartialEq, Eq)]
1414 pub struct $name {
1415 compilers: RustcPrivateCompilers,
1416 }
1417
1418 impl $name {
1419 pub fn from_compilers(compilers: RustcPrivateCompilers) -> Self {
1420 Self {
1421 compilers,
1422 }
1423 }
1424 }
1425
1426 impl Step for $name {
1427 type Output = ToolBuildResult;
1428 const DEFAULT: bool = true; const IS_HOST: bool = true;
1430
1431 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1432 should_run_extended_rustc_tool(
1433 run,
1434 $tool_name,
1435 $path,
1436 $stable,
1437 )
1438 }
1439
1440 fn make_run(run: RunConfig<'_>) {
1441 run.builder.ensure($name {
1442 compilers: RustcPrivateCompilers::new(run.builder, run.builder.top_stage, run.target),
1443 });
1444 }
1445
1446 fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
1447 let Self { compilers } = self;
1448 build_extended_rustc_tool(
1449 builder,
1450 compilers,
1451 $tool_name,
1452 $path,
1453 None $( .or(Some(&$add_bins_to_sysroot)) )?,
1454 None $( .or(Some($add_features)) )?,
1455 None $( .or(Some($cargo_args)) )?,
1456 )
1457 }
1458
1459 fn metadata(&self) -> Option<StepMetadata> {
1460 Some(
1461 StepMetadata::build($tool_name, self.compilers.target())
1462 .built_by(self.compilers.build_compiler)
1463 )
1464 }
1465 }
1466 }
1467}
1468
1469fn should_run_extended_rustc_tool<'a>(
1470 run: ShouldRun<'a>,
1471 tool_name: &'static str,
1472 path: &'static str,
1473 stable: bool,
1474) -> ShouldRun<'a> {
1475 let builder = run.builder;
1476 run.path(path).default_condition(
1477 builder.config.extended
1478 && builder.config.tools.as_ref().map_or(
1479 stable || builder.build.unstable_features(),
1482 |tools| {
1484 tools.iter().any(|tool| match tool.as_ref() {
1485 "clippy" => tool_name == "clippy-driver",
1486 x => tool_name == x,
1487 })
1488 },
1489 ),
1490 )
1491}
1492
1493fn build_extended_rustc_tool(
1494 builder: &Builder<'_>,
1495 compilers: RustcPrivateCompilers,
1496 tool_name: &'static str,
1497 path: &'static str,
1498 add_bins_to_sysroot: Option<&[&str]>,
1499 add_features: Option<fn(&Builder<'_>, TargetSelection, &mut Vec<String>)>,
1500 cargo_args: Option<&[&'static str]>,
1501) -> ToolBuildResult {
1502 let target = compilers.target();
1503 let mut extra_features = Vec::new();
1504 if let Some(func) = add_features {
1505 func(builder, target, &mut extra_features);
1506 }
1507
1508 let build_compiler = compilers.build_compiler;
1509 let ToolBuildResult { tool_path, .. } = builder.ensure(ToolBuild {
1510 build_compiler,
1511 target,
1512 tool: tool_name,
1513 mode: Mode::ToolRustcPrivate,
1514 path,
1515 extra_features,
1516 source_type: SourceType::InTree,
1517 allow_features: "",
1518 cargo_args: cargo_args.unwrap_or_default().iter().map(|s| String::from(*s)).collect(),
1519 artifact_kind: ToolArtifactKind::Binary,
1520 });
1521
1522 let target_compiler = compilers.target_compiler;
1523 if let Some(add_bins_to_sysroot) = add_bins_to_sysroot
1524 && !add_bins_to_sysroot.is_empty()
1525 {
1526 let bindir = builder.sysroot(target_compiler).join("bin");
1527 t!(fs::create_dir_all(&bindir));
1528
1529 for add_bin in add_bins_to_sysroot {
1530 let bin_destination = bindir.join(exe(add_bin, target_compiler.host));
1531 builder.copy_link(&tool_path, &bin_destination, FileType::Executable);
1532 }
1533
1534 let path = bindir.join(exe(tool_name, target_compiler.host));
1536 ToolBuildResult { tool_path: path, build_compiler }
1537 } else {
1538 ToolBuildResult { tool_path, build_compiler }
1539 }
1540}
1541
1542tool_rustc_extended!(Cargofmt {
1543 path: "src/tools/rustfmt",
1544 tool_name: "cargo-fmt",
1545 stable: true,
1546 add_bins_to_sysroot: ["cargo-fmt"]
1547});
1548tool_rustc_extended!(CargoClippy {
1549 path: "src/tools/clippy",
1550 tool_name: "cargo-clippy",
1551 stable: true,
1552 add_bins_to_sysroot: ["cargo-clippy"]
1553});
1554tool_rustc_extended!(Clippy {
1555 path: "src/tools/clippy",
1556 tool_name: "clippy-driver",
1557 stable: true,
1558 add_bins_to_sysroot: ["clippy-driver"],
1559 add_features: |builder, target, features| {
1560 if builder.config.jemalloc(target) {
1561 features.push("jemalloc".to_string());
1562 }
1563 }
1564});
1565tool_rustc_extended!(Miri {
1566 path: "src/tools/miri",
1567 tool_name: "miri",
1568 stable: false,
1569 add_bins_to_sysroot: ["miri"],
1570 add_features: |builder, target, features| {
1571 if builder.config.jemalloc(target) {
1572 features.push("jemalloc".to_string());
1573 }
1574 },
1575 cargo_args: &["--all-targets"],
1577});
1578tool_rustc_extended!(CargoMiri {
1579 path: "src/tools/miri/cargo-miri",
1580 tool_name: "cargo-miri",
1581 stable: false,
1582 add_bins_to_sysroot: ["cargo-miri"]
1583});
1584tool_rustc_extended!(Rustfmt {
1585 path: "src/tools/rustfmt",
1586 tool_name: "rustfmt",
1587 stable: true,
1588 add_bins_to_sysroot: ["rustfmt"]
1589});
1590
1591pub const TEST_FLOAT_PARSE_ALLOW_FEATURES: &str = "f16,cfg_target_has_reliable_f16_f128";
1592
1593impl Builder<'_> {
1594 pub fn tool_cmd(&self, tool: Tool) -> BootstrapCommand {
1599 let mut cmd = command(self.tool_exe(tool));
1600 let compiler = self.compiler(0, self.config.host_target);
1601 let host = &compiler.host;
1602 let mut lib_paths: Vec<PathBuf> =
1607 vec![self.cargo_out(compiler, Mode::ToolBootstrap, *host).join("deps")];
1608
1609 if compiler.host.is_msvc() {
1613 let curpaths = env::var_os("PATH").unwrap_or_default();
1614 let curpaths = env::split_paths(&curpaths).collect::<Vec<_>>();
1615 for (k, v) in self.cc[&compiler.host].env() {
1616 if k != "PATH" {
1617 continue;
1618 }
1619 for path in env::split_paths(v) {
1620 if !curpaths.contains(&path) {
1621 lib_paths.push(path);
1622 }
1623 }
1624 }
1625 }
1626
1627 add_dylib_path(lib_paths, &mut cmd);
1628
1629 cmd.env("RUSTC", &self.initial_rustc);
1631
1632 cmd
1633 }
1634}