@@ -1339,12 +1339,14 @@ impl Build {
1339
1339
}
1340
1340
1341
1341
fn compile_object ( & self , obj : & Object ) -> Result < ( ) , Error > {
1342
- let is_asm = is_asm ( & obj. src ) ;
1342
+ let asm_ext = AsmFileExt :: from_path ( & obj. src ) ;
1343
+ let is_asm = asm_ext. is_some ( ) ;
1343
1344
let target = self . get_target ( ) ?;
1344
1345
let msvc = target. contains ( "msvc" ) ;
1345
1346
let compiler = self . try_get_compiler ( ) ?;
1346
1347
let clang = compiler. family == ToolFamily :: Clang ;
1347
- let ( mut cmd, name) = if msvc && is_asm {
1348
+
1349
+ let ( mut cmd, name) = if msvc && asm_ext == Some ( AsmFileExt :: DotAsm ) {
1348
1350
self . msvc_macro_assembler ( ) ?
1349
1351
} else {
1350
1352
let mut cmd = compiler. to_command ( ) ;
@@ -3496,14 +3498,27 @@ fn which(tool: &Path) -> Option<PathBuf> {
3496
3498
} )
3497
3499
}
3498
3500
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" ;
3501
+ #[ derive( Clone , Copy , PartialEq ) ]
3502
+ enum AsmFileExt {
3503
+ /// `.asm` files. On MSVC targets, we assume these should be passed to MASM
3504
+ /// (`ml{,64}.exe`).
3505
+ DotAsm ,
3506
+ /// `.s` or `.S` files, which do not have the special handling on MSVC targets.
3507
+ DotS ,
3508
+ }
3509
+
3510
+ impl AsmFileExt {
3511
+ fn from_path ( file : & Path ) -> Option < Self > {
3512
+ if let Some ( ext) = file. extension ( ) {
3513
+ if let Some ( ext) = ext. to_str ( ) {
3514
+ let ext = ext. to_lowercase ( ) ;
3515
+ match & * ext {
3516
+ "asm" => return Some ( AsmFileExt :: DotAsm ) ,
3517
+ "s" => return Some ( AsmFileExt :: DotS ) ,
3518
+ _ => return None ,
3519
+ }
3520
+ }
3505
3521
}
3522
+ None
3506
3523
}
3507
-
3508
- false
3509
3524
}
0 commit comments