Skip to content

Commit 09a7ed6

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 43f1f63 commit 09a7ed6

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};
@@ -2888,6 +2888,7 @@ impl Step for Crate {
28882888
}
28892889
}
28902890

2891+
/// Run cargo tests for the rustdoc crate.
28912892
/// Rustdoc is special in various ways, which is why this step is different from `Crate`.
28922893
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
28932894
pub struct CrateRustdoc {
@@ -2983,7 +2984,8 @@ impl Step for CrateRustdoc {
29832984

29842985
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
29852986
pub struct CrateRustdocJsonTypes {
2986-
host: TargetSelection,
2987+
build_compiler: Compiler,
2988+
target: TargetSelection,
29872989
}
29882990

29892991
impl Step for CrateRustdocJsonTypes {
@@ -2998,23 +3000,22 @@ impl Step for CrateRustdocJsonTypes {
29983000
fn make_run(run: RunConfig<'_>) {
29993001
let builder = run.builder;
30003002

3001-
builder.ensure(CrateRustdocJsonTypes { host: run.target });
3003+
builder.ensure(CrateRustdocJsonTypes {
3004+
build_compiler: get_tool_target_compiler(
3005+
builder,
3006+
ToolTargetBuildMode::Build(run.target),
3007+
),
3008+
target: run.target,
3009+
});
30023010
}
30033011

30043012
fn run(self, builder: &Builder<'_>) {
3005-
let target = self.host;
3006-
3007-
// Use the previous stage compiler to reuse the artifacts that are
3008-
// created when running compiletest for tests/rustdoc. If this used
3009-
// `compiler`, then it would cause rustdoc to be built *again*, which
3010-
// isn't really necessary.
3011-
let compiler = builder.compiler_for(builder.top_stage, target, target);
3012-
builder.ensure(compile::Rustc::new(compiler, target));
3013+
let target = self.target;
30133014

30143015
let cargo = tool::prepare_tool_cargo(
30153016
builder,
3016-
compiler,
3017-
Mode::ToolRustc,
3017+
self.build_compiler,
3018+
Mode::ToolTarget,
30183019
target,
30193020
builder.kind,
30203021
"src/rustdoc-json-types",
@@ -3023,7 +3024,7 @@ impl Step for CrateRustdocJsonTypes {
30233024
);
30243025

30253026
// FIXME: this looks very wrong, libtest doesn't accept `-C` arguments and the quotes are fishy.
3026-
let libtest_args = if self.host.contains("musl") {
3027+
let libtest_args = if target.contains("musl") {
30273028
["'-Ctarget-feature=-crt-static'"].as_slice()
30283029
} else {
30293030
&[]
@@ -3707,14 +3708,35 @@ impl Step for CodegenGCC {
37073708
}
37083709
}
37093710

3711+
/// Get a build compiler that can be used to test the standard library (i.e. its stage will
3712+
/// correspond to the stage that we want to test).
3713+
fn get_test_build_compiler_for_std(builder: &Builder<'_>) -> Compiler {
3714+
if builder.top_stage == 0 {
3715+
eprintln!(
3716+
"ERROR: cannot run tests on stage 0. `build.compiletest-allow-stage0` only works for compiletest test suites."
3717+
);
3718+
exit!(1);
3719+
}
3720+
builder.compiler(builder.top_stage, builder.host_target)
3721+
}
3722+
37103723
/// Test step that does two things:
37113724
/// - Runs `cargo test` for the `src/tools/test-float-parse` tool.
37123725
/// - Invokes the `test-float-parse` tool to test the standard library's
37133726
/// float parsing routines.
37143727
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
37153728
pub struct TestFloatParse {
3716-
path: PathBuf,
3717-
host: TargetSelection,
3729+
/// The build compiler which will build and run unit tests of `test-float-parse`, and which will
3730+
/// build the `test-float-parse` tool itself.
3731+
///
3732+
/// Note that the staging is a bit funny here, because this step essentially tests std, but it
3733+
/// also needs to build the tool. So if we test stage1 std, we build:
3734+
/// 1) stage1 rustc
3735+
/// 2) Use that to build stage1 libstd
3736+
/// 3) Use that to build and run *stage2* test-float-parse
3737+
build_compiler: Compiler,
3738+
/// Target for which we build std and test that std.
3739+
target: TargetSelection,
37183740
}
37193741

37203742
impl Step for TestFloatParse {
@@ -3727,47 +3749,47 @@ impl Step for TestFloatParse {
37273749
}
37283750

37293751
fn make_run(run: RunConfig<'_>) {
3730-
for path in run.paths {
3731-
let path = path.assert_single_path().path.clone();
3732-
run.builder.ensure(Self { path, host: run.target });
3733-
}
3752+
run.builder.ensure(Self {
3753+
build_compiler: get_test_build_compiler_for_std(run.builder),
3754+
target: run.target,
3755+
});
37343756
}
37353757

37363758
fn run(self, builder: &Builder<'_>) {
3737-
let bootstrap_host = builder.config.host_target;
3738-
let compiler = builder.compiler(builder.top_stage, bootstrap_host);
3739-
let path = self.path.to_str().unwrap();
3740-
let crate_name = self.path.iter().next_back().unwrap().to_str().unwrap();
3759+
let build_compiler = self.build_compiler;
3760+
let target = self.target;
37413761

3742-
builder.ensure(tool::TestFloatParse { host: self.host });
3762+
// Build the standard library that will be tested, and a stdlib for host code
3763+
builder.std(build_compiler, target);
3764+
builder.std(build_compiler, builder.host_target);
37433765

37443766
// Run any unit tests in the crate
37453767
let mut cargo_test = tool::prepare_tool_cargo(
37463768
builder,
3747-
compiler,
3769+
build_compiler,
37483770
Mode::ToolStd,
3749-
bootstrap_host,
3771+
target,
37503772
Kind::Test,
3751-
path,
3773+
"src/tools/test-float-parse",
37523774
SourceType::InTree,
37533775
&[],
37543776
);
3755-
cargo_test.allow_features(tool::TestFloatParse::ALLOW_FEATURES);
3777+
cargo_test.allow_features(TEST_FLOAT_PARSE_ALLOW_FEATURES);
37563778

3757-
run_cargo_test(cargo_test, &[], &[], crate_name, bootstrap_host, builder);
3779+
run_cargo_test(cargo_test, &[], &[], "test-float-parse", target, builder);
37583780

37593781
// Run the actual parse tests.
37603782
let mut cargo_run = tool::prepare_tool_cargo(
37613783
builder,
3762-
compiler,
3784+
build_compiler,
37633785
Mode::ToolStd,
3764-
bootstrap_host,
3786+
target,
37653787
Kind::Run,
3766-
path,
3788+
"src/tools/test-float-parse",
37673789
SourceType::InTree,
37683790
&[],
37693791
);
3770-
cargo_run.allow_features(tool::TestFloatParse::ALLOW_FEATURES);
3792+
cargo_run.allow_features(TEST_FLOAT_PARSE_ALLOW_FEATURES);
37713793

37723794
if !matches!(env::var("FLOAT_PARSE_TESTS_NO_SKIP_HUGE").as_deref(), Ok("1") | Ok("true")) {
37733795
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)