Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only pass .asm files to masm #755

Merged
merged 1 commit into from Nov 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 25 additions & 10 deletions src/lib.rs
Expand Up @@ -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();
Expand Down Expand Up @@ -3496,14 +3498,27 @@ fn which(tool: &Path) -> Option<PathBuf> {
})
}

/// 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 MSVC 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 MSVC targets.
DotS,
}

impl AsmFileExt {
fn from_path(file: &Path) -> Option<Self> {
if let Some(ext) = file.extension() {
if let Some(ext) = ext.to_str() {
let ext = ext.to_lowercase();
match &*ext {
"asm" => return Some(AsmFileExt::DotAsm),
"s" => return Some(AsmFileExt::DotS),
_ => return None,
}
}
}
None
}

false
}