From 576891dc2ec4d917932a4c396471d4bbbad90c8e Mon Sep 17 00:00:00 2001 From: T Date: Wed, 27 May 2026 08:04:04 -0600 Subject: Finish the hard parts of the lua makeover - bundle luarocks source in the panto binary - bootstrap process (intended for first `panto` run): - make ~/.local/share/panto/... - write out luarocks sources into it - run luarocks to install luv - new `panto bootstrap` command just runs the bootstrap - `panto bootstrap --force` removes everything and re-bootstraps - new `panto lua` command just runs panto's embedded lua --- build/gen_lua_headers_embed.zig | 68 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 build/gen_lua_headers_embed.zig (limited to 'build/gen_lua_headers_embed.zig') diff --git a/build/gen_lua_headers_embed.zig b/build/gen_lua_headers_embed.zig new file mode 100644 index 0000000..1ac4004 --- /dev/null +++ b/build/gen_lua_headers_embed.zig @@ -0,0 +1,68 @@ +//! Build-time codegen: emit a Zig module exposing every Lua public +//! header from the Lua source tarball as embedded bytes. Bootstrap +//! writes these to `$PANTO_HOME/rocks/lua-X.Y.Z/include/` on first run +//! so luarocks can compile C rocks against them. +//! +//! Invoked from `build.zig`: +//! +//! gen-lua-headers-embed +//! +//! `` is the `src/` directory of the Lua tarball. + +const std = @import("std"); + +const headers = [_][]const u8{ + "lua.h", + "luaconf.h", + "lualib.h", + "lauxlib.h", + // hpp is the C++-friendly include shim shipped upstream; some C + // rocks reference it. + "lua.hpp", +}; + +pub fn main(init: std.process.Init) !void { + const arena = init.arena.allocator(); + const io = init.io; + + var args = init.minimal.args.iterate(); + defer args.deinit(); + _ = args.next(); + const embed_prefix = args.next() orelse return error.MissingEmbedPrefix; + const src_dir = args.next() orelse return error.MissingSrcDir; + const out_path = args.next() orelse return error.MissingOutPath; + + var out_file = try std.Io.Dir.cwd().createFile(io, out_path, .{}); + defer out_file.close(io); + var buf: [4096]u8 = undefined; + var writer = out_file.writer(io, &buf); + const w = &writer.interface; + + try w.writeAll( + \\//! Auto-generated. Do not edit. See build/gen_lua_headers_embed.zig. + \\ + \\pub const Entry = struct { + \\ name: []const u8, + \\ contents: []const u8, + \\}; + \\ + \\pub const files: []const Entry = &.{ + \\ + ); + + for (headers) |name| { + const abs = try std.fs.path.join(arena, &.{ src_dir, name }); + // Verify the file exists; emit nothing for missing files (lua.hpp + // exists in current Lua releases but we don't want to hard-fail + // if the tarball ever drops it). + std.Io.Dir.cwd().access(io, abs, .{}) catch continue; + const embed_path = try std.fs.path.join(arena, &.{ embed_prefix, name }); + try w.print( + " .{{ .name = \"{s}\", .contents = @embedFile(\"{s}\") }},\n", + .{ name, embed_path }, + ); + } + + try w.writeAll("};\n"); + try w.flush(); +} -- cgit v1.3