zig build --init should create a working hello world, and it should be in the test suite

Created on 2 Jun 2018  Â·  7Comments  Â·  Source: ziglang/zig

Right now the zig build --init template is bitrotted again. Fix it, and then let's update it so that it creates a working hello world example, and add that to the test suite.

bug enhancement

Most helpful comment

I went ahead with init-lib and init-exe.

@kyle-github Indeed zig build does support building any combination of executables and libraries, but I'm not sure how deep we want to get into providing code templates.

I think that "hello world" for executables and libraries goes a long way, perhaps as far as we need to go.

All 7 comments

@andrewrk Maybe also rename zig build --init to zig init. IMO zig init makes more sense, and other package managers (cargo, npm, nimble etc) use it.
zig init to create build.zig in the current dir.
zig init packagename to create a new dir packagename and place the build.zig inside it.

zig init sounds good. What about the fact that you should have to decide between a library or an executable?

  • Option 1

zig init-lib
zig init-exe

  • Option 2

zig build --init-lib
zig build --init-exe

I like option 1 because it forces the programer to think which init procedure they would like.

zig init — executable by default
zig init --lib — library

@viluon this is too much like rust and there are times that you can forget if lib or bin is the default. Option 1 is better because it forces the programer to think/choose.

When I am building a library, I find it useful to also create examples of using the library, so I tend to create single projects that build both library and executable artifacts. At least with CMake, this is possible, if clearly not the most easily supported option. Would this be allowed with this notation?

zig build --init-lib --init-exe

zig build --init=lib,exe

zig build --init=lib-shared,lib-static,exe-shared,exe-static

Personally I like the idea of separating the idea of initializing the project from the type of project it will be. That allows for future additions without quite as much additional syntax (though this is minor).

The built in test parts of zig make the utility of additional executables a bit less interesting, but I find that for any reasonably sized library, having a working example to start from is very handy.

I went ahead with init-lib and init-exe.

@kyle-github Indeed zig build does support building any combination of executables and libraries, but I'm not sure how deep we want to get into providing code templates.

I think that "hello world" for executables and libraries goes a long way, perhaps as far as we need to go.

Was this page helpful?
0 / 5 - 0 ratings