@@ -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} ;
@@ -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 ) ]
28702871pub struct CrateRustdoc {
@@ -2960,7 +2961,8 @@ impl Step for CrateRustdoc {
29602961
29612962#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
29622963pub struct CrateRustdocJsonTypes {
2963- host : TargetSelection ,
2964+ build_compiler : Compiler ,
2965+ target : TargetSelection ,
29642966}
29652967
29662968impl 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 ) ]
36823695pub 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
36873709impl 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" ] ) ;
0 commit comments