std.Build.Module.linkSystemLibrary() breaks target inheritance #20042
Labels
enhancement
Solving this issue will likely involve adding new logic or components to the codebase.
zig build system
std.Build, the build runner, `zig build` subcommand, package management
Milestone
Zig Version
0.12.0 (nothing looks to have changed on master)
Steps to Reproduce and Observed Behavior
I have a
zig-wlroots
package with idiomatic Zig bindings to the wlroots C library. This package exposes awlroots
Zig module that internally uses@cImport()
to obtain the wlroots version defined in the installed C headers:https://codeberg.org/ifreund/zig-wlroots/src/commit/938a314162ee5ec9abc6dc8e6e930d5e52c87a8b/src/version.zig
This means that the
wlroots
Zig module must be provided with the include path for the wlroots C headers, which in turn should be obtained usingpkg-config
. Currently, the onlypkg-config
integeration instd.Build
is thelinkSystemLibrary()
function.The problem is that calling
std.Build.Module.linkSystemLibrary()
on thewlroots
module errors due to this line:zig/lib/std/Build/Module.zig
Line 431 in 9be8a90
which requires the target to be explicitly specified rather than inherited.
My current workaround is to set the
Module.resolved_target
field directly before callingModule.linkSystemLibrary()
:https://codeberg.org/river/river/src/commit/7fdba05b8249b10d10a2c64c1175429539c01af1/build.zig#L148-L149
Expected Behavior
There are many different changes that could be made which would support this specific use-case well. I'm not sure which option makes the most sense. Here are some reasonable options I can think of:
Make modules inherit include paths from their parent compilation. This would side-step the issue entirely and I would only need a single
linkSystemLibrary()
call for the parent compilation.Add a new
std.Build
API to usepkg-config
to only add the required include paths, not link the library. Don't synchronously require a resolved target in this newModule.addIncludePathPkgConfig()
function.Change
Module.linkSystemLibrary()
to not synchronously require a resolved target. It currently uses this to determine if the requested library name is actually part of libc/libc++. This check could however be deferred untilstd.Build.Complie.make()
if I'm not mistaken.I don't have a strong opinion on which of these approaches is the best.
The text was updated successfully, but these errors were encountered: