summaryrefslogtreecommitdiff
path: root/build
diff options
context:
space:
mode:
Diffstat (limited to 'build')
-rw-r--r--build/gen_panto_so_embed.zig42
1 files changed, 42 insertions, 0 deletions
diff --git a/build/gen_panto_so_embed.zig b/build/gen_panto_so_embed.zig
new file mode 100644
index 0000000..37b8329
--- /dev/null
+++ b/build/gen_panto_so_embed.zig
@@ -0,0 +1,42 @@
+//! Build-time codegen: emit a Zig module exposing the compiled
+//! `libpanto-lua` shared object (`panto.so`) as embedded bytes. Bootstrap
+//! writes these to `<tree>/lib/lua/<short>/panto.so` on first run so the
+//! embedded VM's `require('panto')` resolves to the native module on a
+//! cold machine with no network — the guaranteed initial module load.
+//!
+//! Invoked from `build.zig`:
+//!
+//! gen-panto-so-embed <embed-name> <out-file>
+//!
+//! `<embed-name>` is the filename the generated module `@embedFile`s; the
+//! actual `.so` is materialized alongside the generated file under that
+//! name via `addCopyFile` so `@embedFile` can reach it.
+
+const std = @import("std");
+
+pub fn main(init: std.process.Init) !void {
+ const io = init.io;
+
+ var args = init.minimal.args.iterate();
+ defer args.deinit();
+ _ = args.next();
+ const embed_name = args.next() orelse return error.MissingEmbedName;
+ 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.print(
+ \\//! Auto-generated. Do not edit. See build/gen_panto_so_embed.zig.
+ \\
+ \\/// The compiled `libpanto-lua` shared object, embedded so the
+ \\/// bootstrap can stage it onto the embedded VM's `package.cpath`.
+ \\pub const bytes: []const u8 = @embedFile("{s}");
+ \\
+ , .{embed_name});
+
+ try w.flush();
+}