Liza: Zig codebase initializer

Hi everyone!

I’ve been reusing a few Zig project patterns when staring a new repo, so I decided to combine them into a “templated” alternative to zig init.

Hope you find it useful! Feedback and questions are welcome as always!

13 Likes

Great name - Liza, haha. I will definitely give this a star when I get signed in after work.

1 Like

I think it’s really cool, If I may give one suggestion, it would be to add to the .gitignore, also rules for everything related to C and C dependency, as Zig is meant to be used with C/C libraries.

1 Like

Thanks!

Well, the only C-related files that makes sense to put in a .gitignore are the compiled ones, like pre-compiled headers, static/shared libraries and executables. But I’ve never seen those in a .gitignore file belonging to a Zig codebase and for a good reason – every compiled C or Zig file is meant to end up in zig-out/. That’s why the current .gitignore is already exhaustive for a standard Zig project.

3 Likes

Added a Zig port template for packaging C codebases like the ones @allyoucodebase. Btw, how can someone maintain a codebase there? I could contribute this one.

Really cool. I somehow did not know up until now that you could download the sources from a repo that doesn’t contain a build.zig/build.zig.zon using Zig’s package manager…

1 Like

I’ve invited you to the organization, feel free to move over any C project that you deem appropriate.

There is no specific procedure to invite people to the org yet.

1 Like

Hey, I’ve changed quite a few things recently! Thought I’d write up a changelog ahead of tagging the next version with Zig v0.14.0.

Main Changes

  • Fixed bugs:

    • Renamed lib.zig to root.zig, since Autodoc expects modules to have either a root.zig or a <package_name>.zig (see zig/lib/docs/wasm/main.zig).
  • Added new options:

    • -r: CI/CD runner type: github, forgejo, woodpecker (default: github).
    • -o: Output directory path (default: ./).
    • --add-doc: Add documentation to exe or lib (add doc step, add CD workflow).
    • --add-cov: Add code coverage to exe or lib (add cov step, edit CI workflow, edit .gitignore).
  • Updated templates:

    • Added Mach application template based on the official one.
    • Renamed Zig port template (prt) to Zig build template (bld).
    • Added CI/CD workflows for Codeberg: Forgejo Actions (very experimental since it’s in Beta) and Woodpecker (pretty hacky atm).
    • Downgraded to ubuntu-22.04 for GitHub CI kcov runs, since kcov is missing in ubuntu-24.04.
  • Other features:

    • Determining the version of user’s global Zig installation in order to populate .minimum_zig_version and decide which Zig version to set up for CI/CD.
  • Updated to Zig master in preparation for v0.14.0:

    • Using .root_module in options for addExecutable(), etc.
    • Using std.heap.DebugAllocator instead of GPA.

Planned changes before Zig v0.14.0 (depending on if they land):

  • Update std.heap.DebugAllocator usage sites to std.heap.DefaultAllocator (kinda hope it’s called GeneralPurposeAllocator since it fits and I like gpa as a variable name).

  • Reuse build.zig.zon data in build.zig with @import("build.zig.zon") and also expose build.zig.zon as a module to the executable/library source code.

2 Likes

Added GitHub Release workflow for executable codebases:

  • windows binary is zipped
  • macos/linux binaries are tar.xzipped
  • aarch64-macos is a universal bundle, so it’ll run on x86_64-macos, too

Here’s what it looks like:

1 Like

Separated executable’s installation and running into exe and run steps, respectively. Likewise, for example suite’s installation (example) and running (example-run).

Added a list of build step descriptions for all templates to the root README, so that you could get an idea of what each template’s build.zig provides, in order of declaration.

Edit: I see now that argzon is needed for the default exe stuff. So I guess this is expected.


@tensorush This is a really cool project. I was playing around with the code to add a --add-check flag, but found that currently if I build from the main branch I get this error when running zig build after initializing.

thread 11887 panic: no dependency named 'argzon' in '/home/tyler/projects/test_liza/build.zig.zon'. All packages used in build.zig must be declared in this file
/home/tyler/.local/bin/zig-linux-x86_64-0.14.0/lib/std/Build.zig:2159:20: 0x14bf008 in findPkgHashOrFatal (build)
    std.debug.panic("no dependency named '{s}' in '{s}'. All packages used in build.zig must be declared in this file", .{ name, full_path });
                   ^
/home/tyler/.local/bin/zig-linux-x86_64-0.14.0/lib/std/Build.zig:2222:40: 0x14a207c in dependency__anon_27600 (build)
    const pkg_hash = findPkgHashOrFatal(b, name);
                                       ^
/home/tyler/projects/test_liza/build.zig:15:36: 0x14a0357 in build (build)
    const argzon_dep = b.dependency("argzon", .{
                                   ^
/home/tyler/.local/bin/zig-linux-x86_64-0.14.0/lib/std/Build.zig:2428:44: 0x1491a94 in runBuild__anon_24596 (build)
        .error_union => try build_zig.build(b),
                                           ^
/home/tyler/.local/bin/zig-linux-x86_64-0.14.0/lib/compiler/build_runner.zig:339:29: 0x148a671 in main (build)
        try builder.runBuild(root);
                            ^
/home/tyler/.local/bin/zig-linux-x86_64-0.14.0/lib/std/start.zig:656:37: 0x1478d4a in posixCallMainAndExit (build)
            const result = root.main() catch |err| {
                                    ^
/home/tyler/.local/bin/zig-linux-x86_64-0.14.0/lib/std/start.zig:271:5: 0x14788fd in _start (build)
    asm volatile (switch (native_arch) {
    ^
???:?:?: 0x0 in ??? (???)
error: the following build command crashed:
/home/tyler/projects/test_liza/.zig-cache/o/c133feecc31c3962d9a7710dc806eab6/build /home/tyler/.local/bin/zig-linux-x86_64-0.14.0/zig /home/tyler/.local/bin/zig-linux-x86_64-0.14.0/lib /home/tyler/projects/test_liza /home/tyler/projects/test_liza/.zig-cache /home/tyler/.cache/zig --seed 0x665f9b1a -Z97eaae729d8df3df

Is argzon expected to be a dependency of everything if i use this tool or is this a bug? Wanted to check here before submitting a bug report.

1 Like

Thanks!

Yeah, exe template demonstrates CLI argument parsing with argzon. So it has a dependency which you have to fetch. The build.zig.zon has an example of the correct fetching command.

1 Like