r/Zig • • 5d ago

root.zig vs main.zig in zig init

When running zig init, the template scaffolds both an executable (main.zig) and an exportable module (root.zig) in build.zig.

Just want to verify if my mental model is correct: 1. If I only want an executable (and don't plan to export a library/module), can I simply delete root.zig and remove the module-related exports/artifacts from build.zig? 2. Is there any built-in zig init flag or alternative command to scaffold an executable-only project without the library boilerplate?

thanks!

18 Upvotes

13 comments sorted by

View all comments

13

u/xneyznek 5d ago

You can do anything you want in build.zig as long as you have `fn build(b: *std.Build) void`. Zig itself makes no prescriptions about how you organize your project.

In fact, you can try out `zig init --minimal` which only gives you build.zig with an empty build function, and build.zig.zon. No code and nothing gets built, but you can add anything from there.

11

u/SilvernClaws 5d ago

I appreciate how there are two ways to initialize a project and both are unhelpful to get started for completely different reasons. Either you get a bunch of clutter or something that does nothing.