diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-17 13:11:46 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 13:13:37 -0300 |
| commit | 2fb9cbad0c88dbc3f2db86e2490fca40bc6b47bf (patch) | |
| tree | 564d315cd8ee60fd743ca66782a1251b1bf6037d | |
| parent | 8c32753594ce0d6852336206b86cbdd88a8878b1 (diff) | |
| download | cloud9-2fb9cbad0c88dbc3f2db86e2490fca40bc6b47bf.tar.gz cloud9-2fb9cbad0c88dbc3f2db86e2490fca40bc6b47bf.zip | |
The README and 9proc's told a consumer to pass .target and .optimize to
b.dependency("cloud9", ...), and to swap the URL pin for a path while
working on both packages. Now: the two modules take no options, and the
whole build.zig of a program on cloud9 is written out (eleven lines, the
form test/consumer uses); nothing else of cloud9's build runs in it. The
sibling checkout is Zig's --fork=../cloud9, with the manifest untouched.
Checked outside the tree: that build.zig, in a package pinning cloud9 by
URL and hash (pardes's pin, 7f418a6b, from a copy of its zig-pkg entry),
builds and runs; with --fork=<this checkout> it builds against this one
("fork ... matched 1 cloud9 packages", and no jj or date at configure);
and against this tree as a fetched package (a tarball of its tracked
files, so the manifest's paths filter applies) it builds too.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
| -rw-r--r-- | 9proc/README.md | 11 | ||||
| -rw-r--r-- | README.md | 34 |
2 files changed, 30 insertions, 15 deletions
diff --git a/9proc/README.md b/9proc/README.md index 1b4d6c1..749c8a1 100644 --- a/9proc/README.md +++ b/9proc/README.md @@ -40,13 +40,14 @@ contract. ## Using the library cloud9's `build.zig` exports two modules: `cloud9` (the protocol) and -`9proc` (this library, which imports `cloud9` itself). A package that -depends on cloud9 takes both from the one dependency: +`9proc` (this library, which imports `cloud9` itself), with no target of +their own. A package that depends on cloud9 takes both from the one +dependency, with no options: ```zig -const cloud9_dep = b.dependency("cloud9", .{ .target = target, .optimize = optimize }); -exe.root_module.addImport("cloud9", cloud9_dep.module("cloud9")); -exe.root_module.addImport("9proc", cloud9_dep.module("9proc")); +const cloud9 = b.dependency("cloud9", .{}); +exe.root_module.addImport("cloud9", cloud9.module("cloud9")); +exe.root_module.addImport("9proc", cloud9.module("9proc")); ``` Embedding the core is three static objects and a push/step/output loop, the @@ -59,17 +59,31 @@ zig fetch --save=cloud9 git+https://git.sr.ht/~gbrls/cloud9#<commit> The toolchain has no `git+ssh` support, so the manifest carries the read-only HTTPS URL. Push to `[email protected]:~gbrls/cloud9`. For work on both packages at -once, substitute `.cloud9 = .{ .path = "../cloud9" }` while editing, then -re-pin. Either way, import the module the same way: +once, build against the checkout without touching the manifest: +`zig build --fork=../cloud9`. + +The package exports two modules, `cloud9` and `9proc`, with no target or +optimize of their own: they compile for whatever imports them, so the +dependency takes no options. The whole `build.zig` of a program on cloud9: ```zig -const cloud9 = b.dependency("cloud9", .{ - .target = target, - .optimize = optimize, -}).module("cloud9"); -app.root_module.addImport("cloud9", cloud9); +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const exe = b.addExecutable(.{ .name = "srv", .root_module = b.createModule(.{ + .root_source_file = b.path("src/main.zig"), + .target = b.standardTargetOptions(.{}), + .optimize = b.standardOptimizeOption(.{}), + .imports = &.{.{ .name = "cloud9", .module = b.dependency("cloud9", .{}).module("cloud9") }}, + }) }); + b.installArtifact(exe); +} ``` +Nothing else of cloud9's build runs in yours: its tests and programs are +configured only when it is the root. [`test/consumer`](test/consumer/build.zig) +is such a package, and cloud9's `zig build test` builds and runs it. + Start a client with `Client.init(.{ .in = input_buffer, .out = output_buffer })`. Submit `.version` first. Drain `output()` through your transport and report the number sent with `wrote()`. Feed received bytes using `push()` and collect tagged @@ -151,9 +165,9 @@ enabled program's unit and integration steps. A dependent package gets both modules from the one dependency: ```zig -const cloud9_dep = b.dependency("cloud9", .{ .target = target, .optimize = optimize }); -app.root_module.addImport("cloud9", cloud9_dep.module("cloud9")); -app.root_module.addImport("9proc", cloud9_dep.module("9proc")); +const cloud9 = b.dependency("cloud9", .{}); +app.root_module.addImport("cloud9", cloud9.module("cloud9")); +app.root_module.addImport("9proc", cloud9.module("9proc")); ``` See [design and ownership contracts](docs/design.md), |
