@@ -18,8 +18,8 @@ use crate::core::build_steps::llvm::get_llvm_version;
18
18
use crate :: core:: build_steps:: run:: get_completion_paths;
19
19
use crate :: core:: build_steps:: synthetic_targets:: MirOptPanicAbortSyntheticTarget ;
20
20
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,
23
23
} ;
24
24
use crate :: core:: build_steps:: toolstate:: ToolState ;
25
25
use crate :: core:: build_steps:: { compile, dist, llvm} ;
@@ -2865,6 +2865,7 @@ impl Step for Crate {
2865
2865
}
2866
2866
}
2867
2867
2868
+ /// Run cargo tests for the rustdoc crate.
2868
2869
/// Rustdoc is special in various ways, which is why this step is different from `Crate`.
2869
2870
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
2870
2871
pub struct CrateRustdoc {
@@ -2960,7 +2961,8 @@ impl Step for CrateRustdoc {
2960
2961
2961
2962
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
2962
2963
pub struct CrateRustdocJsonTypes {
2963
- host : TargetSelection ,
2964
+ build_compiler : Compiler ,
2965
+ target : TargetSelection ,
2964
2966
}
2965
2967
2966
2968
impl Step for CrateRustdocJsonTypes {
@@ -2975,23 +2977,22 @@ impl Step for CrateRustdocJsonTypes {
2975
2977
fn make_run ( run : RunConfig < ' _ > ) {
2976
2978
let builder = run. builder ;
2977
2979
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
+ } ) ;
2979
2987
}
2980
2988
2981
2989
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 ;
2990
2991
2991
2992
let cargo = tool:: prepare_tool_cargo (
2992
2993
builder,
2993
- compiler ,
2994
- Mode :: ToolRustc ,
2994
+ self . build_compiler ,
2995
+ Mode :: ToolTarget ,
2995
2996
target,
2996
2997
builder. kind ,
2997
2998
"src/rustdoc-json-types" ,
@@ -3000,7 +3001,7 @@ impl Step for CrateRustdocJsonTypes {
3000
3001
) ;
3001
3002
3002
3003
// 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" ) {
3004
3005
[ "'-Ctarget-feature=-crt-static'" ] . as_slice ( )
3005
3006
} else {
3006
3007
& [ ]
@@ -3674,14 +3675,35 @@ impl Step for CodegenGCC {
3674
3675
}
3675
3676
}
3676
3677
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
+
3677
3690
/// Test step that does two things:
3678
3691
/// - Runs `cargo test` for the `src/tools/test-float-parse` tool.
3679
3692
/// - Invokes the `test-float-parse` tool to test the standard library's
3680
3693
/// float parsing routines.
3681
3694
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
3682
3695
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 ,
3685
3707
}
3686
3708
3687
3709
impl Step for TestFloatParse {
@@ -3694,47 +3716,47 @@ impl Step for TestFloatParse {
3694
3716
}
3695
3717
3696
3718
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
+ } ) ;
3701
3723
}
3702
3724
3703
3725
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 ;
3708
3728
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 ) ;
3710
3732
3711
3733
// Run any unit tests in the crate
3712
3734
let mut cargo_test = tool:: prepare_tool_cargo (
3713
3735
builder,
3714
- compiler ,
3736
+ build_compiler ,
3715
3737
Mode :: ToolStd ,
3716
- bootstrap_host ,
3738
+ target ,
3717
3739
Kind :: Test ,
3718
- path ,
3740
+ "src/tools/test-float-parse" ,
3719
3741
SourceType :: InTree ,
3720
3742
& [ ] ,
3721
3743
) ;
3722
- cargo_test. allow_features ( tool :: TestFloatParse :: ALLOW_FEATURES ) ;
3744
+ cargo_test. allow_features ( TEST_FLOAT_PARSE_ALLOW_FEATURES ) ;
3723
3745
3724
- run_cargo_test ( cargo_test, & [ ] , & [ ] , crate_name , bootstrap_host , builder) ;
3746
+ run_cargo_test ( cargo_test, & [ ] , & [ ] , "test-float-parse" , target , builder) ;
3725
3747
3726
3748
// Run the actual parse tests.
3727
3749
let mut cargo_run = tool:: prepare_tool_cargo (
3728
3750
builder,
3729
- compiler ,
3751
+ build_compiler ,
3730
3752
Mode :: ToolStd ,
3731
- bootstrap_host ,
3753
+ target ,
3732
3754
Kind :: Run ,
3733
- path ,
3755
+ "src/tools/test-float-parse" ,
3734
3756
SourceType :: InTree ,
3735
3757
& [ ] ,
3736
3758
) ;
3737
- cargo_run. allow_features ( tool :: TestFloatParse :: ALLOW_FEATURES ) ;
3759
+ cargo_run. allow_features ( TEST_FLOAT_PARSE_ALLOW_FEATURES ) ;
3738
3760
3739
3761
if !matches ! ( env:: var( "FLOAT_PARSE_TESTS_NO_SKIP_HUGE" ) . as_deref( ) , Ok ( "1" ) | Ok ( "true" ) ) {
3740
3762
cargo_run. args ( [ "--" , "--skip-huge" ] ) ;
0 commit comments