Skip to content

Commit 9ee6d1c

Browse files
committed
Implement RustcPrivateCompilers to unify building of rustc_private tools
1 parent ec8b07c commit 9ee6d1c

File tree

9 files changed

+287
-269
lines changed

9 files changed

+287
-269
lines changed

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,7 @@ impl Step for CodegenBackend {
16371637
let target = self.target;
16381638
let backend = self.backend;
16391639

1640+
// FIXME: migrate to RustcPrivateCompilers
16401641
builder.ensure(Rustc::new(compiler, target));
16411642

16421643
if builder.config.keep_stage.contains(&compiler.stage) {

src/bootstrap/src/core/build_steps/dist.rs

Lines changed: 39 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use object::read::archive::ArchiveFile;
2020
use tracing::instrument;
2121

2222
use crate::core::build_steps::doc::DocumentationFormat;
23-
use crate::core::build_steps::tool::{self, Tool};
23+
use crate::core::build_steps::tool::{self, RustcPrivateCompilers, Tool};
2424
use crate::core::build_steps::vendor::{VENDOR_DIR, Vendor};
2525
use crate::core::build_steps::{compile, llvm};
2626
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step, StepMetadata};
@@ -431,13 +431,14 @@ impl Step for Rustc {
431431

432432
let ra_proc_macro_srv_compiler =
433433
builder.compiler_for(compiler.stage, builder.config.host_target, compiler.host);
434-
builder.ensure(compile::Rustc::new(ra_proc_macro_srv_compiler, compiler.host));
434+
let compilers = RustcPrivateCompilers::from_build_compiler(
435+
builder,
436+
ra_proc_macro_srv_compiler,
437+
compiler.host,
438+
);
435439

436440
if let Some(ra_proc_macro_srv) = builder.ensure_if_default(
437-
tool::RustAnalyzerProcMacroSrv {
438-
compiler: ra_proc_macro_srv_compiler,
439-
target: compiler.host,
440-
},
441+
tool::RustAnalyzerProcMacroSrv::from_compilers(compilers),
441442
builder.kind,
442443
) {
443444
let dst = image.join("libexec");
@@ -1226,7 +1227,7 @@ impl Step for Cargo {
12261227

12271228
#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
12281229
pub struct RustAnalyzer {
1229-
pub compiler: Compiler,
1230+
pub build_compiler: Compiler,
12301231
pub target: TargetSelection,
12311232
}
12321233

@@ -1242,7 +1243,7 @@ impl Step for RustAnalyzer {
12421243

12431244
fn make_run(run: RunConfig<'_>) {
12441245
run.builder.ensure(RustAnalyzer {
1245-
compiler: run.builder.compiler_for(
1246+
build_compiler: run.builder.compiler_for(
12461247
run.builder.top_stage,
12471248
run.builder.config.host_target,
12481249
run.target,
@@ -1252,12 +1253,11 @@ impl Step for RustAnalyzer {
12521253
}
12531254

12541255
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1255-
let compiler = self.compiler;
12561256
let target = self.target;
1257+
let compilers =
1258+
RustcPrivateCompilers::from_build_compiler(builder, self.build_compiler, self.target);
12571259

1258-
builder.ensure(compile::Rustc::new(compiler, target));
1259-
1260-
let rust_analyzer = builder.ensure(tool::RustAnalyzer { compiler, target });
1260+
let rust_analyzer = builder.ensure(tool::RustAnalyzer::from_compilers(compilers));
12611261

12621262
let mut tarball = Tarball::new(builder, "rust-analyzer", &target.triple);
12631263
tarball.set_overlay(OverlayKind::RustAnalyzer);
@@ -1268,9 +1268,9 @@ impl Step for RustAnalyzer {
12681268
}
12691269
}
12701270

1271-
#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
1271+
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
12721272
pub struct Clippy {
1273-
pub compiler: Compiler,
1273+
pub build_compiler: Compiler,
12741274
pub target: TargetSelection,
12751275
}
12761276

@@ -1286,7 +1286,7 @@ impl Step for Clippy {
12861286

12871287
fn make_run(run: RunConfig<'_>) {
12881288
run.builder.ensure(Clippy {
1289-
compiler: run.builder.compiler_for(
1289+
build_compiler: run.builder.compiler_for(
12901290
run.builder.top_stage,
12911291
run.builder.config.host_target,
12921292
run.target,
@@ -1296,16 +1296,15 @@ impl Step for Clippy {
12961296
}
12971297

12981298
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1299-
let compiler = self.compiler;
13001299
let target = self.target;
1301-
1302-
builder.ensure(compile::Rustc::new(compiler, target));
1300+
let compilers =
1301+
RustcPrivateCompilers::from_build_compiler(builder, self.build_compiler, target);
13031302

13041303
// Prepare the image directory
13051304
// We expect clippy to build, because we've exited this step above if tool
13061305
// state for clippy isn't testing.
1307-
let clippy = builder.ensure(tool::Clippy { compiler, target });
1308-
let cargoclippy = builder.ensure(tool::CargoClippy { compiler, target });
1306+
let clippy = builder.ensure(tool::Clippy::from_compilers(compilers));
1307+
let cargoclippy = builder.ensure(tool::CargoClippy::from_compilers(compilers));
13091308

13101309
let mut tarball = Tarball::new(builder, "clippy", &target.triple);
13111310
tarball.set_overlay(OverlayKind::Clippy);
@@ -1317,9 +1316,9 @@ impl Step for Clippy {
13171316
}
13181317
}
13191318

1320-
#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
1319+
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
13211320
pub struct Miri {
1322-
pub compiler: Compiler,
1321+
pub build_compiler: Compiler,
13231322
pub target: TargetSelection,
13241323
}
13251324

@@ -1335,7 +1334,7 @@ impl Step for Miri {
13351334

13361335
fn make_run(run: RunConfig<'_>) {
13371336
run.builder.ensure(Miri {
1338-
compiler: run.builder.compiler_for(
1337+
build_compiler: run.builder.compiler_for(
13391338
run.builder.top_stage,
13401339
run.builder.config.host_target,
13411340
run.target,
@@ -1352,15 +1351,12 @@ impl Step for Miri {
13521351
return None;
13531352
}
13541353

1355-
let compiler = self.compiler;
1356-
let target = self.target;
1357-
1358-
builder.ensure(compile::Rustc::new(compiler, target));
1359-
1360-
let miri = builder.ensure(tool::Miri { compiler, target });
1361-
let cargomiri = builder.ensure(tool::CargoMiri { compiler, target });
1354+
let compilers =
1355+
RustcPrivateCompilers::from_build_compiler(builder, self.build_compiler, self.target);
1356+
let miri = builder.ensure(tool::Miri::from_compilers(compilers));
1357+
let cargomiri = builder.ensure(tool::CargoMiri::from_compilers(compilers));
13621358

1363-
let mut tarball = Tarball::new(builder, "miri", &target.triple);
1359+
let mut tarball = Tarball::new(builder, "miri", &self.target.triple);
13641360
tarball.set_overlay(OverlayKind::Miri);
13651361
tarball.is_preview(true);
13661362
tarball.add_file(&miri.tool_path, "bin", FileType::Executable);
@@ -1462,9 +1458,9 @@ impl Step for CodegenBackend {
14621458
}
14631459
}
14641460

1465-
#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
1461+
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
14661462
pub struct Rustfmt {
1467-
pub compiler: Compiler,
1463+
pub build_compiler: Compiler,
14681464
pub target: TargetSelection,
14691465
}
14701466

@@ -1480,7 +1476,7 @@ impl Step for Rustfmt {
14801476

14811477
fn make_run(run: RunConfig<'_>) {
14821478
run.builder.ensure(Rustfmt {
1483-
compiler: run.builder.compiler_for(
1479+
build_compiler: run.builder.compiler_for(
14841480
run.builder.top_stage,
14851481
run.builder.config.host_target,
14861482
run.target,
@@ -1490,14 +1486,13 @@ impl Step for Rustfmt {
14901486
}
14911487

14921488
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1493-
let compiler = self.compiler;
1494-
let target = self.target;
1489+
let compilers =
1490+
RustcPrivateCompilers::from_build_compiler(builder, self.build_compiler, self.target);
14951491

1496-
builder.ensure(compile::Rustc::new(compiler, target));
1492+
let rustfmt = builder.ensure(tool::Rustfmt::from_compilers(compilers));
1493+
let cargofmt = builder.ensure(tool::Cargofmt::from_compilers(compilers));
14971494

1498-
let rustfmt = builder.ensure(tool::Rustfmt { compiler, target });
1499-
let cargofmt = builder.ensure(tool::Cargofmt { compiler, target });
1500-
let mut tarball = Tarball::new(builder, "rustfmt", &target.triple);
1495+
let mut tarball = Tarball::new(builder, "rustfmt", &self.target.triple);
15011496
tarball.set_overlay(OverlayKind::Rustfmt);
15021497
tarball.is_preview(true);
15031498
tarball.add_file(&rustfmt.tool_path, "bin", FileType::Executable);
@@ -1565,11 +1560,11 @@ impl Step for Extended {
15651560
add_component!("rust-docs" => Docs { host: target });
15661561
add_component!("rust-json-docs" => JsonDocs { host: target });
15671562
add_component!("cargo" => Cargo { compiler, target });
1568-
add_component!("rustfmt" => Rustfmt { compiler, target });
1569-
add_component!("rust-analyzer" => RustAnalyzer { compiler, target });
1563+
add_component!("rustfmt" => Rustfmt { build_compiler: compiler, target });
1564+
add_component!("rust-analyzer" => RustAnalyzer { build_compiler: compiler, target });
15701565
add_component!("llvm-components" => LlvmTools { target });
1571-
add_component!("clippy" => Clippy { compiler, target });
1572-
add_component!("miri" => Miri { compiler, target });
1566+
add_component!("clippy" => Clippy { build_compiler: compiler, target });
1567+
add_component!("miri" => Miri { build_compiler: compiler, target });
15731568
add_component!("analysis" => Analysis { compiler, target });
15741569
add_component!("rustc-codegen-cranelift" => CodegenBackend {
15751570
compiler: builder.compiler(stage, target),

src/bootstrap/src/core/build_steps/install.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ install!((self, builder, _config),
221221
};
222222
RustAnalyzer, alias = "rust-analyzer", Self::should_build(_config), only_hosts: true, {
223223
if let Some(tarball) =
224-
builder.ensure(dist::RustAnalyzer { compiler: self.compiler, target: self.target })
224+
builder.ensure(dist::RustAnalyzer { build_compiler: self.compiler, target: self.target })
225225
{
226226
install_sh(builder, "rust-analyzer", self.compiler.stage, Some(self.target), &tarball);
227227
} else {
@@ -232,12 +232,12 @@ install!((self, builder, _config),
232232
};
233233
Clippy, alias = "clippy", Self::should_build(_config), only_hosts: true, {
234234
let tarball = builder
235-
.ensure(dist::Clippy { compiler: self.compiler, target: self.target })
235+
.ensure(dist::Clippy { build_compiler: self.compiler, target: self.target })
236236
.expect("missing clippy");
237237
install_sh(builder, "clippy", self.compiler.stage, Some(self.target), &tarball);
238238
};
239239
Miri, alias = "miri", Self::should_build(_config), only_hosts: true, {
240-
if let Some(tarball) = builder.ensure(dist::Miri { compiler: self.compiler, target: self.target }) {
240+
if let Some(tarball) = builder.ensure(dist::Miri { build_compiler: self.compiler, target: self.target }) {
241241
install_sh(builder, "miri", self.compiler.stage, Some(self.target), &tarball);
242242
} else {
243243
// Miri is only available on nightly
@@ -257,7 +257,7 @@ install!((self, builder, _config),
257257
};
258258
Rustfmt, alias = "rustfmt", Self::should_build(_config), only_hosts: true, {
259259
if let Some(tarball) = builder.ensure(dist::Rustfmt {
260-
compiler: self.compiler,
260+
build_compiler: self.compiler,
261261
target: self.target
262262
}) {
263263
install_sh(builder, "rustfmt", self.compiler.stage, Some(self.target), &tarball);

src/bootstrap/src/core/build_steps/run.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use clap_complete::{Generator, shells};
99

1010
use crate::core::build_steps::dist::distdir;
1111
use crate::core::build_steps::test;
12-
use crate::core::build_steps::tool::{self, SourceType, Tool};
12+
use crate::core::build_steps::tool::{self, RustcPrivateCompilers, SourceType, Tool};
1313
use crate::core::build_steps::vendor::{Vendor, default_paths_to_vendor};
1414
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
1515
use crate::core::config::TargetSelection;
@@ -135,13 +135,13 @@ impl Step for Miri {
135135
}
136136

137137
// This compiler runs on the host, we'll just use it for the target.
138-
let target_compiler = builder.compiler(stage, target);
139-
let miri_build = builder.ensure(tool::Miri { compiler: target_compiler, target });
140-
// Rustc tools are off by one stage, so use the build compiler to run miri.
138+
let compilers = RustcPrivateCompilers::new(builder, stage, target);
139+
let miri_build = builder.ensure(tool::Miri::from_compilers(compilers));
141140
let host_compiler = miri_build.build_compiler;
142141

143142
// Get a target sysroot for Miri.
144-
let miri_sysroot = test::Miri::build_miri_sysroot(builder, target_compiler, target);
143+
let miri_sysroot =
144+
test::Miri::build_miri_sysroot(builder, compilers.link_compiler(), target);
145145

146146
// # Run miri.
147147
// Running it via `cargo run` as that figures out the right dylib path.
@@ -465,8 +465,8 @@ impl Step for Rustfmt {
465465
std::process::exit(1);
466466
}
467467

468-
let compiler = builder.compiler(stage, host);
469-
let rustfmt_build = builder.ensure(tool::Rustfmt { compiler, target: host });
468+
let compilers = RustcPrivateCompilers::new(builder, stage, host);
469+
let rustfmt_build = builder.ensure(tool::Rustfmt::from_compilers(compilers));
470470

471471
let mut rustfmt = tool::prepare_tool_cargo(
472472
builder,

0 commit comments

Comments
 (0)