@@ -9,46 +9,53 @@ use super::intrinsic_helpers::IntrinsicTypeDefinition;
99// The number of times each intrinsic will be called.
1010const PASSES : u32 = 20 ;
1111
12- pub fn write_cargo_toml ( w : & mut impl std:: io:: Write , binaries : & [ String ] ) -> std:: io:: Result < ( ) > {
12+ fn write_cargo_toml_header ( w : & mut impl std:: io:: Write , name : & str ) -> std:: io:: Result < ( ) > {
1313 writeln ! (
1414 w,
1515 concat!(
1616 "[package]\n " ,
17- "name = \" intrinsic-test-programs \" \n " ,
17+ "name = \" {name} \" \n " ,
1818 "version = \" {version}\" \n " ,
1919 "authors = [{authors}]\n " ,
2020 "license = \" {license}\" \n " ,
2121 "edition = \" 2018\" \n " ,
22- "[workspace]\n " ,
23- "[dependencies]\n " ,
24- "core_arch = {{ path = \" ../crates/core_arch\" }}" ,
2522 ) ,
23+ name = name,
2624 version = env!( "CARGO_PKG_VERSION" ) ,
2725 authors = env!( "CARGO_PKG_AUTHORS" )
2826 . split( ":" )
2927 . format_with( ", " , |author, fmt| fmt( & format_args!( "\" {author}\" " ) ) ) ,
3028 license = env!( "CARGO_PKG_LICENSE" ) ,
31- ) ?;
29+ )
30+ }
3231
33- for binary in binaries {
34- writeln ! (
35- w ,
36- concat! (
37- "[[bin]] \n " ,
38- "name = \" {binary} \" \n " ,
39- "path = \" {binary}/main.rs \" \n " ,
40- ) ,
41- binary = binary ,
42- ) ?;
32+ pub fn write_bin_cargo_toml (
33+ w : & mut impl std :: io :: Write ,
34+ module_count : usize ,
35+ ) -> std :: io :: Result < ( ) > {
36+ write_cargo_toml_header ( w , "intrinsic-test-programs" ) ? ;
37+
38+ writeln ! ( w , "[dependencies]" ) ? ;
39+
40+ for i in 0 ..module_count {
41+ writeln ! ( w , "mod_{i} = {{ path = \" mod_{i}/ \" }}" ) ?;
4342 }
4443
4544 Ok ( ( ) )
4645}
4746
47+ pub fn write_lib_cargo_toml ( w : & mut impl std:: io:: Write , name : & str ) -> std:: io:: Result < ( ) > {
48+ write_cargo_toml_header ( w, name) ?;
49+
50+ writeln ! ( w, "[dependencies]" ) ?;
51+ writeln ! ( w, "core_arch = {{ path = \" ../../crates/core_arch\" }}" ) ?;
52+
53+ Ok ( ( ) )
54+ }
55+
4856pub fn write_main_rs < ' a > (
4957 w : & mut impl std:: io:: Write ,
50- available_parallelism : usize ,
51- architecture : & str ,
58+ chunk_count : usize ,
5259 cfg : & str ,
5360 definitions : & str ,
5461 intrinsics : impl Iterator < Item = & ' a str > + Clone ,
@@ -65,10 +72,7 @@ pub fn write_main_rs<'a>(
6572 writeln ! ( w, "{cfg}" ) ?;
6673 writeln ! ( w, "{definitions}" ) ?;
6774
68- writeln ! ( w, "use core_arch::arch::{architecture}::*;" ) ?;
69-
70- for module in 0 ..Ord :: min ( available_parallelism, intrinsics. clone ( ) . count ( ) ) {
71- writeln ! ( w, "mod mod_{module};" ) ?;
75+ for module in 0 ..chunk_count {
7276 writeln ! ( w, "use mod_{module}::*;" ) ?;
7377 }
7478
@@ -91,6 +95,38 @@ pub fn write_main_rs<'a>(
9195 Ok ( ( ) )
9296}
9397
98+ pub fn write_lib_rs < T : IntrinsicTypeDefinition > (
99+ w : & mut impl std:: io:: Write ,
100+ architecture : & str ,
101+ notice : & str ,
102+ cfg : & str ,
103+ definitions : & str ,
104+ intrinsics : & [ impl IntrinsicDefinition < T > ] ,
105+ ) -> std:: io:: Result < ( ) > {
106+ write ! ( w, "{notice}" ) ?;
107+
108+ writeln ! ( w, "#![feature(simd_ffi)]" ) ?;
109+ writeln ! ( w, "#![feature(f16)]" ) ?;
110+ writeln ! ( w, "#![allow(unused)]" ) ?;
111+
112+ // Cargo will spam the logs if these warnings are not silenced.
113+ writeln ! ( w, "#![allow(non_upper_case_globals)]" ) ?;
114+ writeln ! ( w, "#![allow(non_camel_case_types)]" ) ?;
115+ writeln ! ( w, "#![allow(non_snake_case)]" ) ?;
116+
117+ writeln ! ( w, "{cfg}" ) ?;
118+
119+ writeln ! ( w, "use core_arch::arch::{architecture}::*;" ) ?;
120+
121+ writeln ! ( w, "{definitions}" ) ?;
122+
123+ for intrinsic in intrinsics {
124+ crate :: common:: gen_rust:: create_rust_test_module ( w, intrinsic) ?;
125+ }
126+
127+ Ok ( ( ) )
128+ }
129+
94130pub fn compile_rust_programs ( toolchain : Option < & str > , target : & str , linker : Option < & str > ) -> bool {
95131 /* If there has been a linker explicitly set from the command line then
96132 * we want to set it via setting it in the RUSTFLAGS*/
@@ -100,6 +136,9 @@ pub fn compile_rust_programs(toolchain: Option<&str>, target: &str, linker: Opti
100136 let mut cargo_command = Command :: new ( "cargo" ) ;
101137 cargo_command. current_dir ( "rust_programs" ) ;
102138
139+ // Do not use the target directory of the workspace please.
140+ cargo_command. env ( "CARGO_TARGET_DIR" , "target" ) ;
141+
103142 if let Some ( toolchain) = toolchain
104143 && !toolchain. is_empty ( )
105144 {
0 commit comments