aboutsummaryrefslogtreecommitdiff
path: root/lib/init/build.zig
AgeCommit message (Collapse)Author
2025-08-24fix: fix typo in comment by removing repeated 'business' wordNathaniel Ketema
2025-07-25init: replace '--strip' with '--minimal'mlugg
This option never worked properly (it emitted wrongly-formatted code), and it doesn't seem particularly *useful* -- someone who's proficient enough with `std.Build` to not need explanations probably just wants to write their own thing. Meanwhile, the use case of writing your own `build.zig` was extremely poorly served, because `build.zig.zon` *needs* to be generated programmatically for a correct `fingerprint`, but the only ways to do that were to a) do it wrong and get an error, or b) get the full init template and delete the vast majority of it. Both of these were pretty clunky, and `-s` didn't really help. So, replace this flag with a new one, `--minimal`/`-m`, which uses a different template. This template is trivial enough that I opted to just hardcode it into the compiler for simplicity. The main job of `zig init -m` is to generate a correct `build.zig.zon` (if it is unable to do this, it exits with a fatal error). In addition, it will *attempt* to generate a tiny stub `build.zig`, with only an `std` import and an empty `pub fn build`. However, if `build.zig` already exists, it will avoid overwriting it, and doesn't even complain. This serves the use case of writing `build.zig` manually and *then* running `zig init -m` to generate an appropriate `build.zig.zon`.
2025-06-13zig init: simplify templating logic (#24170)Loris Cro
and also rename `advancedPrint` to `bufferedPrint` in the zig init templates These are left overs from my previous changes to zig init. The new templating system removes LITNAME because the new restrictions on package names make it redundant with NAME, and the use of underscores for marking templated identifiers lets us template variable names while still keeping zig fmt happy.
2025-06-02zig init: add new --strip flag and improve template filesLoris Cro
This commit introduces a new flag to generate a new Zig project using `zig init` without comments for users who are already familiar with the Zig build system. Additionally, the generated files are now different. Previously we would generate a set of files that defined a static library and an executable, which real-life experience has shown to cause confusion to newcomers. The new template generates one Zig module and one executable both in order to accommodate the two most common use cases, but also to suggest that a library could use a CLI tool (e.g. a parser library could use a CLI tool that provides syntax checking) and vice-versa a CLI tool might want to expose its core functionality as a Zig module. All references to C interoperability are removed from the template under the assumption that if you're tall enough to do C interop, you're also tall enough to find your way around the build system. Experienced users will still be able to use the current template and adapt it with minimal changes in order to perform more advanced operations. As an example, one only needs to change `b.addExecutable` to `b.addLibrary` to switch from generating an executable to a dynamic (or static) library.
2025-02-26zig init: adjust template lang to allow zig fmt passthroughAndrew Kelley
2025-02-26introduce package id and redo hash format againAndrew Kelley
Introduces the `id` field to `build.zig.zon`. Together with name, this represents a globally unique package identifier. This field should be initialized with a 16-bit random number when the package is first created, and then *never change*. This allows Zig to unambiguously detect when one package is an updated version of another. When forking a Zig project, this id should be regenerated with a new random number if the upstream project is still maintained. Otherwise, the fork is *hostile*, attempting to take control over the original project's identity. `0x0000` is invalid because it obviously means a random number wasn't used. `0xffff` is reserved to represent "naked" packages. Tracking issue #14288 Additionally: * Fix bad path in error messages regarding build.zig.zon file. * Manifest validates that `name` and `version` field of build.zig.zon are maximum 32 bytes. * Introduce error for root package to not switch to enum literal for name. * Introduce error for root package to omit `id`. * Update init template to generate `id` * Update init template to populate `minimum_zig_version`. * New package hash format changes: - name and version limited to 32 bytes via error rather than truncation - truncate sha256 to 192 bits rather than 40 bits - include the package id This means that, given only the package hashes for a complete dependency tree, it is possible to perform version selection and know the final size on disk, without doing any fetching whatsoever. This prevents wasted bandwidth since package versions not selected do not need to be fetched.
2025-01-22std.Build: add `addLibrary` function (#22554)BratishkaErik
Acts as a replacement for `addSharedLibrary` and `addStaticLibrary`, but linking mode can be changed more easily in build.zig, for example: In library: ```zig const linkage = b.option(std.builtin.LinkMode, "linkage", "Link mode for a foo_bar library") orelse .static; // or other default const lib = b.addLibrary(.{ .linkage = linkage, .name = "foo_bar", .root_module = mod, }); ``` In consumer: ```zig const dep_foo_bar = b.dependency("foo_bar", .{ .target = target, .optimize = optimize, .linkage = .static // or dynamic }); mod.linkLibrary(dep_foor_bar.artifact("foo_bar")); ``` It also matches nicely with `linkLibrary` name. Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
2024-12-18init template: expand slightly, migrate from deprecated std.Build APIsmlugg
2024-04-15zig init: Replace deprecated LazyPath.path with Build.path()Linus Groh
2023-11-20merge `zig init-exe` and `zig init-lib` into `zig init`Andrew Kelley
Instead of `zig init-lib` and `zig init-exe`, now there is only `zig init`, which initializes any of the template files that do not already exist, and makes a package that contains both an executable and a static library. The idea is that the user can delete whatever they don't want. In fact, I think even more things should be added to the build.zig template.