Skip to content

fix: make Zig libc requirements explicit - #712

Open
cerisier wants to merge 1 commit into
cerisier/zig-static-archive-link-settingfrom
cerisier/explicit-zig-libc
Open

cerisier wants to merge 1 commit into
cerisier/zig-static-archive-link-settingfrom
cerisier/explicit-zig-libc

Conversation

@cerisier

@cerisier cerisier commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

use_cc_common_link selects the final linker for Zig binaries, tests, and shared libraries. Zig also needs to know during compilation whether the target uses libc or libc++.

Before

  • With the setting off, -lc and -lc++ from the helper dependencies reached Zig as ordinary linker flags in the combined compile and link invocation.
  • With the setting on, those dependency flags went to the C/C++ linker. The Zig compile action got a blanket -lc. That happened to give hosted binaries the C ABI main they needed, but it also forced libc mode on freestanding targets and left Zig compilation unaware of an explicit :libc++ dependency.
    A hosted binary with a :libc dependency therefore compiled with -lc in either mode, but only the combined Zig invocation got that flag from the dependency itself.

After

:libc and :libc++ have the same meaning with either linker. Rules_zig recognizes the helper labels in CcInfo so that an explicit runtime dependency configures Zig compilation and carries the corresponding flags to the final link.

Hosted targets that relied on the blanket -lc now need to declare libc explicitly. Freestanding targets can use cc_common.link with their own entry point and linker options.

Selecting cc_common.link previously forced Zig into libc mode even for freestanding targets. Use the existing libc and libc++ dependencies to configure Zig compilation while preserving their CcInfo for the final link.

Declare libc on bundled hosted tools and exercise both hosted and freestanding links.
@cerisier
cerisier added this pull request to stack #713 November 21, 2026 11:47
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