Skip to content

Add build option to provide an additional header file to the Lua compilation #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

hubidubi13
Copy link

@hubidubi13 hubidubi13 commented Jun 24, 2025

resolves #143

Supplying the option as a std.Builld.LazyPath and expanding relative paths might not be the most elegant option, but it works for both the examples and when used as a module.

Alternatively to this solution, ziglua could provide its own header file and expose some functions a user would have to implement (like lua_zlock). But this would require additional flags or some structure containing all the options. Delegating the header to the user seems simpler and more flexible to me. (I am not sure how much this feature is going to be used anyways :D)

Copy link
Collaborator

@robbielyman robbielyman left a comment

Choose a reason for hiding this comment

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

i'm a bit concerned about the user_h.getPath3 call—could you make sure that this is an acceptable method for consumers of the Zig build system to be using? in particular, i'm concerned about whether this build script works correctly in the case that the lua_user_h file is generated at build time.

also the orelse null should be deleted, since it does nothing.

build.zig Outdated
@@ -18,11 +18,24 @@ pub fn build(b: *Build) void {
const lang = b.option(Language, "lang", "Lua language version to build") orelse .lua54;
const shared = b.option(bool, "shared", "Build shared library instead of static") 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;
var lua_user_h = b.option(Build.LazyPath, "lua_user_h", "Lazy path to user supplied c header file") orelse null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

both var and orelse null are code smells.

build/lua.zig Outdated
@@ -55,6 +55,8 @@ pub fn configure(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.

// Build as DLL for windows if shared
if (target.result.os.tag == .windows and shared) "-DLUA_BUILD_AS_DLL" else "",

if (lua_user_h) |user_h| b.fmt("-DLUA_USER_H=\"{}\"", .{user_h.getPath3(b, null)}) else "",
Copy link
Collaborator

Choose a reason for hiding this comment

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

i'm not sure, but are authors of build scripts supposed to use getPath at all?

Copy link
Author

Choose a reason for hiding this comment

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

Probably not, that was rather sloppy. Actually using the provided addIncludePath and installHeader seems to be the way to do it properly. This also solves the var code smell from above.

Simon Galli added 2 commits July 2, 2025 10:22
@hubidubi13
Copy link
Author

At this point, maybe an options struct being passed to the configure calls could help with extensibility.

@hubidubi13 hubidubi13 requested a review from robbielyman July 2, 2025 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose LUA_USER_H as a build option
2 participants