@@ -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,87 @@ 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 ( |index| {
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 main_{index}.cpp" ) ;
134+ let output = cpp_compiler. compile_object_file (
135+ format ! ( "main_{index}.cpp" ) . as_str ( ) ,
136+ format ! ( "main_{index}.o" ) . as_str ( ) ,
137+ ) ;
126138
127- true
139+ if output. is_err ( ) {
140+ return output;
141+ } ;
142+
143+ let object_files = ( 0 ..chunk_count)
144+ . map ( |i| format ! ( "mod_{i}.o" ) )
145+ . chain ( [ format ! ( "main_{index}.o" ) . to_owned ( ) ] ) ;
146+
147+ let output = cpp_compiler. link_executable (
148+ object_files,
149+ format ! ( "intrinsic-test-programs-{index}" ) . as_str ( ) ,
150+ ) ;
151+ trace ! ( "finished compiling main_{index}.cpp" ) ;
152+
153+ return output;
154+ } )
155+ . inspect ( |output| {
156+ assert ! ( output. is_ok( ) , "{output:?}" ) ;
157+ if let Ok ( out) = & output {
158+ assert ! ( out. status. success( ) , "{output:?}" )
159+ }
160+ } )
161+ . all ( |output| output. is_ok ( ) )
162+ } else {
163+ true
164+ }
128165 }
129166
130167 fn build_rust_file ( & self ) -> bool {
131168 std:: fs:: create_dir_all ( "rust_programs/src" ) . unwrap ( ) ;
132169
133170 let ( chunk_size, chunk_count) = manual_chunk ( self . intrinsics ( ) . len ( ) , 400 ) ;
171+ let available_parallelism = std:: thread:: available_parallelism ( ) . unwrap ( ) . get ( ) ;
134172
135173 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 ( ) ;
174+ write_bin_cargo_toml ( & mut cargo, chunk_count, available_parallelism) . unwrap ( ) ;
175+
176+ self . intrinsics ( )
177+ . par_chunks ( available_parallelism)
178+ . enumerate ( )
179+ . map ( |( i, chunk) | {
180+ let mut main_rs = File :: create ( format ! ( "rust_programs/src/main_{i}.rs" ) ) . unwrap ( ) ;
181+ write_main_rs (
182+ & mut main_rs,
183+ chunk_count,
184+ Self :: PLATFORM_RUST_CFGS ,
185+ "" ,
186+ chunk. iter ( ) . map ( |i| i. name . as_str ( ) ) ,
187+ )
188+ } )
189+ . collect :: < Result < ( ) , std:: io:: Error > > ( )
190+ . unwrap ( ) ;
147191
148192 let target = & self . cli_options ( ) . target ;
149193 let toolchain = self . cli_options ( ) . toolchain . as_deref ( ) ;
0 commit comments