@@ -3,7 +3,9 @@ const std = @import("std");
33const Build = std .Build ;
44const Step = std .Build .Step ;
55
6- const applyPatchToFile = @import ("utils.zig" ).applyPatchToFile ;
6+ const utils = @import ("utils.zig" );
7+ const applyPatchToFile = utils .applyPatchToFile ;
8+ const concatenateFiles = utils .concatenateFiles ;
79
810const build = @import ("../build.zig" );
911
@@ -56,6 +58,8 @@ pub fn configure(
5658
5759 const user_header = "user.h" ;
5860
61+ const enable_apicheck = opts .api_check == .on or (opts .api_check == .debug and optimize == .Debug );
62+
5963 const flags = [_ ][]const u8 {
6064 // Standard version used in Lua Makefile
6165 "-std=gnu99" ,
@@ -69,12 +73,12 @@ pub fn configure(
6973 },
7074
7175 // Enable api check
72- if (opts . api_check == .on or ( opts . api_check == .debug and optimize == .Debug ) ) "-DLUA_USE_APICHECK" else "" ,
76+ if (lang == .lua55 and enable_apicheck ) "-DLUA_USE_APICHECK" else "" ,
7377
7478 // Build as DLL for windows if shared
7579 if (target .result .os .tag == .windows and shared ) "-DLUA_BUILD_AS_DLL" else "" ,
7680
77- if (lua_user_h ) | _ | b .fmt ("-DLUA_USER_H=\" {s}\" " , .{user_header }) else "" ,
81+ if (enable_apicheck or lua_user_h != null ) b .fmt ("-DLUA_USER_H=\" {s}\" " , .{user_header }) else "" ,
7882 };
7983
8084 const lua_source_files = switch (lang ) {
@@ -110,8 +114,19 @@ pub fn configure(
110114 library .installHeader (upstream .path ("src/luaconf.h" ), "luaconf.h" );
111115
112116 if (lua_user_h ) | user_h | {
113- library .root_module .addIncludePath (user_h .dirname ());
114- library .installHeader (user_h , user_header );
117+ if (enable_apicheck ) {
118+ const concat = concatenateFiles (b , b .graph .host , user_h , b .path ("src/user.h" ), user_header );
119+ library .step .dependOn (& concat .run .step );
120+
121+ library .root_module .addIncludePath (concat .output .dirname ());
122+ library .installHeader (concat .output , user_header );
123+ } else {
124+ library .root_module .addIncludePath (user_h .dirname ());
125+ library .installHeader (user_h , user_header );
126+ }
127+ } else if (enable_apicheck ) {
128+ library .root_module .addIncludePath (b .path ("src" ));
129+ library .installHeader (b .path ("src/user.h" ), user_header );
115130 }
116131
117132 return library ;
0 commit comments