Hi! I'm just getting started with Zig and liking the design so far, well done! Running:
$ zig init-exe
$ zig build
I expected the executable to appear in a target/debug directory or something comparable, but (seemingly) nothing happened. Reading https://github.com/ziglang/zig/pull/2038 my understanding is that one should use zig build install --prefix target to achieve this (or modify build.zig / search through zig-cache). It's a bit unexpected coming from other build tools like Maven / Cargo that define a default build output directory, so following the principle of least astonishment, it might make sense for Zig to do the same.
More generally, a default project layout reduces cognitive overhead and allows things like .gitignore to be written once. Ideally, build.zig would be basically empty, with defaults being good enough for most projects. But that's probably another issue, having a default output directory would be a good step in that direction and also help developers getting started.
Hi @zimmi, thanks for taking the time to file this issue. I've been meaning to fix this for a while now, and I think it's time now. The install target with a nice default for prefix is going to become the default step. That will cause target/debug directory or equivalent to show up as you noted.
Here are some notable changes that I just pushed:
install and uninstall steps are always available now; never missing.install is now the default step. The default step can be changed with b.default_step = some_other_step;.zig-cache by default) is now the default install prefix. This means your installed binaries will be available by default in ./zig-cache/bin/.install() method. b.installArtifact(artifact) is now deprecated in favor of this.b.setPreferredReleaseMode for when the application has a preference about which release build mode is appropriate. It provides the -Drelease option rather than -Drelease-safe, -Drelease-small, -Drelease-fast. This function must be called before b.standardReleaseOptions.exe.run() steps will execute the binary from the install directory rather than the cache system.There should no longer be any reason to use setOutputDir.
That's much better, thanks!
It seems like calling the folder zig-cache is no longer accurate though, because it is doing double duty as a target folder now. But I'm sure this won't be the last iteration on the road to 1.0.0, so thanks again!
Most helpful comment
Hi @zimmi, thanks for taking the time to file this issue. I've been meaning to fix this for a while now, and I think it's time now. The
installtarget with a nice default for prefix is going to become the default step. That will causetarget/debugdirectory or equivalent to show up as you noted.