feat: Counter canister and a Node client, over OCapN on a local replica
The canister is freestanding wasm32 importing only ic0. Each caller principal gets a CapTP session: start carries op:start-session, deliver carries later frames, and each reply carries the canister's frames. The client peer is wasm too, driven from Node by @icp-sdk/core. It holds answer releases so they ride ahead of the next call instead of costing an update call of their own: handshake, fetch, and each send are one update call apiece. Generated-by: Claude Code (claude-opus-5-5)
This commit is contained in:
1 parent
6348422012
commit
1177fc86b6
13 files changed
+787
-14
No files matched your search
@@ -5,13 +5,46 @@ pub fn build(b: *std.Build) void {
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const glowcap = b.dependency("glowcap", .{ .target = target, .optimize = optimize });
|
||||
const test_step = b.step("test", "Run the unit tests and the in-memory client/canister round trip");
|
||||
for ([_][]const u8{ "src/pair_test.zig", "src/candid.zig", "src/principal.zig" }) |root| {
|
||||
const t = b.addTest(.{ .root_module = b.createModule(.{
|
||||
.root_source_file = b.path(root),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.imports = &.{.{ .name = "glowcap", .module = glowcap.module("glowcap") }},
|
||||
}) });
|
||||
test_step.dependOn(&b.addRunArtifact(t).step);
|
||||
}
|
||||
|
||||
const pair_test = b.addTest(.{ .root_module = b.createModule(.{
|
||||
.root_source_file = b.path("src/pair_test.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.imports = &.{.{ .name = "glowcap", .module = glowcap.module("glowcap") }},
|
||||
}) });
|
||||
const test_step = b.step("test", "Run the in-memory client/canister round trip");
|
||||
test_step.dependOn(&b.addRunArtifact(pair_test).step);
|
||||
// The canister: freestanding 32-bit Wasm whose only imports are `ic0`.
|
||||
const wasm32 = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
|
||||
const canister_glowcap = b.dependency("glowcap", .{ .target = wasm32, .optimize = .ReleaseSmall });
|
||||
const canister = b.addExecutable(.{
|
||||
.name = "counter",
|
||||
.root_module = b.createModule(.{
|
||||
.root_source_file = b.path("src/canister.zig"),
|
||||
.target = wasm32,
|
||||
.optimize = .ReleaseSmall,
|
||||
.imports = &.{.{ .name = "glowcap", .module = canister_glowcap.module("glowcap") }},
|
||||
}),
|
||||
});
|
||||
canister.entry = .disabled;
|
||||
canister.root_module.export_symbol_names = &.{ "canister_init", "canister_update start", "canister_update deliver" };
|
||||
const canister_step = b.step("canister", "Build the canister to zig-out/bin/counter.wasm");
|
||||
canister_step.dependOn(&b.addInstallArtifact(canister, .{}).step);
|
||||
|
||||
// The client peer, for a JavaScript host to drive.
|
||||
const client = b.addExecutable(.{
|
||||
.name = "client",
|
||||
.root_module = b.createModule(.{
|
||||
.root_source_file = b.path("src/client.zig"),
|
||||
.target = wasm32,
|
||||
.optimize = .ReleaseSmall,
|
||||
.imports = &.{.{ .name = "glowcap", .module = canister_glowcap.module("glowcap") }},
|
||||
}),
|
||||
});
|
||||
client.entry = .disabled;
|
||||
client.rdynamic = true;
|
||||
const client_step = b.step("client", "Build the client peer to zig-out/bin/client.wasm");
|
||||
client_step.dependOn(&b.addInstallArtifact(client, .{}).step);
|
||||
}
|
||||
Reference in new issue
Block a user