How to get zig build to dump disassembly

I’d like to look at the generated machine code but not sure how to enable zig build to output disassembly. I’m working on Windows.

zig build-exe some.zig -femit-asm
it’s on linux but I believe should work on Windows too.

Thanks. I’m building a project with a build.zig, so I wonder if there’s an equivalent when using zig build?


pub fn build(b: * void {

    const target = b.standardTargetOptions(.{});
    const mode = b.standardReleaseOptions();
    const exe = b.addExecutable("zf", "src/main.zig");
    exe.single_threaded = true;
    exe.emit_asm = .emit; // <<<<<<<<<<<<<<<
1 Like

It’s a tagged union defined in zig-0.10.1/lib/std/build.zig:

    pub const EmitOption = union(enum) {
        default: void,
        no_emit: void,
        emit: void,
        emit_to: []const u8,

Thanks! I set this to a library I’m building but I don’t know where the output goes. There’s no .s or .asm files anywhere after rebuilding. :slight_smile: I guess I’ll try on Linux, see if I can get it to work there first.

In my case it is in the root of the project:

$ ls -1
zf.s  <<<<<<<<<<
1 Like

Did you try

zig build-lib ... -femit-asm
zig build-obj ... -femit-asm


That worked for producing asm output for the library root source file. But looks like it doesn’t contain the other source files than the root.

btw, I asked similar question some time ago