Skip to content

Commit 72e67e8

Browse files
committed
return more advanced type from ToolBuild
Signed-off-by: onur-ozkan <[email protected]>
1 parent 7638abb commit 72e67e8

File tree

1 file changed

+125
-98
lines changed
  • src/bootstrap/src/core/build_steps

1 file changed

+125
-98
lines changed

src/bootstrap/src/core/build_steps/tool.rs

+125-98
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,15 @@ impl Builder<'_> {
6464
}
6565
}
6666

67+
#[derive(Clone)]
68+
struct ToolBuildResult {
69+
tool_path: PathBuf,
70+
build_compiler: Compiler,
71+
target_compiler: Compiler,
72+
}
73+
6774
impl Step for ToolBuild {
68-
type Output = PathBuf;
75+
type Output = ToolBuildResult;
6976

7077
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
7178
run.never()
@@ -75,30 +82,31 @@ impl Step for ToolBuild {
7582
///
7683
/// This will build the specified tool with the specified `host` compiler in
7784
/// `stage` into the normal cargo output directory.
78-
fn run(self, builder: &Builder<'_>) -> PathBuf {
85+
fn run(mut self, builder: &Builder<'_>) -> ToolBuildResult {
7986
let target = self.target;
8087
let mut tool = self.tool;
8188
let path = self.path;
8289

83-
let compiler = if self.mode == Mode::ToolRustc {
90+
let target_compiler = self.compiler;
91+
self.compiler = if self.mode == Mode::ToolRustc {
8492
get_tool_rustc_compiler(builder, self.compiler)
8593
} else {
8694
self.compiler
8795
};
8896

8997
match self.mode {
9098
Mode::ToolRustc => {
91-
builder.ensure(compile::Std::new(compiler, compiler.host));
92-
builder.ensure(compile::Rustc::new(compiler, target));
99+
builder.ensure(compile::Std::new(self.compiler, self.compiler.host));
100+
builder.ensure(compile::Rustc::new(self.compiler, target));
93101
}
94-
Mode::ToolStd => builder.ensure(compile::Std::new(compiler, target)),
102+
Mode::ToolStd => builder.ensure(compile::Std::new(self.compiler, target)),
95103
Mode::ToolBootstrap => {} // uses downloaded stage0 compiler libs
96104
_ => panic!("unexpected Mode for tool build"),
97105
}
98106

99107
let mut cargo = prepare_tool_cargo(
100108
builder,
101-
compiler,
109+
self.compiler,
102110
self.mode,
103111
target,
104112
Kind::Build,
@@ -136,7 +144,10 @@ impl Step for ToolBuild {
136144
if tool == "tidy" {
137145
tool = "rust-tidy";
138146
}
139-
copy_link_tool_bin(builder, self.compiler, self.target, self.mode, tool)
147+
let tool_path =
148+
copy_link_tool_bin(builder, target_compiler, self.target, self.mode, tool);
149+
150+
ToolBuildResult { tool_path, build_compiler: self.compiler, target_compiler }
140151
}
141152
}
142153
}
@@ -361,7 +372,7 @@ macro_rules! bootstrap_tool {
361372
extra_features: vec![],
362373
allow_features: concat!($($allow_features)*),
363374
cargo_args: vec![]
364-
})
375+
}).tool_path
365376
}
366377
}
367378
)+
@@ -429,17 +440,19 @@ impl Step for OptimizedDist {
429440
// the tool requires it to be in place to run.
430441
builder.require_submodule("src/tools/rustc-perf", None);
431442

432-
builder.ensure(ToolBuild {
433-
compiler: self.compiler,
434-
target: self.target,
435-
tool: "opt-dist",
436-
mode: Mode::ToolBootstrap,
437-
path: "src/tools/opt-dist",
438-
source_type: SourceType::InTree,
439-
extra_features: Vec::new(),
440-
allow_features: "",
441-
cargo_args: Vec::new(),
442-
})
443+
builder
444+
.ensure(ToolBuild {
445+
compiler: self.compiler,
446+
target: self.target,
447+
tool: "opt-dist",
448+
mode: Mode::ToolBootstrap,
449+
path: "src/tools/opt-dist",
450+
source_type: SourceType::InTree,
451+
extra_features: Vec::new(),
452+
allow_features: "",
453+
cargo_args: Vec::new(),
454+
})
455+
.tool_path
443456
}
444457
}
445458

