@@ -70,22 +70,25 @@ fn hash_changed(
70
70
71
71
#[ cfg( feature = "asm" ) ]
72
72
fn build_nasm_files ( ) {
73
- use std:: fs:: File ;
74
- use std:: io:: Write ;
75
- let out_dir = env:: var ( "OUT_DIR" ) . unwrap ( ) ;
73
+ let mut config = "
74
+ %pragma preproc sane_empty_expansion true
75
+ %define private_prefix rav1e
76
+ %define ARCH_X86_32 0
77
+ %define ARCH_X86_64 1
78
+ %define PIC 1
79
+ %define STACK_ALIGNMENT 16
80
+ %define HAVE_AVX512ICL 1
81
+ "
82
+ . to_owned ( ) ;
76
83
77
- let dest_path = Path :: new ( & out_dir) . join ( "config.asm" ) ;
78
- let mut config_file = File :: create ( & dest_path) . unwrap ( ) ;
79
- config_file. write ( b" %define private_prefix rav1e\n " ) . unwrap ( ) ;
80
- config_file. write ( b" %define ARCH_X86_32 0\n " ) . unwrap ( ) ;
81
- config_file. write ( b" %define ARCH_X86_64 1\n " ) . unwrap ( ) ;
82
- config_file. write ( b" %define PIC 1\n " ) . unwrap ( ) ;
83
- config_file. write ( b" %define STACK_ALIGNMENT 16\n " ) . unwrap ( ) ;
84
- config_file. write ( b" %define HAVE_AVX512ICL 1\n " ) . unwrap ( ) ;
85
84
if env:: var ( "CARGO_CFG_TARGET_VENDOR" ) . unwrap ( ) == "apple" {
86
- config_file . write ( b" %define PREFIX 1\n ") . unwrap ( ) ;
85
+ config += " %define PREFIX 1\n ";
87
86
}
88
87
88
+ let out_dir = env:: var ( "OUT_DIR" ) . unwrap ( ) ;
89
+ let dest_path = Path :: new ( & out_dir) . join ( "config.asm" ) ;
90
+ std:: fs:: write ( & dest_path, config) . expect ( "can write config.asm" ) ;
91
+
89
92
let asm_files = & [
90
93
"src/x86/cdef_avx2.asm" ,
91
94
"src/x86/cdef_avx512.asm" ,
@@ -132,20 +135,17 @@ fn build_nasm_files() {
132
135
if let Some ( ( hash, hash_path) ) =
133
136
hash_changed ( asm_files, & out_dir, & dest_path)
134
137
{
135
- let mut config_include_arg = String :: from ( "-I" ) ;
136
- config_include_arg. push_str ( & out_dir) ;
137
- config_include_arg. push ( '/' ) ;
138
- let mut nasm = nasm_rs:: Build :: new ( ) ;
139
- nasm. min_version ( 2 , 14 , 0 ) ;
140
- for file in asm_files {
141
- nasm. file ( file) ;
142
- }
143
- nasm. flag ( & config_include_arg) ;
144
- nasm. flag ( "-Isrc/" ) ;
145
- let obj = nasm. compile_objects ( ) . unwrap_or_else ( |e| {
146
- println ! ( "cargo:warning={e}" ) ;
147
- panic ! ( "NASM build failed. Make sure you have nasm installed or disable the \" asm\" feature.\n \
148
- You can get NASM from https://nasm.us or your system's package manager.\n \n error: {e}") ;
138
+ let obj = nasm_rs:: Build :: new ( )
139
+ . min_version ( 2 , 15 , 0 )
140
+ . include ( & out_dir)
141
+ . include ( "src" )
142
+ . files ( asm_files)
143
+ . compile_objects ( )
144
+ . unwrap_or_else ( |e| {
145
+ panic ! ( "NASM build failed. Make sure you have nasm installed or disable the \" asm\" feature.\n \
146
+ You can get NASM from https://nasm.us or your system's package manager.\n \
147
+ \n \
148
+ error: {e}") ;
149
149
} ) ;
150
150
151
151
// cc is better at finding the correct archiver
@@ -196,21 +196,21 @@ fn strip_command() -> Option<String> {
196
196
197
197
#[ cfg( feature = "asm" ) ]
198
198
fn build_asm_files ( ) {
199
- use std:: fs:: File ;
200
- use std:: io:: Write ;
201
- let out_dir = env:: var ( "OUT_DIR" ) . unwrap ( ) ;
199
+ let mut config = "
200
+ #define PRIVATE_PREFIX rav1e_
201
+ #define ARCH_AARCH64 1
202
+ #define ARCH_ARM 0
203
+ #define CONFIG_LOG 1
204
+ #define HAVE_ASM 1
205
+ "
206
+ . to_owned ( ) ;
202
207
203
- let dest_path = Path :: new ( & out_dir) . join ( "config.h" ) ;
204
- let mut config_file = File :: create ( & dest_path) . unwrap ( ) ;
205
208
if env:: var ( "CARGO_CFG_TARGET_VENDOR" ) . unwrap ( ) == "apple" {
206
- config_file . write ( b" #define PREFIX 1\n ") . unwrap ( ) ;
209
+ config += " #define PREFIX 1\n ";
207
210
}
208
- config_file. write ( b" #define PRIVATE_PREFIX rav1e_\n " ) . unwrap ( ) ;
209
- config_file. write ( b" #define ARCH_AARCH64 1\n " ) . unwrap ( ) ;
210
- config_file. write ( b" #define ARCH_ARM 0\n " ) . unwrap ( ) ;
211
- config_file. write ( b" #define CONFIG_LOG 1 \n " ) . unwrap ( ) ;
212
- config_file. write ( b" #define HAVE_ASM 1\n " ) . unwrap ( ) ;
213
- config_file. sync_all ( ) . unwrap ( ) ;
211
+ let out_dir = env:: var ( "OUT_DIR" ) . unwrap ( ) ;
212
+ let dest_path = Path :: new ( & out_dir) . join ( "config.h" ) ;
213
+ std:: fs:: write ( & dest_path, config) . expect ( "can write config.h" ) ;
214
214
215
215
let asm_files = & [
216
216
"src/arm/64/cdef.S" ,
0 commit comments