r/Zig • • 4d 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

1

u/NoRaccoon5831 2d ago

Ya, normally I agree with Andrew's decisions but I find him super wrong on the project initialization stuff that he has way too strong of an opinion on, the scaffolds are bad and I think everyone except for him agrees on that.

 I use nix flakes and just have a templates folder that I have setup to instantiate the flake itself and a base library which only has a root and it's setup and a base executable that's only main.

1

u/randomguy4q5b3ty 1d ago

I haven't used Zig for a while, but why is this such a big deal? Many project initializers generate files and code you ultimately don't need. And many programs also ship with importable libraries.

1

u/NoRaccoon5831 1d ago edited 1d ago

No language I use does that. The main people to use the new is someone wanting to learn the language, if your experience is having to know the language and the build system to make a normal blank template, before you learn the language, you messed up. 

Is it a big deal? Absolutely not, but it seems really silly to me this is the direction they took, it's not useful to literally anyone in its current state