@@ -1339,12 +1339,14 @@ impl Build {
13391339 }
13401340
13411341 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 ( ) ;
13431344 let target = self . get_target ( ) ?;
13441345 let msvc = target. contains ( "msvc" ) ;
13451346 let compiler = self . try_get_compiler ( ) ?;
13461347 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 ) {
13481350 self . msvc_macro_assembler ( ) ?
13491351 } else {
13501352 let mut cmd = compiler. to_command ( ) ;
@@ -3496,14 +3498,27 @@ fn which(tool: &Path) -> Option<PathBuf> {
34963498 } )
34973499}
34983500
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+ }
35053521 }
3522+ None
35063523 }
3507-
3508- false
35093524}
0 commit comments