Skip to content

Instantly share code, notes, and snippets.

@layneson
Created April 15, 2020 15:33
Show Gist options
  • Save layneson/e0ed54f9e14da878dd0ba102da41e2c3 to your computer and use it in GitHub Desktop.
Save layneson/e0ed54f9e14da878dd0ba102da41e2c3 to your computer and use it in GitHub Desktop.
Custom step in build.zig
const std = @import("std");
const Builder = std.build.Builder;
const Step = std.build.Step;
pub fn build(b: *Builder) void {
const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions();
const exe = b.addExecutable("hw", "hw.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
exe.install();
var my_build = b.allocator.create(MyBuildStep) catch unreachable;
my_build.* = MyBuildStep.init(b.allocator, 15);
my_build.step.dependOn(&exe.step);
b.default_step.dependOn(&my_build.step);
}
const MyBuildStep = struct {
step: Step,
some_variable: i32,
pub fn init(allocator: *std.mem.Allocator, some_variable: i32) MyBuildStep {
return .{
.step = Step.init("my build", allocator, MyBuildStep.doStep),
.some_variable = some_variable,
};
}
pub fn doStep(step: *Step) anyerror!void {
const self = @fieldParentPtr(MyBuildStep, "step", step);
// self is a MyBuildStep.
// Do something with self.some_variable.
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment