summaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig
index 15b2dd2..6654c95 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -4,6 +4,10 @@ const ping_tool = @import("ping_tool.zig");
const lua_bridge = @import("lua_bridge.zig");
const lua_runtime = @import("lua_runtime.zig");
const extension_loader = @import("extension_loader.zig");
+const panto_home = @import("panto_home.zig");
+const luarocks_runtime = @import("luarocks_runtime.zig");
+const self_exe = @import("self_exe.zig");
+const subcommand = @import("subcommand.zig");
// Shorthand alias for the Lua C API. The bridge module owns the actual
// `@cImport`; we re-use it here so the smoke check uses identical types.
@@ -23,6 +27,10 @@ test {
_ = lua_bridge;
_ = lua_runtime;
_ = extension_loader;
+ _ = panto_home;
+ _ = luarocks_runtime;
+ _ = self_exe;
+ _ = subcommand;
}
const Receiver = panto.provider.Receiver;
@@ -231,6 +239,26 @@ pub fn main(init: std.process.Init) !void {
// wired up yet, this just confirms the static lib comes through.
luaSmokeCheck();
+ // Resolve the absolute path of the running panto binary. Needed
+ // both by `panto lua` (we re-exec ourselves through a wrapper
+ // luarocks invokes) and by the agent's bootstrap.
+ const panto_path = try self_exe.selfExePathAlloc(alloc);
+ defer alloc.free(panto_path);
+
+ // Subcommand dispatch: `panto lua` and `panto bootstrap` short
+ // out of the agent loop, but still run the same luarocks bootstrap
+ // pipeline so first-run setup happens consistently.
+ switch (try subcommand.dispatch(
+ alloc,
+ io,
+ init.environ_map,
+ init.minimal.args,
+ panto_path,
+ )) {
+ .done => return,
+ .agent => {},
+ }
+
const config = try loadConfig(init.environ_map);
var stdout_buffer: [4096]u8 = undefined;
@@ -260,6 +288,24 @@ pub fn main(init: std.process.Init) !void {
var rt = try lua_runtime.LuaRuntime.create(alloc);
defer rt.deinit();
+ // Bootstrap luarocks against the Lua runtime's lua_State — same
+ // pipeline as `panto lua` and `panto bootstrap`. After this,
+ // `require("luarocks.*")` works and any pinned batteries from the
+ // manifest are installed under $PANTO_HOME.
+ const luarocks_rt = try luarocks_runtime.bootstrap(
+ alloc,
+ io,
+ init.environ_map,
+ rt.L,
+ panto_path,
+ );
+ defer luarocks_rt.deinit();
+
+ // luv is installed (or already present) at this point; wire the
+ // libuv-driven coroutine scheduler before any extensions get a
+ // chance to register tools that might want to yield.
+ try rt.installScheduler();
+
// Discover Lua extensions from $XDG_CONFIG_HOME/panto/extensions (or
// $HOME/.config/panto/extensions) and ./.panto/extensions. Project
// entries shadow user entries with the same name; tool-name collisions