summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
authorT <t@tjp.lol>2026-05-27 16:34:32 -0600
committerT <t@tjp.lol>2026-05-27 16:35:09 -0600
commitf72b5793a5c7e7891e4904be73c0bc6bc038fa18 (patch)
tree5201aa7c6648d96b401dcbcb5343d4510b1c34e5 /build.zig
parent6545cdfd8f2bc865aa06a2b5515056daf58ba111 (diff)
system agent definition scaffolding
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig42
1 files changed, 42 insertions, 0 deletions
diff --git a/build.zig b/build.zig
index 4e4e862..bcfe1be 100644
--- a/build.zig
+++ b/build.zig
@@ -41,6 +41,11 @@ pub fn build(b: *std.Build) void {
// for luarocks to find when compiling C rocks.
const lua_headers_embed_path = generateLuaHeadersEmbed(b, lua_src);
+ // And the in-repo `agent/` tree: bundled into the binary and
+ // staged at $PANTO_HOME/agent/ on first run. This is panto's
+ // "system" extension/tool layer (read/write/edit/bash etc.).
+ const agent_embed_path = generateAgentEmbed(b);
+
// Constants module: makes Zig know the Lua and luarocks versions
// without duplicating literals everywhere.
const versions_mod = b.addOptions();
@@ -64,6 +69,9 @@ pub fn build(b: *std.Build) void {
exe_mod.addImport("embedded_lua_headers", b.createModule(.{
.root_source_file = lua_headers_embed_path,
}));
+ exe_mod.addImport("embedded_agent", b.createModule(.{
+ .root_source_file = agent_embed_path,
+ }));
// Link Lua. We can't use a static library here because the
// standard archive-linking behavior drops object files whose
// symbols nothing in our code references — e.g. `lua_settable`,
@@ -121,6 +129,9 @@ pub fn build(b: *std.Build) void {
test_mod.addImport("embedded_lua_headers", b.createModule(.{
.root_source_file = lua_headers_embed_path,
}));
+ test_mod.addImport("embedded_agent", b.createModule(.{
+ .root_source_file = agent_embed_path,
+ }));
addLuaSources(test_mod, lua_src, lua_anchor_path);
test_mod.addIncludePath(lua_src.path("src"));
test_mod.linkLibrary(lua_repl);
@@ -300,6 +311,37 @@ fn generateLuarocksEmbed(
return out_zig;
}
+/// Codegen step: walk the in-repo `agent/` tree and emit a Zig module
+/// embedding every file. Bootstrap stages the result under
+/// `$PANTO_HOME/agent/` on first run, where the runtime's extension
+/// loader finds it as the "system" layer (below user and project).
+///
+/// Mirrors `generateLuarocksEmbed`'s addCopyDirectory trick so the
+/// emitted `@embedFile("agent_src/<rel>")` references resolve relative
+/// to the generated zig file.
+fn generateAgentEmbed(b: *std.Build) std.Build.LazyPath {
+ const tool = b.addExecutable(.{
+ .name = "gen-agent-embed",
+ .root_module = b.createModule(.{
+ .root_source_file = b.path("build/gen_agent_embed.zig"),
+ .target = b.graph.host,
+ .optimize = .Debug,
+ }),
+ });
+
+ const run = b.addRunArtifact(tool);
+ // Marker subpath: each emitted `@embedFile` reference is
+ // `agent_src/<rel>`, and we stage the tree under that name.
+ run.addArg("agent_src");
+ run.addDirectoryArg(b.path("agent"));
+ const gen_file = run.addOutputFileArg("embedded_agent.zig");
+
+ const wf = b.addWriteFiles();
+ const out_zig = wf.addCopyFile(gen_file, "embedded_agent.zig");
+ _ = wf.addCopyDirectory(b.path("agent"), "agent_src", .{});
+ return out_zig;
+}
+
/// Codegen step: emit a Zig module that exposes every Lua public header
/// from the Lua source tarball as embedded bytes. The bootstrap stages
/// these under `$PANTO_HOME/rocks/lua-X.Y.Z/include/` so luarocks can