build: delete module_homes — imports resolve through the declared zon

The module-to-domain table in build-support duplicated what each
domain's build.zig already states with its addModule exports. userBinary
now resolves each named import by searching the packages the binary
declared in its own build.zig.zon (b.available_deps), which also makes
the zon the literal include path: an import can only be satisfied by a
domain the binary claims, and naming a module whose domain is missing
fails the build graph with the domain to declare. build-support is down
to the recipe alone. All build variants green; manifest unchanged.
This commit is contained in:
Daniel Samson 2026-07-30 07:49:19 +01:00
parent 62d6a7a150
commit be04ebe954
No known key found for this signature in database
GPG Key ID: A9EB2589C60F7268
29 changed files with 53 additions and 93 deletions

View File

@ -31,60 +31,20 @@ pub fn freestandingTarget(b: *std.Build) std.Build.ResolvedTarget {
}); });
} }
/// Which library domain package exports each importable module the one /// Resolve one imported module by searching the packages this binary DECLARED
/// name -> home table. When a domain grows a module, it gets a row here; a /// in its own build.zig.zon the C include path made literal: an import can
/// binary naming a module whose home is missing from its own build.zig.zon /// only be satisfied by a domain the binary claims, and each domain's own
/// fails loudly at dependency resolution. /// build.zig (its addModule exports) is the single statement of who owns
const ModuleHome = struct { name: []const u8, home: []const u8 }; /// what. There is no name table here to drift.
const module_homes = [_]ModuleHome{ fn moduleFromDeclaredDependencies(b: *std.Build, name: []const u8) *std.Build.Module {
// library/kernel the userspace private-ABI library, split by concern. for (b.available_deps) |declared| {
.{ .name = "abi", .home = "kernel" }, const dependency = b.dependency(declared[0], .{});
.{ .name = "system-call", .home = "kernel" }, if (dependency.builder.modules.get(name)) |module| return module;
.{ .name = "ipc", .home = "kernel" },
.{ .name = "time", .home = "kernel" },
.{ .name = "thread", .home = "kernel" },
.{ .name = "logging", .home = "kernel" },
.{ .name = "process", .home = "kernel" },
.{ .name = "file-system", .home = "kernel" },
.{ .name = "memory", .home = "kernel" },
.{ .name = "service", .home = "kernel" },
.{ .name = "start", .home = "kernel" },
// library/device driver-side libraries + the flat reference data.
.{ .name = "mmio", .home = "device" },
.{ .name = "acpi-ids", .home = "device" },
.{ .name = "device-abi", .home = "device" },
.{ .name = "aml", .home = "device" },
.{ .name = "usb-abi", .home = "device" },
.{ .name = "usb-ids", .home = "device" },
.{ .name = "usb", .home = "device" },
.{ .name = "driver", .home = "device" },
.{ .name = "block", .home = "device" },
.{ .name = "pci", .home = "device" },
.{ .name = "pci-class", .home = "device" },
.{ .name = "device-registry", .home = "device" },
// library/client userspace service clients.
.{ .name = "display-client", .home = "client" },
.{ .name = "input-client", .home = "client" },
// library/protocol the wire protocols.
.{ .name = "vfs-protocol", .home = "protocol" },
.{ .name = "input-protocol", .home = "protocol" },
.{ .name = "block-protocol", .home = "protocol" },
.{ .name = "usb-transfer-protocol", .home = "protocol" },
.{ .name = "device-manager-protocol", .home = "protocol" },
.{ .name = "display-protocol", .home = "protocol" },
.{ .name = "scanout-protocol", .home = "protocol" },
.{ .name = "power-protocol", .home = "protocol" },
// library/csv the /etc/*.csv helpers.
.{ .name = "csv", .home = "csv" },
// library/xkeyboard-config keycode -> keysym/character tables.
.{ .name = "xkeyboard-config", .home = "xkeyboard-config" },
};
fn moduleHome(name: []const u8) ?[]const u8 {
for (module_homes) |entry| {
if (std.mem.eql(u8, entry.name, name)) return entry.home;
} }
return null; @panic(b.fmt(
"no declared dependency exports a module named '{s}' — declare the domain that owns it in this package's build.zig.zon",
.{name},
));
} }
/// What `userBinary` needs to know about one user binary. /// What `userBinary` needs to know about one user binary.
@ -95,8 +55,8 @@ pub const UserBinaryOptions = struct {
root_source_file: std.Build.LazyPath, root_source_file: std.Build.LazyPath,
/// Exactly the modules the program's source @imports (directly or through /// Exactly the modules the program's source @imports (directly or through
/// its same-directory files) no more, no less. Order is free; sorted /// its same-directory files) no more, no less. Order is free; sorted
/// reads best. An undeclared @import fails the compile; a declared name no /// reads best. An undeclared @import fails the compile; a name no
/// domain exports fails the build graph with a pointer to module_homes. /// declared domain exports fails the build graph, naming the miss.
imports: []const []const u8, imports: []const []const u8,
/// Built multi-threaded (`single_threaded = false`) so real atomics/TLS /// Built multi-threaded (`single_threaded = false`) so real atomics/TLS
/// work required before a binary may call `Thread.spawn` /// work required before a binary may call `Thread.spawn`
@ -121,12 +81,10 @@ pub fn userBinary(b: *std.Build, options: UserBinaryOptions) *std.Build.Step.Com
const kernel = b.dependency("kernel", .{}); const kernel = b.dependency("kernel", .{});
var imports: std.ArrayListUnmanaged(std.Build.Module.Import) = .empty; var imports: std.ArrayListUnmanaged(std.Build.Module.Import) = .empty;
for (options.imports) |name| { for (options.imports) |name| {
const home = moduleHome(name) orelse @panic(b.fmt( imports.append(b.allocator, .{
"no library domain exports a module named '{s}' — if a domain grew it, add its row to module_homes in build-support/build.zig", .name = name,
.{name}, .module = moduleFromDeclaredDependencies(b, name),
)); }) catch @panic("OOM");
const dependency = if (std.mem.eql(u8, home, "kernel")) kernel else b.dependency(home, .{});
imports.append(b.allocator, .{ .name = name, .module = dependency.module(name) }) catch @panic("OOM");
} }
// Settings (target, optimize, code model, ...) live on the root module // Settings (target, optimize, code model, ...) live on the root module
// only; the program module inherits them. // only; the program module inherits them.

View File

@ -62,8 +62,10 @@ Rules:
include list — and its zon names only the domains those modules come from include list — and its zon names only the domains those modules come from
(plus `build-support` and `kernel`, which is implicit in every binary: the (plus `build-support` and `kernel`, which is implicit in every binary: the
root shim and user link script live there). Nothing is pre-wired: an root shim and user link script live there). Nothing is pre-wired: an
undeclared `@import` is a compile error, and build-support's one undeclared `@import` is a compile error, and build-support resolves each
module-to-domain table (`module_homes`) resolves each name. Availability name by searching the packages the zon declares — the domains' own
addModule exports are the single statement of who owns what, with no name
table anywhere to drift. Availability
never meant bloat — Zig only compiles what a program actually imports — but never meant bloat — Zig only compiles what a program actually imports — but
exactness makes the declared interface honest and machine-checked. exactness makes the declared interface honest and machine-checked.
- **Modules export source, not artifacts** — each consumer compiles libraries - **Modules export source, not artifacts** — each consumer compiles libraries
@ -132,9 +134,9 @@ rewritten against the package template.
## Execution notes (the finished shape) ## Execution notes (the finished shape)
- The shared recipe lives in `build-support/build.zig`: `userBinary` (what - The shared recipe lives in `build-support/build.zig`: `userBinary` (what
every binary package calls, resolving each named import through the every binary package calls; each named import resolves by searching the
`module_homes` table) and `programModule` (for per-binary addOptions packages the binary's zon declares) and `programModule` (for per-binary
modules). The `start` root shim and `user.ld` are named through the kernel addOptions modules). The `start` root shim and `user.ld` are named through the kernel
package (Dependency.path). package (Dependency.path).
- Adding a binary = adding a directory with source + a ~15-line build.zig + - Adding a binary = adding a directory with source + a ~15-line build.zig +
zon (copy any existing binary package, e.g. zon (copy any existing binary package, e.g.

View File

@ -1,6 +1,6 @@
//! The pci-bus driver as a binary package (docs/build-packages-plan.md): //! The pci-bus driver as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
const std = @import("std"); const std = @import("std");
const build_support = @import("build-support"); const build_support = @import("build-support");

View File

@ -1,6 +1,6 @@
//! The ps2-bus driver as a binary package (docs/build-packages-plan.md): //! The ps2-bus driver as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
const std = @import("std"); const std = @import("std");
const build_support = @import("build-support"); const build_support = @import("build-support");

View File

@ -1,6 +1,6 @@
//! The usb-hid driver as a binary package (docs/build-packages-plan.md): //! The usb-hid driver as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
const std = @import("std"); const std = @import("std");
const build_support = @import("build-support"); const build_support = @import("build-support");

View File

@ -1,6 +1,6 @@
//! The usb-storage driver as a binary package (docs/build-packages-plan.md): //! The usb-storage driver as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
const std = @import("std"); const std = @import("std");
const build_support = @import("build-support"); const build_support = @import("build-support");

View File

@ -1,6 +1,6 @@
//! The usb-xhci-bus driver as a binary package (docs/build-packages-plan.md): //! The usb-xhci-bus driver as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
const std = @import("std"); const std = @import("std");
const build_support = @import("build-support"); const build_support = @import("build-support");

View File

@ -1,6 +1,6 @@
//! The virtio-gpu driver as a binary package (docs/build-packages-plan.md): //! The virtio-gpu driver as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
const std = @import("std"); const std = @import("std");
const build_support = @import("build-support"); const build_support = @import("build-support");

View File

@ -1,6 +1,6 @@
//! The acpi service as a binary package (docs/build-packages-plan.md): //! The acpi service as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
//! //!
//! The artifact is named "discovery": one swappable process per firmware //! The artifact is named "discovery": one swappable process per firmware
//! fills the ramdisk's neutral `discovery` slot (docs/discovery.md); the //! fills the ramdisk's neutral `discovery` slot (docs/discovery.md); the

View File

@ -1,6 +1,6 @@
//! The device-manager service as a binary package (docs/build-packages-plan.md): //! The device-manager service as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
const std = @import("std"); const std = @import("std");
const build_support = @import("build-support"); const build_support = @import("build-support");

View File

@ -1,6 +1,6 @@
//! The display-demo service as a binary package (docs/build-packages-plan.md): //! The display-demo service as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
const std = @import("std"); const std = @import("std");
const build_support = @import("build-support"); const build_support = @import("build-support");

View File

@ -1,6 +1,6 @@
//! The display service as a binary package (docs/build-packages-plan.md): //! The display service as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
const std = @import("std"); const std = @import("std");
const build_support = @import("build-support"); const build_support = @import("build-support");

View File

@ -1,6 +1,6 @@
//! The fat service as a binary package (docs/build-packages-plan.md): //! The fat service as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
const std = @import("std"); const std = @import("std");
const build_support = @import("build-support"); const build_support = @import("build-support");

View File

@ -1,6 +1,6 @@
//! The fdt service as a binary package (docs/build-packages-plan.md): //! The fdt service as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
//! //!
//! The artifact is named "discovery" like acpi's: the Raspberry Pis hand over //! The artifact is named "discovery" like acpi's: the Raspberry Pis hand over
//! a flattened device tree, and the aarch64 target flips the root's //! a flattened device tree, and the aarch64 target flips the root's

View File

@ -1,6 +1,6 @@
//! init (PID 1) as a binary package (docs/build-packages-plan.md): this file //! init (PID 1) as a binary package (docs/build-packages-plan.md): this file
//! names the binary and EXACTLY the modules its source imports the shared //! names the binary and EXACTLY the modules its source imports the shared
//! recipe and the module-to-domain map live in build-support. The root build //! recipe resolves each name from the domains the zon declares. The root build
//! consumes the artifact for the boot image and forwards its -Dserial here. //! consumes the artifact for the boot image and forwards its -Dserial here.
const std = @import("std"); const std = @import("std");

View File

@ -1,6 +1,6 @@
//! The input service as a binary package (docs/build-packages-plan.md): //! The input service as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
const std = @import("std"); const std = @import("std");
const build_support = @import("build-support"); const build_support = @import("build-support");

View File

@ -1,6 +1,6 @@
//! The args-echo test fixture as a binary package (docs/build-packages-plan.md): //! The args-echo test fixture as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
const std = @import("std"); const std = @import("std");
const build_support = @import("build-support"); const build_support = @import("build-support");

View File

@ -1,6 +1,6 @@
//! The crash-test test fixture as a binary package (docs/build-packages-plan.md): //! The crash-test test fixture as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
const std = @import("std"); const std = @import("std");
const build_support = @import("build-support"); const build_support = @import("build-support");

View File

@ -1,6 +1,6 @@
//! The device-list test fixture as a binary package (docs/build-packages-plan.md): //! The device-list test fixture as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
const std = @import("std"); const std = @import("std");
const build_support = @import("build-support"); const build_support = @import("build-support");

View File

@ -1,6 +1,6 @@
//! The fat-test test fixture as a binary package (docs/build-packages-plan.md): //! The fat-test test fixture as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
const std = @import("std"); const std = @import("std");
const build_support = @import("build-support"); const build_support = @import("build-support");

View File

@ -1,6 +1,6 @@
//! The input-source test fixture as a binary package (docs/build-packages-plan.md): //! The input-source test fixture as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
const std = @import("std"); const std = @import("std");
const build_support = @import("build-support"); const build_support = @import("build-support");

View File

@ -1,6 +1,6 @@
//! The input-test test fixture as a binary package (docs/build-packages-plan.md): //! The input-test test fixture as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
const std = @import("std"); const std = @import("std");
const build_support = @import("build-support"); const build_support = @import("build-support");

View File

@ -1,6 +1,6 @@
//! The iommu-fault-test test fixture as a binary package (docs/build-packages-plan.md): //! The iommu-fault-test test fixture as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
const std = @import("std"); const std = @import("std");
const build_support = @import("build-support"); const build_support = @import("build-support");

View File

@ -1,6 +1,6 @@
//! The pci-cap-test test fixture as a binary package (docs/build-packages-plan.md): //! The pci-cap-test test fixture as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
const std = @import("std"); const std = @import("std");
const build_support = @import("build-support"); const build_support = @import("build-support");

View File

@ -1,6 +1,6 @@
//! The process-test test fixture as a binary package (docs/build-packages-plan.md): //! The process-test test fixture as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
const std = @import("std"); const std = @import("std");
const build_support = @import("build-support"); const build_support = @import("build-support");

View File

@ -1,6 +1,6 @@
//! The shared-memory-client test fixture as a binary package (docs/build-packages-plan.md): //! The shared-memory-client test fixture as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
const std = @import("std"); const std = @import("std");
const build_support = @import("build-support"); const build_support = @import("build-support");

View File

@ -1,6 +1,6 @@
//! The shared-memory-server test fixture as a binary package (docs/build-packages-plan.md): //! The shared-memory-server test fixture as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
const std = @import("std"); const std = @import("std");
const build_support = @import("build-support"); const build_support = @import("build-support");

View File

@ -1,6 +1,6 @@
//! The thread-test test fixture as a binary package (docs/build-packages-plan.md): //! The thread-test test fixture as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
const std = @import("std"); const std = @import("std");
const build_support = @import("build-support"); const build_support = @import("build-support");

View File

@ -1,6 +1,6 @@
//! The vfs-test test fixture as a binary package (docs/build-packages-plan.md): //! The vfs-test test fixture as a binary package (docs/build-packages-plan.md):
//! this file names the binary and EXACTLY the modules its source imports //! this file names the binary and EXACTLY the modules its source imports
//! the shared recipe and the module-to-domain map live in build-support. //! build-support resolves each name from the domains this zon declares.
const std = @import("std"); const std = @import("std");
const build_support = @import("build-support"); const build_support = @import("build-support");