Skip to content

Ability to control what Zig emits in build.zig #6871

@jaredramirez

Description

@jaredramirez

As far as I understand, right now you can't specify what Zig should emit in build.zig. I'd like to have the equivalent build.zig config for the command: zig build-obj src/main.zig -femit-llvm-ir -fno-emit-bin

Here's what I have in my build.zig

const Builder = @import("std").build.Builder;

pub fn build(b: *Builder) void {
    b.setPreferredReleaseMode(builtin.Mode.ReleaseFast);
    const mode = b.standardReleaseOptions();

    const obj = b.addObject("bitcode", "src/main.zig");
    obj.setBuildMode(mode);

    // Theses don't exist
    // obj.shouldEmitLLVMIR(true);
    // obj.shouldEmitBin(false);

    // test steps, etc
}

After looking in lib/std/build.zig, I think adding something like:

pub fn shouldEmitLLVMIR(self: *LibExeObjStep, should_emit: bool) void {
    self.emit_llvm_ir = should_emit;
}

pub fn shouldEmitBin(self: *LibExeObjStep, should_emit: bool) void {
    self.emit_bin = should_emit;
}

// etc for all other emit types

Then in make everything already seems setup to add the args!

If this is something you'd like, I can submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.docsenhancementSolving this issue will likely involve adding new logic or components to the codebase.zig build systemstd.Build, the build runner, `zig build` subcommand, package management

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions