@@ -18,6 +18,7 @@ pub fn build(b: *Build) void {
1818 const lang = b .option (Language , "lang" , "Lua language version to build" ) orelse .lua54 ;
1919 const library_name = b .option ([]const u8 , "library_name" , "Library name for lua linking, default is `lua`" ) orelse "lua" ;
2020 const shared = b .option (bool , "shared" , "Build shared library instead of static" ) orelse false ;
21+ const system = b .option (bool , "system" , "Use system lua" ) orelse false ;
2122 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 ;
2223 const lua_user_h = b .option (Build .LazyPath , "lua_user_h" , "Lazy path to user supplied c header file" ) orelse null ;
2324
@@ -30,22 +31,36 @@ pub fn build(b: *Build) void {
3031 }
3132
3233 // Zig module
33- const zlua = b .addModule ("zlua" , .{
34+ const zlua = if (system ) b .addModule ("zlua" , .{
35+ .root_source_file = b .path ("src/lib.zig" ),
36+ .target = target , // can't cross compile with system lua
37+ }) else b .addModule ("zlua" , .{
3438 .root_source_file = b .path ("src/lib.zig" ),
3539 });
3640
3741 // Expose build configuration to the ziglua module
3842 const config = b .addOptions ();
3943 config .addOption (Language , "lang" , lang );
4044 config .addOption (bool , "luau_use_4_vector" , luau_use_4_vector );
45+ config .addOption (bool , "system" , system );
4146 zlua .addOptions ("config" , config );
4247
4348 if (lang == .luau ) {
4449 const vector_size : usize = if (luau_use_4_vector ) 4 else 3 ;
4550 zlua .addCMacro ("LUA_VECTOR_SIZE" , b .fmt ("{}" , .{vector_size }));
4651 }
4752
48- if (b .lazyDependency (@tagName (lang ), .{})) | upstream | {
53+ if (system ) {
54+ const link_mode : std.builtin.LinkMode = if (shared ) .dynamic else .static ;
55+ switch (lang ) {
56+ .lua51 = > zlua .linkSystemLibrary ("lua5.1" , .{ .preferred_link_mode = link_mode }),
57+ .lua52 = > zlua .linkSystemLibrary ("lua5.2" , .{ .preferred_link_mode = link_mode }),
58+ .lua53 = > zlua .linkSystemLibrary ("lua5.3" , .{ .preferred_link_mode = link_mode }),
59+ .lua54 = > zlua .linkSystemLibrary ("lua5.4" , .{ .preferred_link_mode = link_mode }),
60+ .luajit = > zlua .linkSystemLibrary ("luajit" , .{ .preferred_link_mode = link_mode }),
61+ .luau = > @panic ("luau not handled" ),
62+ }
63+ } else if (b .lazyDependency (@tagName (lang ), .{})) | upstream | {
4964 const lib = switch (lang ) {
5065 .luajit = > luajit_setup .configure (b , target , optimize , upstream , shared ),
5166 .luau = > luau_setup .configure (b , target , optimize , upstream , luau_use_4_vector ),
0 commit comments