I’m trying to write a zig package that implements complex build steps. Users will import this into their build.zig to get access to these custom steps.
Here is one of my steps that I am providing to users:
pub fn createLayer(b: *std.Build, options: CreateLayerOptions) *Layer {
const tar_cf_tool = b.addExecutable(.{
.name = "create_layer",
.root_module = b.createModule(.{
.root_source_file = b.path("src/build/create_layer.zig"),
.target = b.graph.host,
}),
});
// HACK: this is wack and won't work under other peoples projects
tar_cf_tool.root_module.addImport(
"oci",
b.createModule(
.{ .root_source_file = b.path("src/root.zig") },
),
);
const run = b.addRunArtifact(tar_cf_tool);
const blob = run.addOutputFileArg(switch (options.compression) {
.raw => "blob.tar",
.gzip => "blob.tar.gz",
});
...
There are a few problems as it is written:
b.pathwill not refer to my source files. It will refer to the user’s source files. (the user doesn’t have asrc/build/create_layer.zig, only I do.- same problem for my
b.createModule.
How do I fix this?