Skip to content

Commit 7b96851

Browse files
committed
Auto merge of rust-lang#137373 - Kobzol:tool-stage0-improve, r=jieyouxu
Compile run-make-support and run-make tests with the bootstrap compiler It does not seem necessary to have to recompile run-make-support on changes to the local compiler/stdlib. This PR simplifies the implementation of a few tools, then switches rms to stage0 and also makes the handling of environment variables in run-make tests simpler. Best reviewed commit-by-commit. I can split it into multiple PRs if you want. Also tested that `COMPILETEST_FORCE_STAGE0=1 ./x test tests/run-make --stage 0` still works. Incredibly, it looks like it even passes more tests than on `master` 😆 r? `@jieyouxu`
2 parents fd17dea + 9d6ca5f commit 7b96851

File tree

13 files changed

+124
-256
lines changed

13 files changed

+124
-256
lines changed

Diff for: src/bootstrap/src/core/build_steps/test.rs

+9-87
Original file line numberDiff line numberDiff line change
@@ -1242,59 +1242,6 @@ macro_rules! test {
12421242
};
12431243
}
12441244

1245-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
1246-
pub struct RunMakeSupport {
1247-
pub compiler: Compiler,
1248-
pub target: TargetSelection,
1249-
}
1250-
1251-
impl Step for RunMakeSupport {
1252-
type Output = PathBuf;
1253-
const DEFAULT: bool = true;
1254-
1255-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1256-
run.never()
1257-
}
1258-
1259-
fn make_run(run: RunConfig<'_>) {
1260-
let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
1261-
run.builder.ensure(RunMakeSupport { compiler, target: run.build_triple() });
1262-
}
1263-
1264-
/// Builds run-make-support and returns the path to the resulting rlib.
1265-
fn run(self, builder: &Builder<'_>) -> PathBuf {
1266-
builder.ensure(compile::Std::new(self.compiler, self.target));
1267-
1268-
let cargo = tool::prepare_tool_cargo(
1269-
builder,
1270-
self.compiler,
1271-
Mode::ToolStd,
1272-
self.target,
1273-
Kind::Build,
1274-
"src/tools/run-make-support",
1275-
SourceType::InTree,
1276-
&[],
1277-
);
1278-
1279-
let _guard = builder.msg_tool(
1280-
Kind::Build,
1281-
Mode::ToolStd,
1282-
"run-make-support",
1283-
self.compiler.stage,
1284-
&self.compiler.host,
1285-
&self.target,
1286-
);
1287-
cargo.into_cmd().run(builder);
1288-
1289-
let lib_name = "librun_make_support.rlib";
1290-
let lib = builder.tools_dir(self.compiler).join(lib_name);
1291-
1292-
let cargo_out = builder.cargo_out(self.compiler, Mode::ToolStd, self.target).join(lib_name);
1293-
builder.copy_link(&cargo_out, &lib);
1294-
lib
1295-
}
1296-
}
1297-
12981245
/// Runs `cargo test` on the `src/tools/run-make-support` crate.
12991246
/// That crate is used by run-make tests.
13001247
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -1446,40 +1393,7 @@ test!(Pretty {
14461393
only_hosts: true,
14471394
});
14481395

1449-
/// Special-handling is needed for `run-make`, so don't use `test!` for defining `RunMake`
1450-
/// tests.
1451-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1452-
pub struct RunMake {
1453-
pub compiler: Compiler,
1454-
pub target: TargetSelection,
1455-
}
1456-
1457-
impl Step for RunMake {
1458-
type Output = ();
1459-
const DEFAULT: bool = true;
1460-
const ONLY_HOSTS: bool = false;
1461-
1462-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1463-
run.suite_path("tests/run-make")
1464-
}
1465-
1466-
fn make_run(run: RunConfig<'_>) {
1467-
let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
1468-
run.builder.ensure(RunMakeSupport { compiler, target: run.build_triple() });
1469-
run.builder.ensure(RunMake { compiler, target: run.target });
1470-
}
1471-
1472-
fn run(self, builder: &Builder<'_>) {
1473-
builder.ensure(Compiletest {
1474-
compiler: self.compiler,
1475-
target: self.target,
1476-
mode: "run-make",
1477-
suite: "run-make",
1478-
path: "tests/run-make",
1479-
compare_mode: None,
1480-
});
1481-
}
1482-
}
1396+
test!(RunMake { path: "tests/run-make", mode: "run-make", suite: "run-make", default: true });
14831397

