ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
31.96k stars 2.34k forks source link

Init templates #20363

Open Darkfllame opened 1 week ago

Darkfllame commented 1 week ago

So I was thinking about a thing that would be pretty convenient, init templates, basically let you save templates to use with zig init to have custom project templates. I though about a few commands for it:

The goal ? Some may find it pretty convenient, personally it would since, when initializing a new project, I always delete comments, delete src/root.zig and clean up the build file and src/main.zig, which I do a lot since I'm always restarting old projects and all.

I might get instant rejected but I just wanted to put this here. If this was already planned, then sorry but I didn't find any proposals about this and I don't remember it being on zig's "todo list".

To be honest, I don't know how I should format a proposal, and I'm kind of tired and a bit lazy so I'll just put this here like this.

paperdave commented 1 week ago

in the past there was zig init-exe and zig init-lib, which got merged into one. i don't know which issue or pr that was.

nektro commented 1 week ago

I'd personally recommend using https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-template-repository

Darkfllame commented 1 week ago

I'd personally recommend using https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-template-repository

No I mean a thing that is WITH the zig executable, so you wouldn't need other tools and more setup

BratishkaErik commented 1 week ago

in the past there was zig init-exe and zig init-lib, which got merged into one. i don't know which issue or pr that was.

https://github.com/ziglang/zig/pull/18055

hippietrail commented 6 days ago

I just started to look at making a zig init -m switch for myself to make a minimal template. I realized we create already create our own zig init template simply by replacing the four files in lib/init/ and lib/init/src/, but we're restricted to using those exact filenames and must use all of them.

I don't think that's supported/documented. But it would be a minor change to allow it and replace the logic which relies specifically on main.zig and root.zig and copy all .zig files, or even more minimally, to only copy root.zig if it's present in lib/init/src/.

jedisct1 commented 6 days ago

I'd love the ability to select between multiple, hard-coded templates: to build a library (no example code, no comments), an executable (same), both (same), a fully commented example (like the current template), a template to compile a C project, etc.