Skip to content

fix: scope C dependency include paths to their module#673

Open
aherrmann wants to merge 3 commits into
mainfrom
non-root-c-import
Open

fix: scope C dependency include paths to their module#673
aherrmann wants to merge 3 commits into
mainfrom
non-root-c-import

Conversation

@aherrmann

Copy link
Copy Markdown
Member

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.

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.
@aherrmann

Copy link
Copy Markdown
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.

@aherrmann
aherrmann requested a review from cerisier July 16, 2026 13:08
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
aherrmann force-pushed the non-root-c-import branch from 77a8630 to 1defb1f Compare July 16, 2026 13:11
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
aherrmann force-pushed the non-root-c-import branch from 8c93d4a to 4b6a350 Compare July 16, 2026 15:07
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.

1 participant