Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub fn build(b: *Build) void {
const lang = b.option(Language, "lang", "Lua language version to build") orelse .lua54;
const library_name = b.option([]const u8, "library_name", "Library name for lua linking, default is `lua`") orelse "lua";
const shared = b.option(bool, "shared", "Build shared library instead of static") orelse false;
const system_lua = b.option(bool, "system_lua", "Use system lua") orelse false;
const luau_use_4_vector = b.option(bool, "luau_use_4_vector", "Build Luau to use 4-vectors instead of the default 3-vector.") orelse false;
const lua_user_h = b.option(Build.LazyPath, "lua_user_h", "Lazy path to user supplied c header file") orelse null;

Expand All @@ -30,22 +31,36 @@ pub fn build(b: *Build) void {
}

// Zig module
const zlua = b.addModule("zlua", .{
const zlua = if (system_lua) b.addModule("zlua", .{
.root_source_file = b.path("src/lib.zig"),
.target = target,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can't cross compile when using system lua so this should be fine

}) else b.addModule("zlua", .{
.root_source_file = b.path("src/lib.zig"),
});

// Expose build configuration to the ziglua module
const config = b.addOptions();
config.addOption(Language, "lang", lang);
config.addOption(bool, "luau_use_4_vector", luau_use_4_vector);
config.addOption(bool, "system_lua", system_lua);
zlua.addOptions("config", config);

if (lang == .luau) {
const vector_size: usize = if (luau_use_4_vector) 4 else 3;
zlua.addCMacro("LUA_VECTOR_SIZE", b.fmt("{}", .{vector_size}));
}

if (b.lazyDependency(@tagName(lang), .{})) |upstream| {
if (system_lua) {
const link_mode: std.builtin.LinkMode = if (shared) .dynamic else .static;
switch (lang) {
.lua51 => zlua.linkSystemLibrary("lua5.1", .{ .preferred_link_mode = link_mode }),
.lua52 => zlua.linkSystemLibrary("lua5.2", .{ .preferred_link_mode = link_mode }),
.lua53 => zlua.linkSystemLibrary("lua5.3", .{ .preferred_link_mode = link_mode }),
.lua54 => zlua.linkSystemLibrary("lua5.4", .{ .preferred_link_mode = link_mode }),
.luajit => zlua.linkSystemLibrary("luajit", .{ .preferred_link_mode = link_mode }),
.luau => @panic("luau not supported for system lua"),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the luau package in my distro doesn't come with libraries or headers

}
} else if (b.lazyDependency(@tagName(lang), .{})) |upstream| {
const lib = switch (lang) {
.luajit => luajit_setup.configure(b, target, optimize, upstream, shared),
.luau => luau_setup.configure(b, target, optimize, upstream, luau_use_4_vector),
Expand Down
11 changes: 9 additions & 2 deletions src/lib.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@ const std = @import("std");
pub const def = @import("define.zig");
pub const define = def.define;

const c = @import("c");

const config = @import("config");

const c = if (config.system_lua)
@cImport({
@cInclude("lua.h");
@cInclude("lualib.h");
@cInclude("lauxlib.h");
})
else
@import("c");

/// Lua language version targeted
pub const lang = config.lang;

Expand Down
Loading