Skip to content

Commit

Permalink
Auto merge of rust-lang#137373 - Kobzol:tool-stage0-improve, r=jieyouxu
Browse files Browse the repository at this point in the history
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`

try-job: x86_64-apple-1
try-job: x86_64-apple-2
try-job: aarch64-apple
try-job: x86_64-msvc-1
try-job: x86_64-msvc-2
try-job: x86_64-mingw-1
try-job: x86_64-mingw-2
try-job: test-various
  • Loading branch information
bors committed Feb 26, 2025
2 parents ac91805 + 50bddc8 commit ea5f15f
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 256 deletions.
91 changes: 4 additions & 87 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1230,59 +1230,6 @@ macro_rules! test {
};
}

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
pub struct RunMakeSupport {
pub compiler: Compiler,
pub target: TargetSelection,
}

impl Step for RunMakeSupport {
type Output = PathBuf;
const DEFAULT: bool = true;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.never()
}

fn make_run(run: RunConfig<'_>) {
let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
run.builder.ensure(RunMakeSupport { compiler, target: run.build_triple() });
}

/// Builds run-make-support and returns the path to the resulting rlib.
fn run(self, builder: &Builder<'_>) -> PathBuf {
builder.ensure(compile::Std::new(self.compiler, self.target));

let cargo = tool::prepare_tool_cargo(
builder,
self.compiler,
Mode::ToolStd,
self.target,
Kind::Build,
"src/tools/run-make-support",
SourceType::InTree,
&[],
);

let _guard = builder.msg_tool(
Kind::Build,
Mode::ToolStd,
"run-make-support",
self.compiler.stage,
&self.compiler.host,
&self.target,
);
cargo.into_cmd().run(builder);

let lib_name = "librun_make_support.rlib";
let lib = builder.tools_dir(self.compiler).join(lib_name);

let cargo_out = builder.cargo_out(self.compiler, Mode::ToolStd, self.target).join(lib_name);
builder.copy_link(&cargo_out, &lib);
lib
}
}

/// Runs `cargo test` on the `src/tools/run-make-support` crate.
/// That crate is used by run-make tests.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -1434,40 +1381,7 @@ test!(Pretty {
only_hosts: true,
});

/// Special-handling is needed for `run-make`, so don't use `test!` for defining `RunMake`
/// tests.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct RunMake {
pub compiler: Compiler,
pub target: TargetSelection,
}

impl Step for RunMake {
type Output = ();
const DEFAULT: bool = true;
const ONLY_HOSTS: bool = false;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.suite_path("tests/run-make")
}

fn make_run(run: RunConfig<'_>) {
let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
run.builder.ensure(RunMakeSupport { compiler, target: run.build_triple() });
run.builder.ensure(RunMake { compiler, target: run.target });
}

fn run(self, builder: &Builder<'_>) {
builder.ensure(Compiletest {
compiler: self.compiler,
target: self.target,
mode: "run-make",
suite: "run-make",
path: "tests/run-make",
compare_mode: None,
});
}
}
test!(RunMake { path: "tests/run-make", mode: "run-make", suite: "run-make", default: true });

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

Expand Down Expand Up @@ -1710,6 +1624,9 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
host: target,
});
}
if suite == "run-make" {
builder.tool_exe(Tool::RunMakeSupport);
}

// Also provide `rust_test_helpers` for the host.
builder.ensure(TestHelpers { target: compiler.host });
Expand Down
81 changes: 38 additions & 43 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ pub enum SourceType {
Submodule,
}

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub enum ToolArtifactKind {
Binary,
Library,
}

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
struct ToolBuild {
compiler: Compiler,
Expand All @@ -47,6 +53,8 @@ struct ToolBuild {
allow_features: &'static str,
/// Additional arguments to pass to the `cargo` invocation.
cargo_args: Vec<String>,
/// Whether the tool builds a binary or a library.
artifact_kind: ToolArtifactKind,
}

impl Builder<'_> {
Expand Down Expand Up @@ -79,7 +87,7 @@ impl Builder<'_> {
/// for using this type as `type Output = ToolBuildResult;`
#[derive(Clone)]
pub struct ToolBuildResult {
/// Executable path of the corresponding tool that was built.
/// Artifact path of the corresponding tool that was built.
pub tool_path: PathBuf,
/// Compiler used to build the tool. For non-`ToolRustc` tools this is equal to `target_compiler`.
/// For `ToolRustc` this is one stage before of the `target_compiler`.
Expand Down Expand Up @@ -179,8 +187,14 @@ impl Step for ToolBuild {
if tool == "tidy" {
tool = "rust-tidy";
}
let tool_path =
copy_link_tool_bin(builder, self.compiler, self.target, self.mode, tool);
let tool_path = match self.artifact_kind {
ToolArtifactKind::Binary => {
copy_link_tool_bin(builder, self.compiler, self.target, self.mode, tool)
}
ToolArtifactKind::Library => builder
.cargo_out(self.compiler, self.mode, self.target)
.join(format!("lib{tool}.rlib")),
};

ToolBuildResult { tool_path, build_compiler: self.compiler, target_compiler }
}
Expand Down Expand Up @@ -330,6 +344,7 @@ macro_rules! bootstrap_tool {
$(,is_unstable_tool = $unstable:expr)*
$(,allow_features = $allow_features:expr)?
$(,submodules = $submodules:expr)?
$(,artifact_kind = $artifact_kind:expr)?
;
)+) => {
#[derive(PartialEq, Eq, Clone)]
Expand Down Expand Up @@ -389,6 +404,7 @@ macro_rules! bootstrap_tool {
builder.require_submodule(submodule, None);
}
)*

builder.ensure(ToolBuild {
compiler: self.compiler,
target: self.target,
Expand All @@ -407,7 +423,12 @@ macro_rules! bootstrap_tool {
},
extra_features: vec![],
allow_features: concat!($($allow_features)*),
cargo_args: vec![]
cargo_args: vec![],
artifact_kind: if false $(|| $artifact_kind == ToolArtifactKind::Library)* {
ToolArtifactKind::Library
} else {
ToolArtifactKind::Binary
}
})
}
}
Expand Down Expand Up @@ -445,51 +466,14 @@ bootstrap_tool!(
WasmComponentLd, "src/tools/wasm-component-ld", "wasm-component-ld", is_unstable_tool = true, allow_features = "min_specialization";
UnicodeTableGenerator, "src/tools/unicode-table-generator", "unicode-table-generator";
FeaturesStatusDump, "src/tools/features-status-dump", "features-status-dump";
OptimizedDist, "src/tools/opt-dist", "opt-dist", submodules = &["src/tools/rustc-perf"];
RunMakeSupport, "src/tools/run-make-support", "run_make_support", artifact_kind = ToolArtifactKind::Library;
);

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

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct OptimizedDist {
pub compiler: Compiler,
pub target: TargetSelection,
}

impl Step for OptimizedDist {
type Output = ToolBuildResult;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.path("src/tools/opt-dist")
}

fn make_run(run: RunConfig<'_>) {
run.builder.ensure(OptimizedDist {
compiler: run.builder.compiler(0, run.builder.config.build),
target: run.target,
});
}

fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
// We need to ensure the rustc-perf submodule is initialized when building opt-dist since
// the tool requires it to be in place to run.
builder.require_submodule("src/tools/rustc-perf", None);

builder.ensure(ToolBuild {
compiler: self.compiler,
target: self.target,
tool: "opt-dist",
mode: Mode::ToolBootstrap,
path: "src/tools/opt-dist",
source_type: SourceType::InTree,
extra_features: Vec::new(),
allow_features: "",
cargo_args: Vec::new(),
})
}
}

/// The [rustc-perf](https://github.com/rust-lang/rustc-perf) benchmark suite, which is added
/// as a submodule at `src/tools/rustc-perf`.
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
Expand Down Expand Up @@ -529,6 +513,7 @@ impl Step for RustcPerf {
// Only build the collector package, which is used for benchmarking through
// a CLI.
cargo_args: vec!["-p".to_string(), "collector".to_string()],
artifact_kind: ToolArtifactKind::Binary,
};
let res = builder.ensure(tool.clone());
// We also need to symlink the `rustc-fake` binary to the corresponding directory,
Expand Down Expand Up @@ -586,6 +571,7 @@ impl Step for ErrorIndex {
extra_features: Vec::new(),
allow_features: "",
cargo_args: Vec::new(),
artifact_kind: ToolArtifactKind::Binary,
})
}
}
Expand Down Expand Up @@ -621,6 +607,7 @@ impl Step for RemoteTestServer {
extra_features: Vec::new(),
allow_features: "",
cargo_args: Vec::new(),
artifact_kind: ToolArtifactKind::Binary,
})
}
}
Expand Down Expand Up @@ -725,6 +712,7 @@ impl Step for Rustdoc {
extra_features,
allow_features: "",
cargo_args: Vec::new(),
artifact_kind: ToolArtifactKind::Binary,
});

// don't create a stage0-sysroot/bin directory.
Expand Down Expand Up @@ -779,6 +767,7 @@ impl Step for Cargo {
extra_features: Vec::new(),
allow_features: "",
cargo_args: Vec::new(),
artifact_kind: ToolArtifactKind::Binary,
})
}
}
Expand Down Expand Up @@ -827,6 +816,7 @@ impl Step for LldWrapper {
extra_features: Vec::new(),
allow_features: "",
cargo_args: Vec::new(),
artifact_kind: ToolArtifactKind::Binary,
});

let libdir_bin = builder.sysroot_target_bindir(self.target_compiler, target);
Expand Down Expand Up @@ -887,6 +877,7 @@ impl Step for RustAnalyzer {
source_type: SourceType::InTree,
allow_features: RustAnalyzer::ALLOW_FEATURES,
cargo_args: Vec::new(),
artifact_kind: ToolArtifactKind::Binary,
})
}
}
Expand Down Expand Up @@ -931,6 +922,7 @@ impl Step for RustAnalyzerProcMacroSrv {
source_type: SourceType::InTree,
allow_features: RustAnalyzer::ALLOW_FEATURES,
cargo_args: Vec::new(),
artifact_kind: ToolArtifactKind::Binary,
});

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

if tool_result.target_compiler.stage > 0 {
Expand Down Expand Up @@ -1164,6 +1157,7 @@ fn run_tool_build_step(
source_type: SourceType::InTree,
allow_features: "",
cargo_args: vec![],
artifact_kind: ToolArtifactKind::Binary,
});

// FIXME: This should just be an if-let-chain, but those are unstable.
Expand Down Expand Up @@ -1242,6 +1236,7 @@ impl Step for TestFloatParse {
extra_features: Vec::new(),
allow_features: "",
cargo_args: Vec::new(),
artifact_kind: ToolArtifactKind::Binary,
})
}
}
Expand Down
Loading

0 comments on commit ea5f15f

Please sign in to comment.