11use clap:: Parser ;
2+ use compiletest:: common:: Mode ;
23use itertools:: Itertools as _;
3- use rustc_codegen_spirv_types:: { SpirvTarget , TargetSpecVersion , query_rustc_version} ;
4- use std:: ffi:: OsString ;
4+ use rustc_codegen_spirv_types:: { SpirvTarget , TargetSpec , TargetSpecVersion , query_rustc_version} ;
55use std:: {
66 env, io,
77 path:: { Path , PathBuf } ,
@@ -79,7 +79,7 @@ fn main() {
7979 codegen_backend_path,
8080 } ;
8181
82- runner. run_mode ( "ui" ) ;
82+ runner. run_mode ( Mode :: Ui ) ;
8383}
8484
8585struct Runner {
@@ -94,7 +94,7 @@ impl Runner {
9494 /// Runs the given `mode` on the directory that matches that name, using the
9595 /// backend provided by `codegen_backend_path`.
9696 #[ allow( clippy:: string_add) ]
97- fn run_mode ( & self , mode : & ' static str ) {
97+ fn run_mode ( & self , mode : Mode ) {
9898 /// RUSTFLAGS passed to all test files.
9999 fn test_rustc_flags (
100100 codegen_backend_path : & Path ,
@@ -157,7 +157,12 @@ impl Runner {
157157 println ! ( "Testing env: {stage_id}\n " ) ;
158158
159159 let target = SpirvTarget :: parse ( env) . unwrap ( ) ;
160- let libs = self . build_deps ( & target) ;
160+ let rustc_version = query_rustc_version ( None ) . unwrap ( ) ;
161+ let target_spec =
162+ TargetSpecVersion :: target_arg ( rustc_version, & target, & self . deps_target_dir )
163+ . unwrap ( ) ;
164+
165+ let libs = self . build_deps ( & target, & target_spec) ;
161166 let mut flags = test_rustc_flags (
162167 & self . codegen_backend_path ,
163168 & libs,
@@ -175,9 +180,9 @@ impl Runner {
175180 let config = compiletest:: Config {
176181 stage_id,
177182 target_rustcflags : Some ( flags) ,
178- mode : mode . parse ( ) . expect ( "Invalid mode" ) ,
179- target : self . target_spec_json ( & target) . into_string ( ) . unwrap ( ) ,
180- src_base : self . tests_dir . join ( mode) ,
183+ mode,
184+ target : target_spec . target . into_string ( ) . unwrap ( ) ,
185+ src_base : self . tests_dir . join ( mode. to_string ( ) ) ,
181186 build_base : self . compiletest_build_dir . clone ( ) ,
182187 bless : self . opt . bless ,
183188 filters : self . opt . filters . clone ( ) ,
@@ -191,20 +196,18 @@ impl Runner {
191196 }
192197
193198 /// Runs the processes needed to build `spirv-std` & other deps.
194- fn build_deps ( & self , target : & SpirvTarget ) -> TestDeps {
199+ fn build_deps ( & self , target : & SpirvTarget , target_spec : & TargetSpec ) -> TestDeps {
195200 // Build compiletests-deps-helper
196- std:: process:: Command :: new ( "cargo" )
197- . args ( [
198- "build" ,
199- "-p" ,
200- "compiletests-deps-helper" ,
201- "-Zjson-target-spec" ,
202- "-Zbuild-std=core" ,
203- "-Zbuild-std-features=compiler-builtins-mem" ,
204- "--target" ,
205- ] )
206- . arg ( self . target_spec_json ( target) )
207- . arg ( "--target-dir" )
201+ let mut cmd = std:: process:: Command :: new ( "cargo" ) ;
202+ cmd. args ( [
203+ "build" ,
204+ "-p" ,
205+ "compiletests-deps-helper" ,
206+ "-Zbuild-std=core" ,
207+ "-Zbuild-std-features=compiler-builtins-mem" ,
208+ ] ) ;
209+ target_spec. append_to_cmd ( & mut cmd) ;
210+ cmd. arg ( "--target-dir" )
208211 . arg ( & self . deps_target_dir )
209212 . env ( "RUSTFLAGS" , rust_flags ( & self . codegen_backend_path ) )
210213 . stderr ( std:: process:: Stdio :: inherit ( ) )
@@ -242,7 +245,7 @@ impl Runner {
242245 "warning: cleaning deps ({missing_count} missing libs, {duplicate_count} duplicated libs)"
243246 ) ;
244247 self . clean_deps ( ) ;
245- self . build_deps ( target)
248+ self . build_deps ( target, target_spec )
246249 } else {
247250 TestDeps {
248251 core : core. ok ( ) . unwrap ( ) ,
@@ -259,17 +262,10 @@ impl Runner {
259262 . arg ( "clean" )
260263 . arg ( "--target-dir" )
261264 . arg ( & self . deps_target_dir )
262- . stderr ( std:: process:: Stdio :: inherit ( ) )
263- . stdout ( std:: process:: Stdio :: inherit ( ) )
264265 . status ( )
265266 . and_then ( map_status_to_result)
266267 . unwrap ( ) ;
267268 }
268-
269- fn target_spec_json ( & self , target : & SpirvTarget ) -> OsString {
270- let rustc_version = query_rustc_version ( None ) . unwrap ( ) ;
271- TargetSpecVersion :: target_arg ( rustc_version, target, & self . deps_target_dir ) . unwrap ( )
272- }
273269}
274270
275271enum FindLibError {
0 commit comments