fix: scope C dependency include paths to their module#673
Open
aherrmann wants to merge 3 commits into
Open
Conversation
Zig requires C dependencies, defined by `-I`, `-D`, and similar flags, to be passed within the corresponding Zig module's command-line section, i.e. before the `-M` flag for that module. However, rules_zig emitted all accumulated C depency flags globally at the beginning of the command-line, effectively marking all C dependencies as dependencies of the root module. This change emits C dependency flags per Zig module.
Member
Author
|
The issue was discovered in the context of #669 when trying to import zig-sqlite, where include search paths have to be set at the correct module. |
Add an e2e test for a `zig_library` `@cImport` in a transitive dependency of a `zig_binary`, i.e. at a non-root module. This is a regression test for C flags erroneously being set globally rather than per module.
aherrmann
force-pushed
the
non-root-c-import
branch
from
July 16, 2026 13:11
77a8630 to
1defb1f
Compare
On MacOS, ld fails with errors of the following form. Skip such targets. ld: multiple errors: 64-bit mach-o member 'libadd_zcu.o' not 8-byte aligned in 'bazel-out/darwin_arm64-fastbuild-ST-8e42560474ff/bin/cc-dependencies/static-library-cdeps/libadd.a'; 64-bit mach-o member 'libmul_zcu.o' not 8-byte aligned in 'bazel-out/darwin_arm64-fastbuild-ST-8e42560474ff/bin/cc-dependencies/static-library-cdeps/libmul.a'
aherrmann
force-pushed
the
non-root-c-import
branch
from
July 16, 2026 15:07
8c93d4a to
4b6a350
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Zig requires C dependencies, defined by
-I,-D, and similar flags, to be passed within the corresponding Zig module's command-line section, i.e. before the-Mflag for that module. However, rules_zig emitted all accumulated C depency flags globally at the beginning of the command-line, effectively marking all C dependencies as dependencies of the root module. This change emits C dependency flags per Zig module.