14841398
test!(Assembly { path: "tests/assembly", mode: "assembly", suite: "assembly", default: true });
14851399

@@ -1722,6 +1636,9 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
17221636
host: target,
17231637
});
17241638
}
1639+
if suite == "run-make" {
1640+
builder.tool_exe(Tool::RunMakeSupport);
1641+
}
17251642

17261643
// Also provide `rust_test_helpers` for the host.
17271644
builder.ensure(TestHelpers { target: compiler.host });
@@ -1774,6 +1691,11 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
17741691
};
17751692

17761693
cmd.arg("--cargo-path").arg(cargo_path);
1694+
1695+
// We need to pass the compiler that was used to compile run-make-support,
1696+
// because we have to use the same compiler to compile rmake.rs recipes.
1697+
let stage0_rustc_path = builder.compiler(0, compiler.host);
1698+
cmd.arg("--stage0-rustc-path").arg(builder.rustc(stage0_rustc_path));
17771699
}
17781700

17791701
// Avoid depending on rustdoc when we don't need it.

Diff for: src/bootstrap/src/core/build_steps/tool.rs

+38-43
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ pub enum SourceType {
3434
Submodule,
3535
}
3636

37+
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
38+
pub enum ToolArtifactKind {
39+
Binary,
40+
Library,
41+
}
42+
3743
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
3844
struct ToolBuild {
3945
compiler: Compiler,
@@ -47,6 +53,8 @@ struct ToolBuild {
4753
allow_features: &'static str,
4854
/// Additional arguments to pass to the `cargo` invocation.
4955
cargo_args: Vec<String>,
56+
/// Whether the tool builds a binary or a library.
57+
artifact_kind: ToolArtifactKind,
5058
}
5159

5260
impl Builder<'_> {
@@ -79,7 +87,7 @@ impl Builder<'_> {
7987
/// for using this type as `type Output = ToolBuildResult;`
8088
#[derive(Clone)]
8189
pub struct ToolBuildResult {
82-
/// Executable path of the corresponding tool that was built.
90+
/// Artifact path of the corresponding tool that was built.
8391
pub tool_path: PathBuf,
8492
/// Compiler used to build the tool. For non-`ToolRustc` tools this is equal to `target_compiler`.
8593
/// For `ToolRustc` this is one stage before of the `target_compiler`.
@@ -179,8 +187,14 @@ impl Step for ToolBuild {
179187
if tool == "tidy" {
180188
tool = "rust-tidy";
181189
}
182-
let tool_path =
183-
copy_link_tool_bin(builder, self.compiler, self.target, self.mode, tool);
190+
let tool_path = match self.artifact_kind {
191+
ToolArtifactKind::Binary => {
192+
copy_link_tool_bin(builder, self.compiler, self.target, self.mode, tool)
193+
}
194+
ToolArtifactKind::Library => builder
195+
.cargo_out(self.compiler, self.mode, self.target)
196+
.join(format!("lib{tool}.rlib")),
197+
};
184198

185199
ToolBuildResult { tool_path, build_compiler: self.compiler, target_compiler }
186200
}
@@ -330,6 +344,7 @@ macro_rules! bootstrap_tool {
330344
$(,is_unstable_tool = $unstable:expr)*
331345
$(,allow_features = $allow_features:expr)?
332346
$(,submodules = $submodules:expr)?
347+
$(,artifact_kind = $artifact_kind:expr)?
333348
;
334349
)+) => {
335350
#[derive(PartialEq, Eq, Clone)]
@@ -389,6 +404,7 @@ macro_rules! bootstrap_tool {
389404
builder.require_submodule(submodule, None);
390405
}
391406
)*
407+
392408
builder.ensure(ToolBuild {
393409
compiler: self.compiler,
394410
target: self.target,
@@ -407,7 +423,12 @@ macro_rules! bootstrap_tool {
407423
},
408424
extra_features: vec![],
409425
allow_features: concat!($($allow_features)*),
410-
cargo_args: vec![]
426+
cargo_args: vec![],
427+
artifact_kind: if false $(|| $artifact_kind == ToolArtifactKind::Library)* {
428+
ToolArtifactKind::Library
429+
} else {
430+
ToolArtifactKind::Binary
431+
}
411432
})
412433
}
413434
}
@@ -445,51 +466,14 @@ bootstrap_tool!(
445466
WasmComponentLd, "src/tools/wasm-component-ld", "wasm-component-ld", is_unstable_tool = true, allow_features = "min_specialization";
446467
UnicodeTableGenerator, "src/tools/unicode-table-generator", "unicode-table-generator";
447468
FeaturesStatusDump, "src/tools/features-status-dump", "features-status-dump";
469+
OptimizedDist, "src/tools/opt-dist", "opt-dist", submodules = &["src/tools/rustc-perf"];
470+
RunMakeSupport, "src/tools/run-make-support", "run_make_support", artifact_kind = ToolArtifactKind::Library;
448471
);
449472

