@@ -2,7 +2,6 @@ use itertools::Itertools;
22use rayon:: prelude:: * ;
33use std:: collections:: BTreeMap ;
44use std:: fs:: File ;
5- use std:: io:: Write ;
65use std:: process:: Command ;
76
87use super :: argument:: Argument ;
@@ -23,8 +22,8 @@ pub fn format_rust_main_template(
2322) -> String {
2423 format ! (
2524 r#"{notices}#![feature(simd_ffi)]
26- #![feature(link_llvm_intrinsics)]
2725#![feature(f16)]
26+ #![allow(unused)]
2827{configurations}
2928{definitions}
3029
@@ -38,75 +37,75 @@ fn main() {{
3837 )
3938}
4039
40+ fn write_cargo_toml ( w : & mut impl std:: io:: Write , binaries : & [ String ] ) -> std:: io:: Result < ( ) > {
41+ writeln ! (
42+ w,
43+ concat!(
44+ "[package]\n " ,
45+ "name = \" intrinsic-test-programs\" \n " ,
46+ "version = \" {version}\" \n " ,
47+ "authors = [{authors}]\n " ,
48+ "license = \" {license}\" \n " ,
49+ "edition = \" 2018\" \n " ,
50+ "[workspace]\n " ,
51+ "[dependencies]\n " ,
52+ "core_arch = {{ path = \" ../crates/core_arch\" }}" ,
53+ ) ,
54+ version = env!( "CARGO_PKG_VERSION" ) ,
55+ authors = env!( "CARGO_PKG_AUTHORS" )
56+ . split( ":" )
57+ . format_with( ", " , |author, fmt| fmt( & format_args!( "\" {author}\" " ) ) ) ,
58+ license = env!( "CARGO_PKG_LICENSE" ) ,
59+ ) ?;
60+
61+ for binary in binaries {
62+ writeln ! (
63+ w,
64+ concat!(
65+ "[[bin]]\n " ,
66+ "name = \" {binary}\" \n " ,
67+ "path = \" {binary}/main.rs\" \n " ,
68+ ) ,
69+ binary = binary,
70+ ) ?;
71+ }
72+
73+ Ok ( ( ) )
74+ }
75+
4176pub fn compile_rust_programs (
4277 binaries : Vec < String > ,
4378 toolchain : Option < & str > ,
4479 target : & str ,
4580 linker : Option < & str > ,
4681) -> bool {
4782 let mut cargo = File :: create ( "rust_programs/Cargo.toml" ) . unwrap ( ) ;
48- cargo
49- . write_all (
50- format ! (
51- r#"[package]
52- name = "intrinsic-test-programs"
53- version = "{version}"
54- authors = [{authors}]
55- license = "{license}"
56- edition = "2018"
57- [workspace]
58- [dependencies]
59- core_arch = {{ path = "../crates/core_arch" }}
60- {binaries}"# ,
61- version = env!( "CARGO_PKG_VERSION" ) ,
62- authors = env!( "CARGO_PKG_AUTHORS" )
63- . split( ":" )
64- . format_with( ", " , |author, fmt| fmt( & format_args!( "\" {author}\" " ) ) ) ,
65- license = env!( "CARGO_PKG_LICENSE" ) ,
66- binaries = binaries
67- . iter( )
68- . map( |binary| {
69- format!(
70- r#"[[bin]]
71- name = "{binary}"
72- path = "{binary}/main.rs""# ,
73- )
74- } )
75- . collect:: <Vec <_>>( )
76- . join( "\n " )
77- )
78- . into_bytes ( )
79- . as_slice ( ) ,
80- )
81- . unwrap ( ) ;
82-
83- let toolchain = match toolchain {
84- None => return true ,
85- Some ( t) => t,
86- } ;
83+ write_cargo_toml ( & mut cargo, & binaries) . unwrap ( ) ;
8784
8885 /* If there has been a linker explicitly set from the command line then
8986 * we want to set it via setting it in the RUSTFLAGS*/
9087
91- let cargo_command = format ! ( "cargo {toolchain} build --target {target} --release" ) ;
88+ let mut cargo_command = Command :: new ( "cargo" ) ;
89+ cargo_command. current_dir ( "rust_programs" ) ;
9290
93- let mut command = Command :: new ( "sh" ) ;
94- command
95- . current_dir ( "rust_programs" )
96- . arg ( "-c" )
97- . arg ( cargo_command) ;
91+ if let Some ( toolchain) = toolchain {
92+ if !toolchain. is_empty ( ) {
93+ cargo_command. arg ( toolchain) ;
94+ }
95+ }
96+ cargo_command. args ( [ "build" , "--target" , target, "--release" ] ) ;
9897
9998 let mut rust_flags = "-Cdebuginfo=0" . to_string ( ) ;
10099 if let Some ( linker) = linker {
101100 rust_flags. push_str ( " -C linker=" ) ;
102101 rust_flags. push_str ( linker) ;
103102 rust_flags. push_str ( " -C link-args=-static" ) ;
104103
105- command . env ( "CPPFLAGS" , "-fuse-ld=lld" ) ;
104+ cargo_command . env ( "CPPFLAGS" , "-fuse-ld=lld" ) ;
106105 }
107106
108- command . env ( "RUSTFLAGS" , rust_flags) ;
109- let output = command . output ( ) ;
107+ cargo_command . env ( "RUSTFLAGS" , rust_flags) ;
108+ let output = cargo_command . output ( ) ;
110109
111110 if let Ok ( output) = output {
112111 if output. status . success ( ) {
0 commit comments