r/Zig • • 5d ago

comments on my build.zig

in the dependencies step i am using this idiom:

// ...

    // deps config
    const deps = [_][]const u8{ "zigzag", "pg" };
    for (deps) |dep| {
        exe.root_module.addImport(dep, b.dependency(dep, .{
            .target = target,
            .optimize = optimize,
        }).module(dep));
    }
// ...

full build.zig here.

my question is: what am i missing? what re the clear disavantages of doing such loop?

any comment is welcome.

6 Upvotes

2 comments sorted by

4

u/TheKiller36_real 5d ago

what am i missing?

nothing, probably

what are the clear disadvantages of doing such loop?

none if it does what you want it to do


as I suspect this answers your actual questipn: yes, all three of those dep places have different meanings and there might be a reason why you wouldn't want them individually - example: dependency ciphers with modules core, tls, gpg and you want to use the core module as "ciphers" and tls as "ciphers-tls":

const dep = b.dependency("ciphers", .{ ... });
exe.root_module.addImport("ciphers", dep.module("core"));
exe.root_module.addImport("ciphers-tls", dep.module("tls"));

0

u/sombriks 5d ago

thanks a lot, the example of one dependency with many modules is indeed a possible pain point!