From f44744d8bfce2f94cae9a658c416a3c2a0364a6a Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 13:04:05 -0300 Subject: build: a library's part for a consumer, and no more A package that depends on cloud9 ran all of its build(): the tests, 9web, the probes and the three program fragments, with the jj and the date 9proc's fragment spawns at configure, and it had to pass .target and .optimize, since the module carried both (one forgotten, cloud9 was Debug inside a release build). Now build() exports two modules with no target or optimize of their own, which take their importer's (std.Build.Module's CreateOptions: unspecified options are inherited): cloud9, and 9proc beside it at the top level, then returns when it is not the root (b.isRoot()). A consumer writes b.dependency("cloud9", .{}).module("cloud9"). The root's tests and programs root a compilation on the library, which needs a target, so they make their own module from the same file: the five lines the module took before, now a createModule, and 9proc's fragment makes its copy with createModule where it exported with addModule (no line more). The target and optimize options are still declared before the return: pardes and sketchbook pass both today, and an undeclared option a dependency is given is logged as "invalid option" (target, cpu and optimize) with a stack trace on every configure of theirs (not fatal: Build.dependencyResolved reports it, only the root's invalid options exit, compiler/configurer.zig:146-158; seen in a consumer: rc 0, three errors). The comment says to move both under the return once they pass nothing. zig build test 106 of 108 at load 15 (serve's "a ticket of a hung-up client" and "repeated connect/disconnect", the two known to fail under load; see the next change for quiet runs); install into a scratch prefix builds 9web, 9ns, 9agents, 9proc-demo and cloud9-probe as before. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- 9proc/build.zig | 10 +++++----- build.zig | 21 ++++++++++++++++++--- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/9proc/build.zig b/9proc/build.zig index 43176d7..cf32886 100644 --- a/9proc/build.zig +++ b/9proc/build.zig @@ -21,9 +21,8 @@ pub const Context = struct { }; pub const Artifacts = struct { - /// The `9proc` module, exported with `b.addModule` so dependents of - /// cloud9 can `.module("9proc")`. Built for any target; the Linux - /// layer is compiled in only when the target OS is Linux. + /// The `9proc` module for `target`: the Linux layer is compiled in + /// only when the target OS is Linux. module: *std.Build.Module, /// The demo 9P2000 server (binary `9proc-demo`); null when the target is /// not Linux. 9ns's integration tests use it as their server. @@ -59,8 +58,9 @@ pub fn add(b: *std.Build, ctx: Context) Artifacts { build_options.addOption([]const u8, "target", target.result.zigTriple(b.allocator) catch "unknown"); // The library: freestanding core + vars, scratch (allocator), Linux layer. - // Exported under the name `9proc` for packages that depend on cloud9. - const lib_mod = b.addModule("9proc", .{ + // This copy is for `target`; packages that depend on cloud9 get the one + // the root exports, which has no target of its own. + const lib_mod = b.createModule(.{ .root_source_file = b.path("9proc/src/root.zig"), .target = target, .optimize = optimize, diff --git a/build.zig b/build.zig index be9c929..41b9104 100644 --- a/build.zig +++ b/build.zig @@ -1,8 +1,23 @@ const std = @import("std"); pub fn build(b: *std.Build) void { + // Taken before the return only because pardes and sketchbook still + // pass `.target` and `.optimize`, which the exports ignore: undeclared, + // each configure of theirs would log "invalid option" for target, cpu + // and optimize with a stack trace (not fatal). Move both below the + // return once they pass nothing. const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const module = b.addModule("cloud9", .{ + // What a package that depends on cloud9 gets: the library and 9proc, + // with no target or optimize of their own (they take their importer's). + const cloud9 = b.addModule("cloud9", .{ .root_source_file = b.path("src/root.zig") }); + _ = b.addModule("9proc", .{ + .root_source_file = b.path("9proc/src/root.zig"), + .imports = &.{.{ .name = "cloud9", .module = cloud9 }}, + }); + // The rest is cloud9's own (tests, programs, and the fragments with + // the `jj` and `date` 9proc spawns), so a consumer's configure stops here. + if (!b.isRoot()) return; + const module = b.createModule(.{ .root_source_file = b.path("src/root.zig"), .target = target, .optimize = optimize, @@ -159,7 +174,7 @@ pub fn build(b: *std.Build) void { // add a directory, a fragment, a toggle here, and the path to // build.zig.zon. // - // -D9proc=[bool] library module (any target) + freestanding check; + // -D9proc=[bool] library tests + freestanding check; // demo server and Linux suites when the target is Linux // -D9ns=[bool] the FUSE mount CLI (Linux only) // @@ -167,7 +182,7 @@ pub fn build(b: *std.Build) void { // programs are installed by the plain `zig build` next to 9web // and cloud9-probe. const is_linux = target.result.os.tag == .linux; - const want_9proc = b.option(bool, "9proc", "Build the 9proc library module and demo (default: target is Linux)") orelse is_linux; + const want_9proc = b.option(bool, "9proc", "Build 9proc's tests, freestanding check and demo (default: target is Linux)") orelse is_linux; const want_9ns = b.option(bool, "9ns", "Build the 9ns FUSE mount CLI (default: target is Linux; Linux only)") orelse is_linux; const want_9agents = b.option(bool, "9agents", "Build the coding-agents fs daemon (default: target is Linux; Linux only)") orelse is_linux; if (want_9ns and !is_linux) { -- cgit v1.3