Skip to content

Commit 0ee7f89

Browse files
committed
Fix staging of TestFloatParse
The tool wasn't useful for anything, it was only built as a part of the test, but we can just use `cargo test` and `cargo run` in the test, no need to (pre-)build the tool itself.
1 parent 8cf3404 commit 0ee7f89

File tree

3 files changed

+61
-74
lines changed

3 files changed

+61
-74
lines changed

src/bootstrap/src/core/build_steps/check.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use crate::core::build_steps::compile::{
88
};
99
use crate::core::build_steps::tool;
1010
use crate::core::build_steps::tool::{
11-
COMPILETEST_ALLOW_FEATURES, SourceType, ToolTargetBuildMode, get_tool_target_compiler,
12-
prepare_tool_cargo,
11+
COMPILETEST_ALLOW_FEATURES, SourceType, TEST_FLOAT_PARSE_ALLOW_FEATURES, ToolTargetBuildMode,
12+
get_tool_target_compiler, prepare_tool_cargo,
1313
};
1414
use crate::core::builder::{
1515
self, Alias, Builder, Cargo, Kind, RunConfig, ShouldRun, Step, StepMetadata, crate_description,
@@ -791,7 +791,7 @@ tool_check_step!(MiroptTestTools {
791791
tool_check_step!(TestFloatParse {
792792
path: "src/tools/test-float-parse",
793793
mode: |_builder| Mode::ToolStd,
794-
allow_features: tool::TestFloatParse::ALLOW_FEATURES
794+
allow_features: TEST_FLOAT_PARSE_ALLOW_FEATURES
795795
});
796796
tool_check_step!(FeaturesStatusDump {
797797
path: "src/tools/features-status-dump",

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 57 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use crate::core::build_steps::llvm::get_llvm_version;
1818
use crate::core::build_steps::run::get_completion_paths;
1919
use crate::core::build_steps::synthetic_targets::MirOptPanicAbortSyntheticTarget;
2020
use crate::core::build_steps::tool::{
21-
self, COMPILETEST_ALLOW_FEATURES, RustcPrivateCompilers, SourceType, Tool, ToolTargetBuildMode,
22-
get_tool_target_compiler,
21+
self, COMPILETEST_ALLOW_FEATURES, RustcPrivateCompilers, SourceType,
22+
TEST_FLOAT_PARSE_ALLOW_FEATURES, Tool, ToolTargetBuildMode, get_tool_target_compiler,
2323
};
2424
use crate::core::build_steps::toolstate::ToolState;
2525
use crate::core::build_steps::{compile, dist, llvm};
@@ -2865,6 +2865,7 @@ impl Step for Crate {
28652865
}
28662866
}
28672867

2868+
/// Run cargo tests for the rustdoc crate.
28682869
/// Rustdoc is special in various ways, which is why this step is different from `Crate`.
28692870
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
28702871
pub struct CrateRustdoc {
@@ -2960,7 +2961,8 @@ impl Step for CrateRustdoc {
29602961

29612962
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
29622963
pub struct CrateRustdocJsonTypes {
2963-
host: TargetSelection,
2964+
build_compiler: Compiler,
2965+
target: TargetSelection,
29642966
}
29652967

29662968
impl Step for CrateRustdocJsonTypes {
@@ -2975,23 +2977,22 @@ impl Step for CrateRustdocJsonTypes {
29752977
fn make_run(run: RunConfig<'_>) {
29762978
let builder = run.builder;
29772979

2978-
builder.ensure(CrateRustdocJsonTypes { host: run.target });
2980+
builder.ensure(CrateRustdocJsonTypes {
2981+
build_compiler: get_tool_target_compiler(
2982+
builder,
2983+
ToolTargetBuildMode::Build(run.target),
2984+
),
2985+
target: run.target,
2986+
});
29792987
}
29802988

29812989
fn run(self, builder: &Builder<'_>) {
2982-
let target = self.host;
2983-
2984-
// Use the previous stage compiler to reuse the artifacts that are
2985-
// created when running compiletest for tests/rustdoc. If this used
2986-
// `compiler`, then it would cause rustdoc to be built *again*, which
2987-
// isn't really necessary.
2988-
let compiler = builder.compiler_for(builder.top_stage, target, target);
2989-
builder.ensure(compile::Rustc::new(compiler, target));
2990+
let target = self.target;
29902991

29912992
let cargo = tool::prepare_tool_cargo(
29922993
builder,
2993-
compiler,
2994-
Mode::ToolRustc,
2994+
self.build_compiler,
2995+
Mode::ToolTarget,
29952996
target,
29962997
builder.kind,
29972998
"src/rustdoc-json-types",
@@ -3000,7 +3001,7 @@ impl Step for CrateRustdocJsonTypes {
30003001
);
30013002

30023003
// FIXME: this looks very wrong, libtest doesn't accept `-C` arguments and the quotes are fishy.
3003-
let libtest_args = if self.host.contains("musl") {
3004+
let libtest_args = if target.contains("musl") {
30043005
["'-Ctarget-feature=-crt-static'"].as_slice()
30053006
} else {
30063007
&[]
@@ -3674,14 +3675,35 @@ impl Step for CodegenGCC {
36743675
}
36753676
}
36763677

3678+
/// Get a build compiler that can be used to test the standard library (i.e. its stage will
3679+
/// correspond to the stage that we want to test).
3680+
fn get_test_build_compiler_for_std(builder: &Builder<'_>) -> Compiler {
3681+
if builder.top_stage == 0 {
3682+
eprintln!(
3683+
"ERROR: cannot run tests on stage 0. `build.compiletest-allow-stage0` only works for compiletest test suites."
3684+
);
3685+
exit!(1);
3686+
}
3687+
builder.compiler(builder.top_stage, builder.host_target)
3688+
}
3689+
36773690
/// Test step that does two things:
36783691
/// - Runs `cargo test` for the `src/tools/test-float-parse` tool.
36793692
/// - Invokes the `test-float-parse` tool to test the standard library's
36803693
/// float parsing routines.
36813694
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
36823695
pub struct TestFloatParse {
3683-
path: PathBuf,
3684-
host: TargetSelection,
3696+
/// The build compiler which will build and run unit tests of `test-float-parse`, and which will
3697+
/// build the `test-float-parse` tool itself.
3698+
///
3699+
/// Note that the staging is a bit funny here, because this step essentially tests std, but it
3700+
/// also needs to build the tool. So if we test stage1 std, we build:
3701+
/// 1) stage1 rustc
3702+
/// 2) Use that to build stage1 libstd
3703+
/// 3) Use that to build and run *stage2* test-float-parse
3704+
build_compiler: Compiler,
3705+
/// Target for which we build std and test that std.
3706+
target: TargetSelection,
36853707
}
36863708

36873709
impl Step for TestFloatParse {
@@ -3694,47 +3716,47 @@ impl Step for TestFloatParse {
36943716
}
36953717

36963718
fn make_run(run: RunConfig<'_>) {
3697-
for path in run.paths {
3698-
let path = path.assert_single_path().path.clone();
3699-
run.builder.ensure(Self { path, host: run.target });
3700-
}
3719+
run.builder.ensure(Self {
3720+
build_compiler: get_test_build_compiler_for_std(run.builder),
3721+
target: run.target,
3722+
});
37013723
}
37023724

37033725
fn run(self, builder: &Builder<'_>) {
3704-
let bootstrap_host = builder.config.host_target;
3705-
let compiler = builder.compiler(builder.top_stage, bootstrap_host);
3706-
let path = self.path.to_str().unwrap();
3707-
let crate_name = self.path.iter().next_back().unwrap().to_str().unwrap();
3726+
let build_compiler = self.build_compiler;
3727+
let target = self.target;
37083728

3709-
builder.ensure(tool::TestFloatParse { host: self.host });
3729+
// Build the standard library that will be tested, and a stdlib for host code
3730+
builder.std(build_compiler, target);
3731+
builder.std(build_compiler, builder.host_target);
37103732

37113733
// Run any unit tests in the crate
37123734
let mut cargo_test = tool::prepare_tool_cargo(
37133735
builder,
3714-
compiler,
3736+
build_compiler,
37153737
Mode::ToolStd,
3716-
bootstrap_host,
3738+
target,
37173739
Kind::Test,
3718-
path,
3740+
"src/tools/test-float-parse",
37193741
SourceType::InTree,
37203742
&[],
37213743
);
3722-
cargo_test.allow_features(tool::TestFloatParse::ALLOW_FEATURES);
3744+
cargo_test.allow_features(TEST_FLOAT_PARSE_ALLOW_FEATURES);
37233745

3724-
run_cargo_test(cargo_test, &[], &[], crate_name, bootstrap_host, builder);
3746+
run_cargo_test(cargo_test, &[], &[], "test-float-parse", target, builder);
37253747

37263748
// Run the actual parse tests.
37273749
let mut cargo_run = tool::prepare_tool_cargo(
37283750
builder,
3729-
compiler,
3751+
build_compiler,
37303752
Mode::ToolStd,
3731-
bootstrap_host,
3753+
target,
37323754
Kind::Run,
3733-
path,
3755+
"src/tools/test-float-parse",
37343756
SourceType::InTree,
37353757
&[],
37363758
);
3737-
cargo_run.allow_features(tool::TestFloatParse::ALLOW_FEATURES);
3759+
cargo_run.allow_features(TEST_FLOAT_PARSE_ALLOW_FEATURES);
37383760

37393761
if !matches!(env::var("FLOAT_PARSE_TESTS_NO_SKIP_HUGE").as_deref(), Ok("1") | Ok("true")) {
37403762
cargo_run.args(["--", "--skip-huge"]);

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

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,42 +1539,7 @@ tool_rustc_extended!(Rustfmt {
15391539
add_bins_to_sysroot: ["rustfmt"]
15401540
});
15411541

1542-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1543-
pub struct TestFloatParse {
1544-
pub host: TargetSelection,
1545-
}
1546-
1547-
impl TestFloatParse {
1548-
pub const ALLOW_FEATURES: &'static str = "f16,cfg_target_has_reliable_f16_f128";
1549-
}
1550-
1551-
impl Step for TestFloatParse {
1552-
type Output = ToolBuildResult;
1553-
const IS_HOST: bool = true;
1554-
const DEFAULT: bool = false;
1555-
1556-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1557-
run.path("src/tools/test-float-parse")
1558-
}
1559-
1560-
fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
1561-
let bootstrap_host = builder.config.host_target;
1562-
let compiler = builder.compiler(builder.top_stage, bootstrap_host);
1563-
1564-
builder.ensure(ToolBuild {
1565-
build_compiler: compiler,
1566-
target: bootstrap_host,
1567-
tool: "test-float-parse",
1568-
mode: Mode::ToolStd,
1569-
path: "src/tools/test-float-parse",
1570-
source_type: SourceType::InTree,
1571-
extra_features: Vec::new(),
1572-
allow_features: Self::ALLOW_FEATURES,
1573-
cargo_args: Vec::new(),
1574-
artifact_kind: ToolArtifactKind::Binary,
1575-
})
1576-
}
1577-
}
1542+
pub const TEST_FLOAT_PARSE_ALLOW_FEATURES: &'static str = "f16,cfg_target_has_reliable_f16_f128";
15781543

15791544
impl Builder<'_> {
15801545
/// Gets a `BootstrapCommand` which is ready to run `tool` in `stage` built for

0 commit comments

Comments
 (0)