Skip to content

Commit

Permalink
build.rs: Restrict preassembly to nasm to simplify logic.
Browse files Browse the repository at this point in the history
Call `nasm` directly during preassembly. This leaves one caller each of
`compile()` and `new_build()`. Inline them into their single caller.
  • Loading branch information
briansmith committed Oct 5, 2023
1 parent 006f57b commit 83534d3
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,8 @@ fn pregenerate_asm_main() {
force_warnings_into_errors: true,
};

let mut b = new_build(&target, &pregenerated_tmp);
for src in srcs {
compile(&mut b, &src, &target, &pregenerated_tmp, &pregenerated);
nasm(&src, &target.arch, &pregenerated_tmp, &pregenerated);
}
}
}
Expand Down Expand Up @@ -486,24 +485,24 @@ fn build_c_code(
);
}

fn new_build(target: &Target, include_dir: &Path) -> cc::Build {
let mut b = cc::Build::new();
configure_cc(&mut b, target, include_dir);
b
}

fn build_library<'a>(
target: &Target,
out_dir: &Path,
lib_name: &str,
srcs: impl Iterator<Item = &'a PathBuf>,
preassembled_objs: &[PathBuf],
) {
let mut c = new_build(target, out_dir);
let mut c = cc::Build::new();
configure_cc(&mut c, target, out_dir);

// Compile all the (dirty) source files into object files.
srcs.for_each(|src| {
compile(&mut c, src, target, out_dir, out_dir);
if !matches!(src.extension(), Some(e) if e == "asm") {
let _ = c.file(src);
} else {
let obj = nasm(src, &target.arch, out_dir, out_dir);
let _ = c.object(obj);
}
});

preassembled_objs.iter().for_each(|obj| {
Expand Down Expand Up @@ -538,15 +537,6 @@ fn build_library<'a>(
println!("cargo:rustc-link-lib=static={}", lib_name);
}

fn compile(b: &mut cc::Build, p: &Path, target: &Target, include_dir: &Path, out_dir: &Path) {
if !matches!(p.extension(), Some(e) if e == "asm") {
let _ = b.file(p);
} else {
let obj = nasm(p, &target.arch, include_dir, out_dir);
let _ = b.object(obj);
}
}

fn obj_path(out_dir: &Path, src: &Path) -> PathBuf {
let mut out_path = out_dir.join(src.file_name().unwrap());
// To eliminate unnecessary conditional logic, use ".o" as the extension,
Expand Down

0 comments on commit 83534d3

Please sign in to comment.