This is just a way for myself to test out and document build.zig.zon
style dependency management. This repository is a zig project that depends on this repository as a dependency.
A dependency in build.zig.zon
system is effectively a namespace that's defined in the build.zig
file, mapping arbitrary names to sources files (and other sources files they import).
// build.zig
// ...
pub fn build(b: *std.Build) void {
_ = b.addModule(
"mymodulename",
.{ .source_file = .{ .path = "./src/hello.zig" } },
);
}
// ...
A zig project can refer to a remote dependency with an arbitrary field name in the .dependencies
field of build.zig.zon
.
build.zig.zon
.{
.name = "jomammad",
.version = "0.1.0",
.dependencies = .{
.hello = .{
.url = "https://github.com/maxsei/hello-zig-zon-pkg/archive/7b8f7278265a14e6879dd974bfe063a664524cb8.tar.gz",
.hash = "1220aa2cf330fb36da40119277f3d99e979e2bf8bc5042cec1aaff067e4c669bfa4f",
},
},
}
and can be included in build.zig
with:
// ...
const hello = b.dependency("hello", .{});
// ...
From there a dependency's modules can be included in zig build artifacts
exe.addModule("mymodulename", hello.module("hello"));
b.installArtifact(exe);
And imported via
@import("mymodulename")