Skip to content

dx: consumer build.zig has to reach into merjs internals (src/main.zig, tools/codegen.zig, src/worker.zig) #67

@justrach

Description

@justrach

Problem

When you use merjs as a dependency, your build.zig has to reference internal file paths from the merjs package directly:

const merjs_dep = b.dependency("merjs", .{});
const mer_mod = merjs_dep.module("mer");

// These all reach into merjs internals
const main_mod = b.createModule(.{
    .root_source_file = merjs_dep.path("src/main.zig"),  // <-- internal path
});

// codegen
.root_source_file = merjs_dep.path("tools/codegen.zig"),  // <-- internal path

// worker
.root_source_file = merjs_dep.path("src/worker.zig"),  // <-- internal path

This means:

  • If merjs renames or moves src/main.zig, every consumer's build breaks
  • The consumer has to know merjs's internal file layout to set up their project
  • @import("mer") works great as a module, but the entry points (server, codegen, worker) aren't exposed as proper modules

What I expected

Something like:

const merjs_dep = b.dependency("merjs", .{});
const mer_mod = merjs_dep.module("mer");
const server_mod = merjs_dep.module("server");    // instead of merjs_dep.path("src/main.zig")
const codegen_mod = merjs_dep.module("codegen");   // instead of merjs_dep.path("tools/codegen.zig")
const worker_mod = merjs_dep.module("worker");     // instead of merjs_dep.path("src/worker.zig")

Or even better, merjs's build.zig could export helper functions that set up the full build for consumers:

const merjs = b.dependency("merjs", .{});
merjs.addServer(b, .{ .name = "my-site", .app_dir = "app", .api_dir = "api" });
merjs.addWorker(b, .{ .name = "my-site" });
merjs.addCodegen(b);

Context

Ran into this building the kuri site (justrach/kuri/site). The build.zig is 120 lines of boilerplate that mostly just wires up merjs internals. Related to #61 (the init experience), but this is about the ongoing build DX, not just first setup.

Also: wasm/ directory missing from .paths

The build.zig.zon .paths field doesn't include wasm/, which means wasm/counter_config.zig isn't in the published package. The build system tries to import it and fails with FileNotFound. Had to manually copy it from the git source.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions