Header paths for b.systemIntegrationOption and translate c

For Ziglua I am working on using b.systemIntegrationOption() to allow linking against a system Lua installation instead of building from source. Things are mostly working, but I’m having issues with passing the correct headers location to the translate c build step.

Here’s my branch: ziglua/build.zig at fix-75-system-integration · natecraddock/ziglua · GitHub.

I am testing with this branch in a test Zig project using zig build -fsys=lua --search-prefix /opt/homebrew. This works to find the compiled lua libraries on my system, but the translate-c step fails. The build system is running this command:

zig translate-c -lc --listen=- /Users/nathan/.cache/zig/p/12209aca1affdb0eebde27f3a5cf1c4d115fca7a4ce764815f0aa1ab7333f710fda0/include/lua_all.h

...

/Users/nathan/.cache/zig/p/12209aca1affdb0eebde27f3a5cf1c4d115fca7a4ce764815f0aa1ab7333f710fda0/include/lua_all.h:4:10: error: 'lua.h' file not found
#include "lua.h"

But it cannot find lua.h. Which makes sense because Zig won’t search the homebrew paths by default. I can get around this by using c_headers.addIncludePath(.{ .cwd_relative = "/opt/homebrew/include" }) (this is linked in my branch above). That will add the -I /opt/homebrew/include to the translate-c step so it can find the headers. But I don’t want to hardcode paths in Ziglua.

Some solutions I have thought of

  1. Use the package manager headers for the translate-c step. But this might have issues because there might be differing headers between the system and Ziglua (maybe the system has Lua 5.4.4 and Ziglua would use 5.4.7).

  2. Add a new build option to specify the path. Unless there is something already in the build system to handle this, I’ll probably do this. It just feels a bit wrong though. If Ziglua adds a new option like system-header-path, then a project that uses Ziglua would also need to expose a similar build option for those who build the project.

Any other solutions? Or is there something I’m missing? This seems like it might be a limitation in the current system package mode.

1 Like