450473
/// These are the submodules that are required for rustbook to work due to
451474
/// depending on mdbook plugins.
452475
pub static SUBMODULES_FOR_RUSTBOOK: &[&str] = &["src/doc/book", "src/doc/reference"];
453476

454-
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
455-
pub struct OptimizedDist {
456-
pub compiler: Compiler,
457-
pub target: TargetSelection,
458-
}
459-
460-
impl Step for OptimizedDist {
461-
type Output = ToolBuildResult;
462-
463-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
464-
run.path("src/tools/opt-dist")
465-
}
466-
467-
fn make_run(run: RunConfig<'_>) {
468-
run.builder.ensure(OptimizedDist {
469-
compiler: run.builder.compiler(0, run.builder.config.build),
470-
target: run.target,
471-
});
472-
}
473-
474-
fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
475-
// We need to ensure the rustc-perf submodule is initialized when building opt-dist since
476-
// the tool requires it to be in place to run.
477-
builder.require_submodule("src/tools/rustc-perf", None);
478-
479-
builder.ensure(ToolBuild {
480-
compiler: self.compiler,
481-
target: self.target,
482-
tool: "opt-dist",
483-
mode: Mode::ToolBootstrap,
484-
path: "src/tools/opt-dist",
485-
source_type: SourceType::InTree,
486-
extra_features: Vec::new(),
487-
allow_features: "",
488-
cargo_args: Vec::new(),
489-
})
490-
}
491-
}
492-
493477
/// The [rustc-perf](https://github.com/rust-lang/rustc-perf) benchmark suite, which is added
494478
/// as a submodule at `src/tools/rustc-perf`.
495479
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
@@ -529,6 +513,7 @@ impl Step for RustcPerf {
529513
// Only build the collector package, which is used for benchmarking through
530514
// a CLI.
531515
cargo_args: vec!["-p".to_string(), "collector".to_string()],
516+
artifact_kind: ToolArtifactKind::Binary,
532517
};
533518
let res = builder.ensure(tool.clone());
534519
// We also need to symlink the `rustc-fake` binary to the corresponding directory,
@@ -586,6 +571,7 @@ impl Step for ErrorIndex {
586571
extra_features: Vec::new(),
587572
allow_features: "",
588573
cargo_args: Vec::new(),
574+
artifact_kind: ToolArtifactKind::Binary,
589575
})
590576
}
591577
}
@@ -621,6 +607,7 @@ impl Step for RemoteTestServer {
621607
extra_features: Vec::new(),
622608
allow_features: "",
623609
cargo_args: Vec::new(),
610+
artifact_kind: ToolArtifactKind::Binary,
624611
})
625612
}
626613
}
@@ -725,6 +712,7 @@ impl Step for Rustdoc {
725712
extra_features,
726713
allow_features: "",
727714
cargo_args: Vec::new(),
715+
artifact_kind: ToolArtifactKind::Binary,
728716
});
729717

