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

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

Open
jaredramirez opened this issue Oct 30, 2020 · 1 comment
Open

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

jaredramirez opened this issue Oct 30, 2020 · 1 comment
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. docs enhancement Solving this issue will likely involve adding new logic or components to the codebase. zig build system std.Build, the build runner, `zig build` subcommand, package management
Milestone

Comments

@jaredramirez
Copy link

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!

@pfgithub
Copy link
Contributor

You can set obj.emit_llvm_ir = true and obj.emit_bin = true directly already. It would be useful if these had documentation comments though to make it clear that you are supposed to do that.

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

    obj.emit_llvm_ir = true;
    obj.emit_bin = true;

@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. zig build system std.Build, the build runner, `zig build` subcommand, package management labels Oct 30, 2020
@andrewrk andrewrk added this to the 0.8.0 milestone Oct 30, 2020
@andrewrk andrewrk added contributor friendly This issue is limited in scope and/or knowledge of Zig internals. docs labels Oct 30, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. docs enhancement Solving this issue will likely involve adding new logic or components to the codebase. zig build system std.Build, the build runner, `zig build` subcommand, package management
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants