Jetzig (and http.zig) with zig 0.16

I need to create a web HTTP API (it will live behind an nginx proxy, so plain HTTP is fine). I would love to use something like Jetzig – it seems appropriate for my purposes; however, I have been unable to make it run with zig 0.16.

The project’s web page says Jetzig tries to track zig master, but the last update was three months ago. Am I doing something obviously stupid, or has Jetzig not been updated to 0.16? And if the latter, are there any plans to update it?

I don’t know the status of Jetzig, but it uses http.zig behind the scenes, and that project is on 0.16. Maybe you can use http.zig directly if all you need is an http rest api behind a reverse proxy?

1 Like

Thanks for the suggestion @cryptocode , I will look into http.zig and report back.

Jetzig has some work to do. I’ve followed Jetzig for a while now, and it appears that the original dev stopped working on it around the release of 0.15, and now it’s being worked on by another person sort of on and off. So development seems to be continued, but slowly, and it’s unfortunatly not really usable. The current dev is active on the Jetzig Discord though, and seems to genuinely want to see Jetzig development continue, so hopefully it gets to a usable state again.

EDIT: None of this is hopefully seen as a knock on anyone who is/has worked on Jetzig, there’s a lot of work to be done getting it to 0.16, and I am very appreciative of the work @bobf and @cohors have done on it. Probably wouldn’t be doing much programming, let alone Zig programming, if not for Jetzig and their contributions :folded_hands:

2 Likes

Ok, followed the instructions for httpz and am seeing these errors:

❯ zig build run
run
└─ run exe server
   └─ compile exe server Debug native 2 errors
error: fatal linker error: unhandled relocation type R_X86_64_PC64 at offset 0x1c
    note: in /usr/lib/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../lib/crt1.o:.sframe
error: fatal linker error: unhandled relocation type R_X86_64_PC64 at offset 0x2c
    note: in /usr/lib/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../lib/crt1.o:.sframe
error: 2 compilation errors

My system:

OS: Arch Linux x86_64
Kernel: Linux 6.19.13-arch1-1
zig version: 0.16.0

This is my first try with 0.16, so I’m sure I’m holding it wrong. Happy to hear any advice. Cheers!

BTW, if I comment these lines out in my build.zig, the linker errors go away:

    // const httpz = b.dependency("httpz", .{
    //     .target = target,
    //     .optimize = optimize,
    // });

    const exe = b.addExecutable(.{
        .name = "server",
        .root_module = b.createModule(.{
            .root_source_file = b.path("src/main.zig"),
            .target = target,
            .optimize = optimize,
            .imports = &.{
                .{ .name = "server", .module = mod },
                // .{ .name = "httpz", .module = httpz.module("httpz") },
            },
        }),
    });
    b.installArtifact(exe);

Following https://codeberg.org/ziglang/zig/issues/31272, if I compile with --release=fast the problem disappears.

1 Like

Indeed, http.zig is perfect for my needs. Thanks for the suggestion!

1 Like