@@ -135,13 +135,9 @@ impl NasmConfiguration {
135135 fn find ( target : Target ) -> Option < Self > {
136136 use TargetArch :: * ;
137137 use TargetFamily :: * ;
138- // use TargetEnv::*;
139138 use TargetOs :: * ;
140139
141140 match target. arch {
142- // for now, we only support building asm with nasm
143- // and nasm only supports x86 and x86_64
144- // sooo, even though we have some logic for other arches coded, we don't actually support them
145141 X86_64 | X86 => { }
146142 _ => return None ,
147143 }
@@ -150,29 +146,22 @@ impl NasmConfiguration {
150146
151147 let asm_extension = match target. arch {
152148 X86_64 | X86 => ".asm" ,
153- Aarch64 | Arm => ".S" ,
154149 _ => return None ,
155150 } ;
156151
157152 let asm_dir = match target. arch {
158153 X86_64 | X86 => "x86" ,
159- Aarch64 => "arm64" ,
160- Arm => "arm" ,
161154 _ => return None ,
162155 } ;
163156
164157 let asm_exclude = match target. arch {
165158 X86_64 | X86 => "asm_inc.asm" ,
166- Aarch64 => "arm_arch64_common_macro.S" ,
167- Arm => "arm_arch_common_macro.S" ,
168159 _ => return None ,
169160 } ;
170161
171162 // CPP defines to inform which assembly symbols to use.
172163 let cpp_define = match target. arch {
173164 X86_64 | X86 => "X86_ASM" ,
174- Aarch64 => "HAVE_NEON_AARCH64" ,
175- Arm => "HAVE_NEON" ,
176165 _ => return None ,
177166 } ;
178167
@@ -184,8 +173,6 @@ impl NasmConfiguration {
184173 _ => return None ,
185174 } ,
186175 X86 => "X86_32" ,
187- Aarch64 => "HAVE_NEON_AARCH64" ,
188- Arm => "HAVE_NEON" ,
189176 _ => return None ,
190177 } ;
191178
@@ -215,15 +202,13 @@ impl NasmConfiguration {
215202}
216203
217204#[ allow( unused) ]
218- fn try_compile_nasm ( cc_build_command : & mut Build , root : & str ) {
205+ fn try_compile_nasm ( target : & Target , cc_build_command : & mut Build , root : & str ) {
219206 if std:: env:: var ( "OPENH264_NO_ASM" ) . is_ok ( ) {
220207 println ! ( "NASM compilation disabled by environment variable." ) ;
221208 return ;
222209 }
223210
224- let target = Target :: from_env ( ) ;
225-
226- let Some ( config) = NasmConfiguration :: find ( target) else {
211+ let Some ( config) = NasmConfiguration :: find ( * target) else {
227212 println ! ( "No NASM configuration found for target, not using any assembly.\n Target: {target:?}" ) ;
228213 return ;
229214 } ;
@@ -257,10 +242,10 @@ fn try_compile_nasm(cc_build_command: &mut Build, root: &str) {
257242}
258243
259244/// Builds an OpenH264 sub-library and adds it to the project.
260- fn compile_and_add_openh264_static_lib ( name : & str , root : & str , includes : & [ & str ] ) {
245+ fn compile_and_add_openh264_static_lib ( target : & Target , name : & str , root : & str , suffix : & str , includes : & [ & str ] ) {
261246 let mut cc_build = cc:: Build :: new ( ) ;
262247
263- try_compile_nasm ( & mut cc_build, root) ;
248+ try_compile_nasm ( target , & mut cc_build, root) ;
264249
265250 cc_build
266251 . include ( "upstream/codec/api/wels/" )
@@ -278,16 +263,36 @@ fn compile_and_add_openh264_static_lib(name: &str, root: &str, includes: &[&str]
278263 // disable stack protectors on mingw:
279264 // (seems to be the way to go https://github.com/rdp/ffmpeg-windows-build-helpers/issues/380)
280265
281- if let Target {
282- os : TargetOs :: Windows ,
283- env : TargetEnv :: Gnu ,
284- ..
285- } = Target :: from_env ( )
286- {
287- } else {
266+ if !matches ! ( target. os, TargetOs :: Windows ) || !matches ! ( target. env, TargetEnv :: Gnu ) {
288267 cc_build. flag_if_supported ( "-fstack-protector-all" ) ;
289268 }
290269
270+ // cl.exe cannot assemble .S files.
271+ // TODO: generalize try_compile_nasm and invoke armasm64.exe.
272+ if !matches ! ( target. os, TargetOs :: Windows ) {
273+ match target. arch {
274+ TargetArch :: Arm => {
275+ cc_build. define ( "HAVE_NEON" , None ) ;
276+ cc_build. include ( "upstream/codec/common/arm" ) ;
277+ cc_build. files ( glob_import (
278+ Path :: new ( root) . join ( suffix) . join ( "arm" ) ,
279+ ".S" ,
280+ "arm_arch_common_macro.S" ,
281+ ) ) ;
282+ }
283+ TargetArch :: Aarch64 => {
284+ cc_build. define ( "HAVE_NEON_AARCH64" , None ) ;
285+ cc_build. include ( "upstream/codec/common/arm64" ) ;
286+ cc_build. files ( glob_import (
287+ Path :: new ( root) . join ( suffix) . join ( "arm64" ) ,
288+ ".S" ,
289+ "arm_arch64_common_macro.S" ,
290+ ) ) ;
291+ }
292+ _ => { }
293+ }
294+ }
295+
291296 for include in includes {
292297 cc_build. include ( include) ;
293298 }
@@ -298,11 +303,15 @@ fn compile_and_add_openh264_static_lib(name: &str, root: &str, includes: &[&str]
298303}
299304
300305fn main ( ) {
301- compile_and_add_openh264_static_lib ( "common" , "upstream/codec/common" , & [ ] ) ;
306+ let target = Target :: from_env ( ) ;
307+
308+ compile_and_add_openh264_static_lib ( & target, "common" , "upstream/codec/common" , "." , & [ ] ) ;
302309
303310 compile_and_add_openh264_static_lib (
311+ & target,
304312 "processing" ,
305313 "upstream/codec/processing" ,
314+ "src" ,
306315 & [
307316 "upstream/codec/processing/src/common/" ,
308317 "upstream/codec/processing/interface/" ,
@@ -311,15 +320,19 @@ fn main() {
311320
312321 // #[cfg(feature = "decoder")]
313322 compile_and_add_openh264_static_lib (
323+ & target,
314324 "decoder" ,
315325 "upstream/codec/decoder" ,
326+ "core" ,
316327 & [ "upstream/codec/decoder/core/inc/" , "upstream/codec/decoder/plus/inc/" ] ,
317328 ) ;
318329
319330 // #[cfg(feature = "encoder")]
320331 compile_and_add_openh264_static_lib (
332+ & target,
321333 "encoder" ,
322334 "upstream/codec/encoder" ,
335+ "core" ,
323336 & [
324337 "upstream/codec/encoder/core/inc/" ,
325338 "upstream/codec/encoder/plus/inc/" ,
0 commit comments