Three file example:
a.zig:
const b = @import("b");
pub fn main() void { b.something(); }
b.zig:
const c = @import("c");
pub fn something() void { c.something(); }
c.zig:
pub fn something() void { }
build.zig:
const std = @import("std");
pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "a",
.root_source_file = .{ .path = "a.zig" },
.optimize = optimize,
});
const mod_c = b.addModule("c", .{
.source_file = .{ .path = "c.zig" },
});
const mod_b = b.addModule("b", .{
.source_file = .{ .path = "b.zig" },
.dependencies = &.{
.{
.name = "c",
.module = mod_c,
},
},
});
exe.addModule("b", mod_b);
b.default_step.dependOn(&exe.step);
}
When using zig build I get:
b.zig:1:11: error: unable to find 'c'
const c = @import("c");
I've looked around in build.zig, but it doesn't seem like there is a way to add package path c.zig to b. Actually, it seems that build.zig just passes the info to the zig compiler through command line args:
zig build-exe a.zig --cache-dir zig-cache --output zig-cache/a --name a --pkg-begin b b.zig --pkg-end --pkg-begin c c.zig --pkg-end
Three file example:
a.zig:b.zig:c.zig:build.zig:When using
zig buildI get:I've looked around in
build.zig, but it doesn't seem like there is a way to add package pathc.zigtob. Actually, it seems thatbuild.zigjust passes the info to the zig compiler through command line args: