@@ -19,11 +19,11 @@ use crate::config::TargetSelection;
1919use crate :: dist;
2020use crate :: doc:: DocumentationFormat ;
2121use crate :: flags:: Subcommand ;
22- use crate :: native ;
22+ use crate :: llvm ;
2323use crate :: render_tests:: add_flags_and_try_run_tests;
2424use crate :: tool:: { self , SourceType , Tool } ;
2525use crate :: toolstate:: ToolState ;
26- use crate :: util:: { self , add_link_lib_path, dylib_path, dylib_path_var, output, t} ;
26+ use crate :: util:: { self , add_link_lib_path, dylib_path, dylib_path_var, output, t, up_to_date } ;
2727use crate :: { envify, CLang , DocTests , GitRepo , Mode } ;
2828
2929const ADB_TEST_DIR : & str = "/data/local/tmp/work" ;
@@ -1434,11 +1434,11 @@ note: if you're sure you want to do this, please open an issue as to why. In the
14341434 builder. ensure ( compile:: Std :: new ( compiler, compiler. host ) ) ;
14351435
14361436 // Also provide `rust_test_helpers` for the host.
1437- builder. ensure ( native :: TestHelpers { target : compiler. host } ) ;
1437+ builder. ensure ( TestHelpers { target : compiler. host } ) ;
14381438
14391439 // As well as the target, except for plain wasm32, which can't build it
14401440 if !target. contains ( "wasm" ) || target. contains ( "emscripten" ) {
1441- builder. ensure ( native :: TestHelpers { target } ) ;
1441+ builder. ensure ( TestHelpers { target } ) ;
14421442 }
14431443
14441444 builder. ensure ( RemoteCopyLibs { compiler, target } ) ;
@@ -1625,8 +1625,8 @@ note: if you're sure you want to do this, please open an issue as to why. In the
16251625 let mut llvm_components_passed = false ;
16261626 let mut copts_passed = false ;
16271627 if builder. config . llvm_enabled ( ) {
1628- let native :: LlvmResult { llvm_config, .. } =
1629- builder. ensure ( native :: Llvm { target : builder. config . build } ) ;
1628+ let llvm :: LlvmResult { llvm_config, .. } =
1629+ builder. ensure ( llvm :: Llvm { target : builder. config . build } ) ;
16301630 if !builder. config . dry_run ( ) {
16311631 let llvm_version = output ( Command :: new ( & llvm_config) . arg ( "--version" ) ) ;
16321632 let llvm_components = output ( Command :: new ( & llvm_config) . arg ( "--components" ) ) ;
@@ -1664,7 +1664,7 @@ note: if you're sure you want to do this, please open an issue as to why. In the
16641664 // If LLD is available, add it to the PATH
16651665 if builder. config . lld_enabled {
16661666 let lld_install_root =
1667- builder. ensure ( native :: Lld { target : builder. config . build } ) ;
1667+ builder. ensure ( llvm :: Lld { target : builder. config . build } ) ;
16681668
16691669 let lld_bin_path = lld_install_root. join ( "bin" ) ;
16701670
@@ -2747,3 +2747,68 @@ impl Step for RustInstaller {
27472747 run. builder . ensure ( Self ) ;
27482748 }
27492749}
2750+
2751+ #[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
2752+ pub struct TestHelpers {
2753+ pub target : TargetSelection ,
2754+ }
2755+
2756+ impl Step for TestHelpers {
2757+ type Output = ( ) ;
2758+
2759+ fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
2760+ run. path ( "tests/auxiliary/rust_test_helpers.c" )
2761+ }
2762+
2763+ fn make_run ( run : RunConfig < ' _ > ) {
2764+ run. builder . ensure ( TestHelpers { target : run. target } )
2765+ }
2766+
2767+ /// Compiles the `rust_test_helpers.c` library which we used in various
2768+ /// `run-pass` tests for ABI testing.
2769+ fn run ( self , builder : & Builder < ' _ > ) {
2770+ if builder. config . dry_run ( ) {
2771+ return ;
2772+ }
2773+ // The x86_64-fortanix-unknown-sgx target doesn't have a working C
2774+ // toolchain. However, some x86_64 ELF objects can be linked
2775+ // without issues. Use this hack to compile the test helpers.
2776+ let target = if self . target == "x86_64-fortanix-unknown-sgx" {
2777+ TargetSelection :: from_user ( "x86_64-unknown-linux-gnu" )
2778+ } else {
2779+ self . target
2780+ } ;
2781+ let dst = builder. test_helpers_out ( target) ;
2782+ let src = builder. src . join ( "tests/auxiliary/rust_test_helpers.c" ) ;
2783+ if up_to_date ( & src, & dst. join ( "librust_test_helpers.a" ) ) {
2784+ return ;
2785+ }
2786+
2787+ builder. info ( "Building test helpers" ) ;
2788+ t ! ( fs:: create_dir_all( & dst) ) ;
2789+ let mut cfg = cc:: Build :: new ( ) ;
2790+ // FIXME: Workaround for https://github.com/emscripten-core/emscripten/issues/9013
2791+ if target. contains ( "emscripten" ) {
2792+ cfg. pic ( false ) ;
2793+ }
2794+
2795+ // We may have found various cross-compilers a little differently due to our
2796+ // extra configuration, so inform cc of these compilers. Note, though, that
2797+ // on MSVC we still need cc's detection of env vars (ugh).
2798+ if !target. contains ( "msvc" ) {
2799+ if let Some ( ar) = builder. ar ( target) {
2800+ cfg. archiver ( ar) ;
2801+ }
2802+ cfg. compiler ( builder. cc ( target) ) ;
2803+ }
2804+ cfg. cargo_metadata ( false )
2805+ . out_dir ( & dst)
2806+ . target ( & target. triple )
2807+ . host ( & builder. config . build . triple )
2808+ . opt_level ( 0 )
2809+ . warnings ( false )
2810+ . debug ( false )
2811+ . file ( builder. src . join ( "tests/auxiliary/rust_test_helpers.c" ) )
2812+ . compile ( "rust_test_helpers" ) ;
2813+ }
2814+ }
0 commit comments