generate command
zigmod generate
- This command takes no parameters and will generate a
deps.zigin the root of your project. This is the file that you will then import into yourbuild.zigto automatically add all the necessary packages and (any) C code that may be in your dependencies. - This behavior is similar to
zigmod fetchbut it does the fetching of dependencies indeps.zigitself to enable your users to only needzig build(and optionallygit). - You as an program author will still need
zigmodinstalled during development, but consumers of your app can get started with only agit cloneandzig build! - To this end, a
deps.zigmade by runningzigmod generatewill want to be checked into source control. Don’t forget to remove it from.gitignore. - The version of dependencies fetched by
deps.zigfrom this command is based on yourzigmod.lockso no surprise breaks from users.
For a full reference on the fields available in deps.zig you can check here.
Adding deps.zig to your build.zig
const std = @import("std");
+const deps = @import("./deps.zig");
pub fn build(b: *std.build.Builder) void {
const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions();
const exe = b.addExecutable("hello", "src/main.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
+ deps.addAllTo(exe);
exe.install();
If you don’t want Zigmod to handle adding packages to your project and only do resource fetching then deps.fetch(exe) may be called independently of deps.addAllTo(exe).
deps.addAllTo(exe) will call deps.fetch(exe) inside of it, so as to be compatible with deps.zig generated by zigmod fetch.