Cargo+nasm: nasm: error: more than one input file specified

I'm new to Rust and this is on OSX.

I have X86 assembly which normally assembles with nasm using a Makefile. The assembly line looks like:

nasm -f macho64 glue.s -o glue.o

I've rewritten my driver in Rust and that works. Now I'm trying to build everything with Cargo. My build.rs is a pretty straightforward copy of the example from Page Moved

// build.rs

use std::process::Command;
use std::path::Path;
use std::env;

fn main() {
let out_dir = env::var("OUT_DIR").unwrap();

Command::new("nasm").args(&["src/glue.s", "-fmacho64"])
                   .arg(&format!("{}/glue.o", out_dir))
                   .status().unwrap();

Command::new("ar").args(&["crus", "libglue.a", "glue.o"])
.current_dir(&Path::new(&out_dir))
.status().unwrap();

println!("cargo:rustc-link-search=native={}", out_dir);
println!("cargo:rustc-link-lib=static=glue");

}

This doesn't work. When I build it with cargo build -vv I get:

Running ..../build-script-build
nasm: error: more than one input file specified
type nasm -h' for help nasm: error: more than one input file specified type nasm -h' for help
ar: glue.o: No such file or directory

However, I have no idea why nasm is complaining about more than one input file specified. The -vv option doesn't print the offending nasm command just the error message (which is helpful). Again, my build.rs code looks very very similar to the example.

Chris

Well, I think I can answer my own question.
The output argument for nasm needs a -o argument:

Command::new("nasm").args(&["src/glue.s",   "-fmacho64", "-o"])
                   .arg(&format!("{}/glue.o", out_dir))
                   .status().unwrap();
1 Like

I am also using nasm in a build script, and almost wrote a crate for it to make it easier, but haven't yet. Maybe i'll do that; I'll let you know :smile:

Oh look, there is one: nasm-rs 0.0.6 - Docs.rs

and one that's defunct with a better name: https://crates.io/crates/nasm

Gonna email some people and see if we can fix this :smile:

1 Like