@@ -44,14 +44,35 @@ pub fn build(b: *Build) void {
4444 const config = b .addOptions ();
4545 config .addOption (Language , "lang" , lang );
4646 config .addOption (bool , "luau_use_4_vector" , luau_use_4_vector );
47- config .addOption (bool , "system_lua" , system_lua );
4847 zlua .addOptions ("config" , config );
4948
5049 if (lang == .luau ) {
5150 const vector_size : usize = if (luau_use_4_vector ) 4 else 3 ;
5251 zlua .addCMacro ("LUA_VECTOR_SIZE" , b .fmt ("{}" , .{vector_size }));
5352 }
5453
54+ // Translate the Lua C headers in to Zig code.
55+ const translate_c = b .dependency ("translate_c" , .{});
56+
57+ const c_header_path = switch (lang ) {
58+ .luajit = > b .path ("build/include/luajit_all.h" ),
59+ .luau = > b .path ("build/include/luau_all.h" ),
60+ else = > b .path ("build/include/lua_all.h" ),
61+ };
62+ const t : Translator = .init (translate_c , .{
63+ .c_source_file = c_header_path ,
64+ .target = target ,
65+ .optimize = optimize ,
66+ });
67+
68+ // If we've been given additional system headers, add them now.
69+ // Useful for things like linking Emscripten headers by including a new sysroot
70+ if (additional_system_headers ) | headers | {
71+ t .addSystemIncludePath (headers );
72+ }
73+
74+ zlua .addImport ("c" , t .mod );
75+
5576 if (system_lua ) {
5677 const link_mode : std.builtin.LinkMode = if (shared ) .dynamic else .static ;
5778 switch (lang ) {
@@ -81,28 +102,8 @@ pub fn build(b: *Build) void {
81102
82103 zlua .linkLibrary (lib );
83104
84- // lib must expose all headers included by these root headers
85- const c_header_path = switch (lang ) {
86- .luajit = > b .path ("build/include/luajit_all.h" ),
87- .luau = > b .path ("build/include/luau_all.h" ),
88- else = > b .path ("build/include/lua_all.h" ),
89- };
90- const translate_c = b .dependency ("translate_c" , .{});
91-
92- const t : Translator = .init (translate_c , .{
93- .c_source_file = c_header_path ,
94- .target = target ,
95- .optimize = optimize ,
96- });
105+ // Ensure translate C can find the Lua headers.
97106 t .addIncludePath (lib .getEmittedIncludeTree ());
98-
99- // If we've been given additional system headers, add them now
100- // Useful for things like linking Emscripten headers by including a new sysroot
101- if (additional_system_headers != null ) {
102- t .addSystemIncludePath (additional_system_headers .? );
103- }
104-
105- zlua .addImport ("c" , t .mod );
106107 }
107108
108109 // Tests
0 commit comments