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

#2415 /Zm20000 increases the available memory for macro expansion and… #2416

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ fn cpp_flags(compiler: &cc::Tool) -> &'static [&'static str] {
"/Zc:wchar_t",
"/Zc:forScope",
"/Zc:inline",
"/Zm2000",
// Warnings.
"/Wall",
"/wd4127", // C4127: conditional expression is constant
Expand Down Expand Up @@ -606,21 +607,23 @@ fn configure_cc(c: &mut cc::Build, target: &Target, c_root_dir: &Path, include_d
}
}


fn nasm(file: &Path, arch: &str, include_dir: &Path, out_dir: &Path, c_root_dir: &Path) {
let out_file = obj_path(out_dir, file);
let oformat = match arch {
x if x == X86_64 => "win64",
x if x == X86 => "win32",
x if x == X86 => "win32",
_ => panic!("unsupported arch: {}", arch),
};

// Nasm requires that the path end in a path separator.
let mut include_dir = include_dir.as_os_str().to_os_string();
include_dir.push(OsString::from(String::from(std::path::MAIN_SEPARATOR)));

let mut c = Command::new("./target/tools/windows/nasm/nasm");
let _ = c
.arg("-o")
let nasm_exe = get_nasm_executable();

let mut c = Command::new(nasm_exe);
c.arg("-o")
.arg(out_file.to_str().expect("Invalid path"))
.arg("-f")
.arg(oformat)
Expand All @@ -634,6 +637,31 @@ fn nasm(file: &Path, arch: &str, include_dir: &Path, out_dir: &Path, c_root_dir:
run_command(c);
}

fn get_nasm_executable() -> PathBuf {
// First, try the default target path.
let default_path = if cfg!(target_os = "windows") {
PathBuf::from("./target/tools/windows/nasm/nasm.exe")
} else {
PathBuf::from("./target/tools/windows/nasm/nasm")
};
if default_path.exists() {
return default_path;
}
// If the default isn't there, try to run "nasm" (or "nasm.exe" on Windows)
let fallback = if cfg!(target_os = "windows") {
"nasm.exe"
} else {
"nasm"
};
// Try executing fallback with --version to see if it is available.
if let Ok(output) = Command::new(fallback).arg("--version").output() {
if output.status.success() {
return PathBuf::from(fallback);
}
}
panic!("Nasm executable not found. Please install NASM or ensure it is available in your PATH.");
}

fn run_command_with_args(command_name: &Path, args: &[OsString]) {
let mut cmd = Command::new(command_name);
let _ = cmd.args(args);
Expand Down