But you don’t actually do that, instead you call printFoo
in your build.zig
:
Using functions imported from a dependencies build.zig
is only for special cases (like here Importing custom modules in build.zig (outside fn build) - #3 by Sze), not for building normal applications, but instead to create helper functions that help while building the project.
Here you just want to embed some text inside something you are building, that doesn’t require importing the build.zig
of any dependency.
I think instead your importing project should add the dependency normally:
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const example_dep = b.dependency("example_module", .{
.target = target,
.optimize = optimize,
});
const mod = b.createModule(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
mod.addImport("example_module", example_dep.module("example_module"));
const exe = b.addExecutable(.{
.name = "app",
.root_module = mod,
);
b.installArtifact(exe);
// run steps etc.
}
src/root.zig
:
const example_module = @import("example_module");
pub fn main() {
example_module.printFoo();
}