| 1 | ## `generate` command |
| 2 | ``` |
| 3 | zigmod generate |
| 4 | ``` |
| 5 | |
| 6 | - This command takes no parameters and will generate a `deps.zig` in the root of your project. This is the file that you will then import into your `build.zig` to automatically add all the necessary packages and (any) C code that may be in your dependencies. |
| 7 | - This behavior is similar to [`zigmod fetch`](./fetch.md) but it does the fetching of dependencies in `deps.zig` itself to enable your users to only need `zig build` (and optionally `git`). |
| 8 | - You as an program author will still need `zigmod` installed during development, but consumers of your app can get started with only a `git clone` and `zig build`! |
| 9 | - To this end, a `deps.zig` made by running `zigmod generate` *will* want to be checked into source control. Don't forget to remove it from `.gitignore`. |
| 10 | - The version of dependencies fetched by `deps.zig` from this command is based on your `zigmod.lock` so no surprise breaks from users. |
| 11 | |
| 12 | For a full reference on the fields available in `deps.zig` you can check [here](../deps.zig.md). |
| 13 | |
| 14 | ### Adding `deps.zig` to your `build.zig` |
| 15 | ```diff |
| 16 | const std = @import("std"); |
| 17 | +const deps = @import("./deps.zig"); |
| 18 | |
| 19 | pub fn build(b: *std.build.Builder) void { |
| 20 | const target = b.standardTargetOptions(.{}); |
| 21 | |
| 22 | const mode = b.standardReleaseOptions(); |
| 23 | |
| 24 | const exe = b.addExecutable("hello", "src/main.zig"); |
| 25 | exe.setTarget(target); |
| 26 | exe.setBuildMode(mode); |
| 27 | + deps.addAllTo(exe); |
| 28 | exe.install(); |
| 29 | ``` |
| 30 | |
| 31 | 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)`. |
| 32 | |
| 33 | `deps.addAllTo(exe)` will call `deps.fetch(exe)` inside of it, so as to be compatible with `deps.zig` generated by `zigmod fetch`. |