summaryrefslogtreecommitdiff
path: root/src/luarocks_runtime.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 /src/luarocks_runtime.zig
parent6545cdfd8f2bc865aa06a2b5515056daf58ba111 (diff)
system agent definition scaffolding
Diffstat (limited to 'src/luarocks_runtime.zig')
-rw-r--r--src/luarocks_runtime.zig37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/luarocks_runtime.zig b/src/luarocks_runtime.zig
index b67a8ad..0114b64 100644
--- a/src/luarocks_runtime.zig
+++ b/src/luarocks_runtime.zig
@@ -37,6 +37,7 @@ const manifest = @import("manifest.zig");
const panto_home = @import("panto_home.zig");
const embedded_luarocks = @import("embedded_luarocks");
const embedded_lua_headers = @import("embedded_lua_headers");
+const embedded_agent = @import("embedded_agent");
const lua_bridge = @import("lua_bridge.zig");
const c = lua_bridge.c;
@@ -135,6 +136,7 @@ pub fn bootstrap(
try panto_home.ensureDirsExist(layout, io);
try stageLuaHeaders(allocator, io, layout);
+ try stageAgentTree(allocator, io, layout);
const lua_wrapper_path = try writeLuaWrapper(allocator, io, layout, panto_executable_path);
defer allocator.free(lua_wrapper_path);
try writeLuarocksConfig(allocator, io, layout, lua_wrapper_path);
@@ -199,6 +201,41 @@ fn stageLuaHeaders(
}
}
+// ---------------------------------------------------------------------------
+// Stage the embedded `agent/` tree
+// ---------------------------------------------------------------------------
+
+/// Materialize the binary-embedded `agent/` tree under
+/// `$PANTO_HOME/agent/`. Each entry's `path` is relative to the agent
+/// root and may include subdirectories (`tools/read.lua` etc.); the
+/// parent directory is created lazily as we encounter files inside it.
+///
+/// Uses the same `writeIfDifferent` discipline as `stageLuaHeaders`:
+/// unchanged files keep their on-disk mtime so downstream consumers
+/// (the extension loader's stat-cached searches, future-rocks builds
+/// against staged headers) don't see spurious invalidations.
+fn stageAgentTree(
+ allocator: Allocator,
+ io: Io,
+ layout: panto_home.Layout,
+) !void {
+ var root = try Io.Dir.cwd().openDir(io, layout.agent_dir, .{});
+ defer root.close(io);
+
+ for (embedded_agent.files) |entry| {
+ // Ensure the file's parent directory exists. `path` is
+ // forward-slash separated (the generator normalizes that),
+ // so we can split off the dirname directly.
+ if (std.fs.path.dirname(entry.path)) |parent| {
+ root.createDirPath(io, parent) catch |err| switch (err) {
+ error.PathAlreadyExists => {},
+ else => return err,
+ };
+ }
+ try writeIfDifferent(allocator, io, root, entry.path, entry.contents);
+ }
+}
+
/// Write `contents` into `dir/name` only if the existing file differs.
/// Creates the file if absent.
fn writeIfDifferent(