Cover image for Zig can do that to...?

Posted on

Zig can do that to...?

So I'm the kind of guy that gets bored doing the same old thing over and over, and recently that has led me to get pretty bored with python. Recently I've been playing around with Rust. I've spun up a discord bot or two. Played around with the Leptos framework, and generally had a good time with Rust.

That said It feels a bit... Heavy?

I've had my eye on zig for a few months now, and have found time to mess about with it here and there, and this weekend along with acquiring the domain th3r00t.dev decided id have a go at some wasm with zig.

I got all set up to decide what Javascript framework I would use to import the wasm into the browser when i found this site fermyon.com about serverless Web Assembly hosting, and tooling with spin.
This post about zig in particular is what caught my eye.
Zig in Web Assembly

It was pretty simple to get that all setup. Once I had that figured out I set about putting together my build.zig to setup everything I might need (yah right...) for setting up my personal site.

Including a currently useless include of the curl library, I put this in as I was trolling over a bunch of code, and guides id managed to search up. Many of which required searching the zig std library for what must have been some sweeping changes to the build system since most of the zig build related guides have been written.

For those who might be interested here is the build.zig I came up with.

const std = @import("std");
const Builder = std.build.Builder;
const RunStep = @import("std").build.RunStep;
const CrossTarget = std.zig.CrossTarget;

const pkgs = struct {
    const args = std.build.Pkg{
        .name = "args",
        .source = .{ .path = "libs/args/args.zig" },
        .dependencies = &[_]std.build.Pkg{},

pub fn build(b: *Builder) void {
    const optimize = b.standardOptimizeOption(.{});

    const exe = b.addExecutable(.{
        .name = "th3r00t.dev",
        .root_source_file = .{ .path = "src/main.zig" },
        .target = CrossTarget{
            .cpu_arch = .wasm32,
            .os_tag = .wasi,
            .abi = .musl,
        .optimize = optimize,
    // exe.addPackagePath("jsbind", "libs/jsbind/zig-out/lib/libjsbind.a");
    const run_cmd_str = &[_][]const u8{ "spin", "up" };
    const size_cmd_str = &[_][]const u8{ "du", "-sh", "zig-out/bin/th3r00t.dev.wasm" };

    const size_cmd = b.addSystemCommand(size_cmd_str);

    const run_cmd = b.addSystemCommand(run_cmd_str);

    const run_step = b.step("run", "Run the kernel");

Enter fullscreen mode Exit fullscreen mode

I'm not gonna say anything about this journey looks like it's going to be easy.

I don't require easy.

I neovim,
I arch & gentoo,
and now I Zig!

Top comments (0)