730718
// don't create a stage0-sysroot/bin directory.
@@ -779,6 +767,7 @@ impl Step for Cargo {
779767
extra_features: Vec::new(),
780768
allow_features: "",
781769
cargo_args: Vec::new(),
770+
artifact_kind: ToolArtifactKind::Binary,
782771
})
783772
}
784773
}
@@ -827,6 +816,7 @@ impl Step for LldWrapper {
827816
extra_features: Vec::new(),
828817
allow_features: "",
829818
cargo_args: Vec::new(),
819+
artifact_kind: ToolArtifactKind::Binary,
830820
});
831821

832822
let libdir_bin = builder.sysroot_target_bindir(self.target_compiler, target);
@@ -887,6 +877,7 @@ impl Step for RustAnalyzer {
887877
source_type: SourceType::InTree,
888878
allow_features: RustAnalyzer::ALLOW_FEATURES,
889879
cargo_args: Vec::new(),
880+
artifact_kind: ToolArtifactKind::Binary,
890881
})
891882
}
892883
}
@@ -931,6 +922,7 @@ impl Step for RustAnalyzerProcMacroSrv {
931922
source_type: SourceType::InTree,
932923
allow_features: RustAnalyzer::ALLOW_FEATURES,
933924
cargo_args: Vec::new(),
925+
artifact_kind: ToolArtifactKind::Binary,
934926
});
935927

936928
// Copy `rust-analyzer-proc-macro-srv` to `<sysroot>/libexec/`
@@ -985,6 +977,7 @@ impl Step for LlvmBitcodeLinker {
985977
extra_features: self.extra_features,
986978
allow_features: "",
987979
cargo_args: Vec::new(),
980+
artifact_kind: ToolArtifactKind::Binary,
988981
});
989982

990983
if tool_result.target_compiler.stage > 0 {
@@ -1164,6 +1157,7 @@ fn run_tool_build_step(
11641157
source_type: SourceType::InTree,
11651158
allow_features: "",
11661159
cargo_args: vec![],
1160+
artifact_kind: ToolArtifactKind::Binary,
11671161
});
11681162

11691163
// FIXME: This should just be an if-let-chain, but those are unstable.
@@ -1242,6 +1236,7 @@ impl Step for TestFloatParse {
12421236
extra_features: Vec::new(),
12431237
allow_features: "",
12441238
cargo_args: Vec::new(),
1239+
artifact_kind: ToolArtifactKind::Binary,
12451240
})
12461241
}
12471242
}

Diff for: src/tools/compiletest/src/common.rs

+3
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ pub struct Config {
190190
/// The cargo executable.
191191
pub cargo_path: Option<PathBuf>,
192192

193+
/// Rustc executable used to compile run-make recipes.
194+
pub stage0_rustc_path: Option<PathBuf>,
195+
193196
/// The rustdoc executable.
194197
pub rustdoc_path: Option<PathBuf>,
195198

Diff for: src/tools/compiletest/src/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ pub fn parse_config(args: Vec<String>) -> Config {
5454
.reqopt("", "run-lib-path", "path to target shared libraries", "PATH")
5555
.reqopt("", "rustc-path", "path to rustc to use for compiling", "PATH")
5656
.optopt("", "cargo-path", "path to cargo to use for compiling", "PATH")
57+
.optopt(
58+
"",
59+
"stage0-rustc-path",
60+
"path to rustc to use for compiling run-make recipes",
61+
"PATH",
62+
)
5763
.optopt("", "rustdoc-path", "path to rustdoc to use for compiling", "PATH")
5864
.optopt("", "coverage-dump-path", "path to coverage-dump to use in tests", "PATH")
5965
.reqopt("", "python", "path to python to use for doc tests", "PATH")
@@ -320,6 +326,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
320326
run_lib_path: make_absolute(opt_path(matches, "run-lib-path")),
321327
rustc_path: opt_path(matches, "rustc-path"),
322328
cargo_path: matches.opt_str("cargo-path").map(PathBuf::from),
329+
stage0_rustc_path: matches.opt_str("stage0-rustc-path").map(PathBuf::from),
323330
rustdoc_path: matches.opt_str("rustdoc-path").map(PathBuf::from),
324331
coverage_dump_path: matches.opt_str("coverage-dump-path").map(PathBuf::from),
325332
python: matches.opt_str("python").unwrap(),

0 commit comments

Comments
 (0)