#How to set build.zig to generate a bin file in zig 0.11.0
1 messages · Page 1 of 1 (latest)
need more context
what do you mean by generate?
is there something specific that isn't working?
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
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);
nice, but seems need more steps to get bin file
const _bin = elf.addObjCopy(.{ .format = .bin });
const bin = b.addInstallBinFile(_bin.getOutputSource(), "zig-program.bin");
b.getInstallStep().dependOn(&bin.step);
You can also use installBinFile only