@@ -29,7 +29,10 @@ pub mod values;
2929
3030/// Architectures must support this trait
3131/// to be successfully tested.
32- pub trait SupportedArchitectureTest {
32+ pub trait SupportedArchitectureTest
33+ where
34+ Self : Sync + Send ,
35+ {
3336 type IntrinsicImpl : IntrinsicTypeDefinition + Sync ;
3437
3538 fn cli_options ( & self ) -> & ProcessedCli ;
@@ -104,46 +107,86 @@ pub trait SupportedArchitectureTest {
104107 )
105108 . unwrap ( ) ;
106109
107- // This is done because `cpp_compiler_wrapped` is None when
108- // the --generate-only flag is passed
110+ let available_parallelism = std:: thread:: available_parallelism ( ) . unwrap ( ) . get ( ) ;
111+ self . intrinsics ( )
112+ . par_chunks ( available_parallelism)
113+ . enumerate ( )
114+ . map ( |( i, chunk) | {
115+ let mut file = File :: create ( format ! ( "c_programs/main_{i}.cpp" ) ) . unwrap ( ) ;
116+ write_main_cpp (
117+ & mut file,
118+ Self :: PLATFORM_C_DEFINITIONS ,
119+ Self :: PLATFORM_C_HEADERS ,
120+ chunk. iter ( ) . map ( |i| i. name . as_str ( ) ) ,
121+ )
122+ } )
123+ . collect :: < Result < ( ) , std:: io:: Error > > ( )
124+ . unwrap ( ) ;
125+
109126 if let Some ( cpp_compiler) = cpp_compiler_wrapped. as_ref ( ) {
110- // compile this cpp file into a .o file
111- trace ! ( "compiling main.cpp" ) ;
112- let output = cpp_compiler
113- . compile_object_file ( "main.cpp" , "intrinsic-test-programs.o" )
114- . unwrap ( ) ;
115- assert ! ( output. status. success( ) , "{output:?}" ) ;
116-
117- let object_files = ( 0 ..chunk_count)
118- . map ( |i| format ! ( "mod_{i}.o" ) )
119- . chain ( [ "intrinsic-test-programs.o" . to_owned ( ) ] ) ;
120-
121- let output = cpp_compiler
122- . link_executable ( object_files, "intrinsic-test-programs" )
123- . unwrap ( ) ;
124- assert ! ( output. status. success( ) , "{output:?}" ) ;
125- }
127+ ( 0 ..available_parallelism)
128+ . into_par_iter ( )
129+ . map ( |i| {
130+ // This is done because `cpp_compiler_wrapped` is None when
131+ // the --generate-only flag is passed
132+ // compile this cpp file into a .o file
133+ trace ! ( "compiling intrinsic-test-programs_{i}.cpp" ) ;
134+ let output = cpp_compiler. compile_object_file (
135+ format ! ( "main_{i}.cpp" ) . as_str ( ) ,
136+ format ! ( "main_{i}.o" ) . as_str ( ) ,
137+ ) ;
138+
139+ if output. is_err ( ) {
140+ return output;
141+ } ;
142+
143+ let object_files = ( 0 ..chunk_count)
144+ . map ( |mod_i| format ! ( "mod_{mod_i}.o" ) )
145+ . chain ( [ format ! ( "main_{i}.o" ) . to_owned ( ) ] ) ;
146+
147+ let output = cpp_compiler. link_executable (
148+ object_files,
149+ format ! ( "intrinsic-test-programs_{i}" ) . as_str ( ) ,
150+ ) ;
126151
127- true
152+ return output;
153+ } )
154+ . inspect ( |output| {
155+ assert ! ( output. is_ok( ) , "{output:?}" ) ;
156+ if let Ok ( out) = & output {
157+ assert ! ( out. status. success( ) , "{output:?}" )
158+ }
159+ } )
160+ . any ( |output| output. is_err ( ) )
161+ } else {
162+ true
163+ }
128164 }
129165
130166 fn build_rust_file ( & self ) -> bool {
131167 std:: fs:: create_dir_all ( "rust_programs/src" ) . unwrap ( ) ;
132168
133169 let ( chunk_size, chunk_count) = manual_chunk ( self . intrinsics ( ) . len ( ) , 400 ) ;
170+ let available_parallelism = std:: thread:: available_parallelism ( ) . unwrap ( ) . get ( ) ;
134171
135172 let mut cargo = File :: create ( "rust_programs/Cargo.toml" ) . unwrap ( ) ;
136- write_bin_cargo_toml ( & mut cargo, chunk_count) . unwrap ( ) ;
137-
138- let mut main_rs = File :: create ( "rust_programs/src/main.rs" ) . unwrap ( ) ;
139- write_main_rs (
140- & mut main_rs,
141- chunk_count,
142- Self :: PLATFORM_RUST_CFGS ,
143- "" ,
144- self . intrinsics ( ) . iter ( ) . map ( |i| i. name . as_str ( ) ) ,
145- )
146- . unwrap ( ) ;
173+ write_bin_cargo_toml ( & mut cargo, chunk_count, available_parallelism) . unwrap ( ) ;
174+
175+ self . intrinsics ( )
176+ . par_chunks ( available_parallelism)
177+ . enumerate ( )
178+ . map ( |( i, chunk) | {
179+ let mut main_rs = File :: create ( format ! ( "rust_programs/src/main_{i}.rs" ) ) . unwrap ( ) ;
180+ write_main_rs (
181+ & mut main_rs,
182+ chunk_count,
183+ Self :: PLATFORM_RUST_CFGS ,
184+ "" ,
185+ chunk. iter ( ) . map ( |i| i. name . as_str ( ) ) ,
186+ )
187+ } )
188+ . collect :: < Result < ( ) , std:: io:: Error > > ( )
189+ . unwrap ( ) ;
147190
148191 let target = & self . cli_options ( ) . target ;
149192 let toolchain = self . cli_options ( ) . toolchain . as_deref ( ) ;
0 commit comments