@@ -483,7 +496,7 @@ impl Step for RustcPerf {
483496
// a CLI.
484497
cargo_args: vec!["-p".to_string(), "collector".to_string()],
485498
};
486-
let collector_bin = builder.ensure(tool.clone());
499+
let collector_bin = builder.ensure(tool.clone()).tool_path;
487500
// We also need to symlink the `rustc-fake` binary to the corresponding directory,
488501
// because `collector` expects it in the same directory.
489502
copy_link_tool_bin(builder, tool.compiler, tool.target, tool.mode, "rustc-fake");
@@ -533,17 +546,19 @@ impl Step for ErrorIndex {
533546
}
534547

535548
fn run(self, builder: &Builder<'_>) -> PathBuf {
536-
builder.ensure(ToolBuild {
537-
compiler: self.compiler,
538-
target: self.compiler.host,
539-
tool: "error_index_generator",
540-
mode: Mode::ToolRustc,
541-
path: "src/tools/error_index_generator",
542-
source_type: SourceType::InTree,
543-
extra_features: Vec::new(),
544-
allow_features: "",
545-
cargo_args: Vec::new(),
546-
})
549+
builder
550+
.ensure(ToolBuild {
551+
compiler: self.compiler,
552+
target: self.compiler.host,
553+
tool: "error_index_generator",
554+
mode: Mode::ToolRustc,
555+
path: "src/tools/error_index_generator",
556+
source_type: SourceType::InTree,
557+
extra_features: Vec::new(),
558+
allow_features: "",
559+
cargo_args: Vec::new(),
560+
})
561+
.tool_path
547562
}
548563
}
549564

@@ -568,17 +583,19 @@ impl Step for RemoteTestServer {
568583
}
569584

570585
fn run(self, builder: &Builder<'_>) -> PathBuf {
571-
builder.ensure(ToolBuild {
572-
compiler: self.compiler,
573-
target: self.target,
574-
tool: "remote-test-server",
575-
mode: Mode::ToolStd,
576-
path: "src/tools/remote-test-server",
577-
source_type: SourceType::InTree,
578-
extra_features: Vec::new(),
579-
allow_features: "",
580-
cargo_args: Vec::new(),
581-
})
586+
builder
587+
.ensure(ToolBuild {
588+
compiler: self.compiler,
589+
target: self.target,
590+
tool: "remote-test-server",
591+
mode: Mode::ToolStd,
592+
path: "src/tools/remote-test-server",
593+
source_type: SourceType::InTree,
594+
extra_features: Vec::new(),
595+
allow_features: "",
596+
cargo_args: Vec::new(),
597+
})
598+
.tool_path
582599
}
583600
}
584601

@@ -754,17 +771,19 @@ impl Step for Cargo {
754771
fn run(self, builder: &Builder<'_>) -> PathBuf {
755772
builder.build.require_submodule("src/tools/cargo", None);
756773

757-
builder.ensure(ToolBuild {
758-
compiler: self.compiler,
759-
target: self.target,
760-
tool: "cargo",
761-
mode: Mode::ToolRustc,
762-
path: "src/tools/cargo",
763-
source_type: SourceType::Submodule,
764-
extra_features: Vec::new(),
765-
allow_features: "",
766-
cargo_args: Vec::new(),
767-
})
774+
builder
775+
.ensure(ToolBuild {
776+
compiler: self.compiler,
777+
target: self.target,
778+
tool: "cargo",
779+
mode: Mode::ToolRustc,
780+
path: "src/tools/cargo",
781+
source_type: SourceType::Submodule,
782+
extra_features: Vec::new(),
783+
allow_features: "",
784+
cargo_args: Vec::new(),
785+
})
786+
.tool_path
768787
}
769788
}
770789

