@@ -18,8 +18,8 @@ use crate::core::build_steps::llvm::get_llvm_version;
1818use crate :: core:: build_steps:: run:: get_completion_paths;
1919use crate :: core:: build_steps:: synthetic_targets:: MirOptPanicAbortSyntheticTarget ;
2020use 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} ;
2424use crate :: core:: build_steps:: toolstate:: ToolState ;
2525use 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 ) ]
28932894pub struct CrateRustdoc {
@@ -2983,7 +2984,8 @@ impl Step for CrateRustdoc {
29832984
29842985#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
29852986pub struct CrateRustdocJsonTypes {
2986- host : TargetSelection ,
2987+ build_compiler : Compiler ,
2988+ target : TargetSelection ,
29872989}
29882990
29892991impl 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 ) ]
37153728pub 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
37203742impl 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" ] ) ;
0 commit comments