From 328c2dcdd1d15d6a2eaf92381244eef8a964b1d3 Mon Sep 17 00:00:00 2001 From: Thom Chiovoloni Date: Wed, 23 Nov 2022 01:32:19 -0800 Subject: [PATCH] Only pass `.asm` files to masm --- src/lib.rs | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 486d67e0b..9463e2e68 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1339,12 +1339,14 @@ impl Build { } fn compile_object(&self, obj: &Object) -> Result<(), Error> { - let is_asm = is_asm(&obj.src); + let asm_ext = AsmFileExt::from_path(&obj.src); + let is_asm = asm_ext.is_some(); let target = self.get_target()?; let msvc = target.contains("msvc"); let compiler = self.try_get_compiler()?; let clang = compiler.family == ToolFamily::Clang; - let (mut cmd, name) = if msvc && is_asm { + + let (mut cmd, name) = if msvc && asm_ext == Some(AsmFileExt::DotAsm) { self.msvc_macro_assembler()? } else { let mut cmd = compiler.to_command(); @@ -3496,14 +3498,27 @@ fn which(tool: &Path) -> Option { }) } -/// Check if the file's extension is either "asm" or "s", case insensitive. -fn is_asm(file: &Path) -> bool { - if let Some(ext) = file.extension() { - if let Some(ext) = ext.to_str() { - let ext = ext.to_lowercase(); - return ext == "asm" || ext == "s"; +#[derive(Clone, Copy, PartialEq)] +enum AsmFileExt { + /// `.asm` files. On windows targets, we assume these should be passed to + /// MASM (`ml{,64}.exe`). + DotAsm, + /// `.s` or `.S` files, which do not have the special handling on windows. + DotS, +} + +impl AsmFileExt { + fn from_path(file: &Path) -> Option { + if let Some(ext) = file.extension() { + if let Some(ext) = ext.to_str() { + let ext = ext.to_lowercase(); + match &*ext { + "asm" => return Some(Self::DotAsm), + "s" => return Some(Self::DotS), + _ => return None, + } + } } + None } - - false }