@@ -797,17 +816,19 @@ impl Step for LldWrapper {
797816

798817
let target = self.target_compiler.host;
799818

800-
let executable = builder.ensure(ToolBuild {
801-
compiler: self.build_compiler,
802-
target,
803-
tool: "lld-wrapper",
804-
mode: Mode::ToolStd,
805-
path: "src/tools/lld-wrapper",
806-
source_type: SourceType::InTree,
807-
extra_features: Vec::new(),
808-
allow_features: "",
809-
cargo_args: Vec::new(),
810-
});
819+
let executable = builder
820+
.ensure(ToolBuild {
821+
compiler: self.build_compiler,
822+
target,
823+
tool: "lld-wrapper",
824+
mode: Mode::ToolStd,
825+
path: "src/tools/lld-wrapper",
826+
source_type: SourceType::InTree,
827+
extra_features: Vec::new(),
828+
allow_features: "",
829+
cargo_args: Vec::new(),
830+
})
831+
.tool_path;
811832

812833
let libdir_bin = builder.sysroot_target_bindir(self.target_compiler, target);
813834
t!(fs::create_dir_all(&libdir_bin));
@@ -854,17 +875,19 @@ impl Step for RustAnalyzer {
854875
}
855876

856877
fn run(self, builder: &Builder<'_>) -> PathBuf {
857-
builder.ensure(ToolBuild {
858-
compiler: self.compiler,
859-
target: self.target,
860-
tool: "rust-analyzer",
861-
mode: Mode::ToolRustc,
862-
path: "src/tools/rust-analyzer",
863-
extra_features: vec!["in-rust-tree".to_owned()],
864-
source_type: SourceType::InTree,
865-
allow_features: RustAnalyzer::ALLOW_FEATURES,
866-
cargo_args: Vec::new(),
867-
})
878+
builder
879+
.ensure(ToolBuild {
880+
compiler: self.compiler,
881+
target: self.target,
882+
tool: "rust-analyzer",
883+
mode: Mode::ToolRustc,
884+
path: "src/tools/rust-analyzer",
885+
extra_features: vec!["in-rust-tree".to_owned()],
886+
source_type: SourceType::InTree,
887+
allow_features: RustAnalyzer::ALLOW_FEATURES,
888+
cargo_args: Vec::new(),
889+
})
890+
.tool_path
868891
}
869892
}
870893

@@ -898,17 +921,19 @@ impl Step for RustAnalyzerProcMacroSrv {
898921
}
899922

900923
fn run(self, builder: &Builder<'_>) -> Option<PathBuf> {
901-
let path = builder.ensure(ToolBuild {
902-
compiler: self.compiler,
903-
target: self.target,
904-
tool: "rust-analyzer-proc-macro-srv",
905-
mode: Mode::ToolRustc,
906-
path: "src/tools/rust-analyzer/crates/proc-macro-srv-cli",
907-
extra_features: vec!["in-rust-tree".to_owned()],
908-
source_type: SourceType::InTree,
909-
allow_features: RustAnalyzer::ALLOW_FEATURES,
910-
cargo_args: Vec::new(),
911-
});
924+
let path = builder
925+
.ensure(ToolBuild {
926+
compiler: self.compiler,
927+
target: self.target,
928+
tool: "rust-analyzer-proc-macro-srv",
929+
mode: Mode::ToolRustc,
930+
path: "src/tools/rust-analyzer/crates/proc-macro-srv-cli",
931+
extra_features: vec!["in-rust-tree".to_owned()],
932+
source_type: SourceType::InTree,
933+
allow_features: RustAnalyzer::ALLOW_FEATURES,
934+
cargo_args: Vec::new(),
935+
})
936+
.tool_path;
912937

913938
// Copy `rust-analyzer-proc-macro-srv` to `<sysroot>/libexec/`
914939
// so that r-a can use it.
@@ -1146,17 +1171,19 @@ fn run_tool_build_step(
11461171
path: &'static str,
11471172
add_bins_to_sysroot: Option<&[&str]>,
11481173
) -> PathBuf {
1149-
let tool = builder.ensure(ToolBuild {
1150-
compiler,
1151-
target,
1152-
tool: tool_name,
1153-
mode: Mode::ToolRustc,
1154-
path,
1155-
extra_features: vec![],
1156-
source_type: SourceType::InTree,
1157-
allow_features: "",
1158-
cargo_args: vec![],
1159-
});
1174+
let tool = builder
1175+
.ensure(ToolBuild {
1176+
compiler,
1177+
target,
1178+
tool: tool_name,
1179+
mode: Mode::ToolRustc,
1180+
path,
1181+
extra_features: vec![],
1182+
source_type: SourceType::InTree,
1183+
allow_features: "",
1184+
cargo_args: vec![],
1185+
})
1186+
.tool_path;
11601187

11611188
// FIXME: This should just be an if-let-chain, but those are unstable.
11621189
if let Some(add_bins_to_sysroot) =

0 commit comments

Comments
 (0)