@@ -97,6 +97,7 @@ pub struct Build {
97
97
flags_supported : Vec < String > ,
98
98
known_flag_support_status : Arc < Mutex < HashMap < String , bool > > > ,
99
99
ar_flags : Vec < String > ,
100
+ asm_flags : Vec < String > ,
100
101
no_default_flags : bool ,
101
102
files : Vec < PathBuf > ,
102
103
cpp : bool ,
@@ -299,6 +300,7 @@ impl Build {
299
300
flags_supported : Vec :: new ( ) ,
300
301
known_flag_support_status : Arc :: new ( Mutex :: new ( HashMap :: new ( ) ) ) ,
301
302
ar_flags : Vec :: new ( ) ,
303
+ asm_flags : Vec :: new ( ) ,
302
304
no_default_flags : false ,
303
305
files : Vec :: new ( ) ,
304
306
shared_flag : None ,
@@ -434,6 +436,25 @@ impl Build {
434
436
self
435
437
}
436
438
439
+ /// Add a flag that will only be used with assembly files.
440
+ ///
441
+ /// The flag will be applied to input files with either a `.s` or
442
+ /// `.asm` extension (case insensitive).
443
+ ///
444
+ /// # Example
445
+ ///
446
+ /// ```no_run
447
+ /// cc::Build::new()
448
+ /// .asm_flag("-Wa,-defsym,abc=1")
449
+ /// .file("src/foo.S") // The asm flag will be applied here
450
+ /// .file("src/bar.c") // The asm flag will not be applied here
451
+ /// .compile("foo");
452
+ /// ```
453
+ pub fn asm_flag ( & mut self , flag : & str ) -> & mut Build {
454
+ self . asm_flags . push ( flag. to_string ( ) ) ;
455
+ self
456
+ }
457
+
437
458
fn ensure_check_file ( & self ) -> Result < PathBuf , Error > {
438
459
let out_dir = self . get_out_dir ( ) ?;
439
460
let src = if self . cuda {
@@ -1318,7 +1339,7 @@ impl Build {
1318
1339
}
1319
1340
1320
1341
fn compile_object ( & self , obj : & Object ) -> Result < ( ) , Error > {
1321
- let is_asm = obj. src . extension ( ) . and_then ( |s| s . to_str ( ) ) == Some ( "asm" ) ;
1342
+ let is_asm = is_asm ( & obj. src ) ;
1322
1343
let target = self . get_target ( ) ?;
1323
1344
let msvc = target. contains ( "msvc" ) ;
1324
1345
let compiler = self . try_get_compiler ( ) ?;
@@ -1349,6 +1370,9 @@ impl Build {
1349
1370
if self . cuda && self . files . len ( ) > 1 {
1350
1371
cmd. arg ( "--device-c" ) ;
1351
1372
}
1373
+ if is_asm {
1374
+ cmd. args ( & self . asm_flags ) ;
1375
+ }
1352
1376
if compiler. family == ( ToolFamily :: Msvc { clang_cl : true } ) && !is_asm {
1353
1377
// #513: For `clang-cl`, separate flags/options from the input file.
1354
1378
// When cross-compiling macOS -> Windows, this avoids interpreting
@@ -3471,3 +3495,15 @@ fn which(tool: &Path) -> Option<PathBuf> {
3471
3495
return if check_exe ( & mut exe) { Some ( exe) } else { None } ;
3472
3496
} )
3473
3497
}
3498
+
3499
+ /// Check if the file's extension is either "asm" or "s", case insensitive.
3500
+ fn is_asm ( file : & Path ) -> bool {
3501
+ if let Some ( ext) = file. extension ( ) {
3502
+ if let Some ( ext) = ext. to_str ( ) {
3503
+ let ext = ext. to_lowercase ( ) ;
3504
+ return ext == "asm" || ext == "s" ;
3505
+ }
3506
+ }
3507
+
3508
+ false
3509
+ }
0 commit comments