#How to set build.zig to generate a bin file in zig 0.11.0

1 messages · Page 1 of 1 (latest)

lofty vortex
#

In 0.10.1, "addInstallRaw" works fine...

hot fog
#

need more context

#

what do you mean by generate?

#

is there something specific that isn't working?

teal briar
#
pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const exe = b.addExecutable(.{
        .name = "main",
        .root_source_file = .{ .path = "src/main.zig" },
        .target = target,
        .optimize = optimize,
    });

    const bin = exe.addObjCopy(.{
        .format = .bin
    });

    const objcopy = b.step("objcopy", "create bin file");
    b.default_step = objcopy;
    objcopy.dependOn(&exe.step);
    objcopy.dependOn(&bin.step);
}

This will produce bin using zig build

lofty vortex
# hot fog need more context

this:

    // With `addInstallRaw()` I tell the build system that I want to generate a
    // raw binary image from the ELF executable we generated above. This is the
    // binary the Pi 3 can run. I make this "bin generation step" a dependency
    // of the default "install step" so that it gets executed on a regular
    // `zig build`.
    const bin = b.addInstallRaw(exe, "kernel7.img", .{});
    b.getInstallStep().dependOn(&bin.step);
lofty vortex
teal briar
#

You can also use installBinFile only