summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
authorT <t@tjp.lol>2026-05-26 10:33:24 -0600
committerT <t@tjp.lol>2026-05-26 10:42:41 -0600
commitedad4fc123099a780d960feea4fe37efb6d979d8 (patch)
tree7fea8bf150fb80af493d7da65417872a4df460e5 /build.zig
parentc2f727e188c1558bcc6b34569af2feab3b0366c0 (diff)
include and link lua 5.4, smoke test in panto cli main.zig
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig69
1 files changed, 69 insertions, 0 deletions
diff --git a/build.zig b/build.zig
index 5d4cdb6..e675859 100644
--- a/build.zig
+++ b/build.zig
@@ -9,13 +9,21 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
});
+ // Fetch upstream Lua 5.4.7 (source-only tarball from lua.org).
+ // Reproducibility comes from the content-addressed hash in build.zig.zon.
+ const lua_src = b.dependency("lua_src", .{});
+ const lua = buildLua(b, target, optimize, lua_src);
+
// CLI executable
const exe_mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
+ .link_libc = true,
});
exe_mod.addImport("panto", panto_lib_dep.module("panto"));
+ exe_mod.linkLibrary(lua);
+ exe_mod.addIncludePath(lua_src.path("src"));
const exe = b.addExecutable(.{
.name = "panto",
@@ -38,8 +46,11 @@ pub fn build(b: *std.Build) void {
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
+ .link_libc = true,
});
test_mod.addImport("panto", panto_lib_dep.module("panto"));
+ test_mod.linkLibrary(lua);
+ test_mod.addIncludePath(lua_src.path("src"));
const unit_tests = b.addTest(.{
.name = "panto-tests",
@@ -54,3 +65,61 @@ pub fn build(b: *std.Build) void {
const lib_test_step = panto_lib_dep.builder.top_level_steps.get("test").?;
test_step.dependOn(&lib_test_step.step);
}
+
+/// Compile Lua 5.4.7 as a static library against the upstream source tarball.
+/// Excludes `lua.c` (interpreter REPL) and `luac.c` (bytecode compiler) — we
+/// only want the embedded library.
+fn buildLua(
+ b: *std.Build,
+ target: std.Build.ResolvedTarget,
+ optimize: std.builtin.OptimizeMode,
+ lua_src: *std.Build.Dependency,
+) *std.Build.Step.Compile {
+ const lua_mod = b.createModule(.{
+ .target = target,
+ .optimize = optimize,
+ .link_libc = true,
+ });
+
+ const cflags = [_][]const u8{
+ "-std=gnu99",
+ "-Wall",
+ "-Wextra",
+ "-Wno-unused-parameter",
+ };
+
+ lua_mod.addCSourceFiles(.{
+ .root = lua_src.path("src"),
+ .files = &lua_files,
+ .flags = &cflags,
+ });
+
+ // Tell Lua which platform features are available. The macros change
+ // which `dlopen`/readline/etc. paths Lua compiles in.
+ switch (target.result.os.tag) {
+ .macos => lua_mod.addCMacro("LUA_USE_MACOSX", ""),
+ .linux => lua_mod.addCMacro("LUA_USE_LINUX", ""),
+ .freebsd, .netbsd, .openbsd => lua_mod.addCMacro("LUA_USE_POSIX", ""),
+ else => {},
+ }
+
+ return b.addLibrary(.{
+ .name = "lua",
+ .linkage = .static,
+ .root_module = lua_mod,
+ });
+}
+
+// Lua 5.4.7 core VM + standard library. Excludes lua.c (interpreter entry
+// point) and luac.c (compiler entry point).
+const lua_files = [_][]const u8{
+ // Core VM
+ "lapi.c", "lcode.c", "lctype.c", "ldebug.c", "ldo.c",
+ "ldump.c", "lfunc.c", "lgc.c", "llex.c", "lmem.c",
+ "lobject.c", "lopcodes.c", "lparser.c", "lstate.c", "lstring.c",
+ "ltable.c", "ltm.c", "lundump.c", "lvm.c", "lzio.c",
+ // Auxiliary + standard library
+ "lauxlib.c", "lbaselib.c", "lcorolib.c", "ldblib.c", "liolib.c",
+ "lmathlib.c", "loadlib.c", "loslib.c", "lstrlib.c", "ltablib.c",
+ "lutf8lib.c", "linit.c",
+};