Skip to content

fix: link -lsynchronization via Zig's bundled API set on windows-gnu - #485

Merged
messense merged 1 commit into
mainfrom
fix-synchronization-import-lib
Sep 14, 2026
Merged

messense merged 1 commit into
mainfrom
fix-synchronization-import-lib

Conversation

@messense

Copy link
Copy Markdown
Member

Fixes #484

Problem

Zig doesn't ship a synchronization.def MinGW import library. The workaround from #116 copied api-ms-win-core-synch-l1-2-0.def to synchronization.def inside Zig's lib directory and discarded the copy result. On any read-only Zig install (distro packages, Nix, snap, root-owned /usr/local, system-wide ziglang pip package) nothing gets copied and the link fails with:

error: unable to find dynamic system library 'synchronization' using strategy 'paths_first'

Because cargo-zigbuild also sets WINAPI_NO_BUNDLED_LIBRARIES=1, the libsynchronization.a bundled by the winapi-*-pc-windows-gnu crates isn't available as a fallback either.

Fix

Rewrite -lsynchronization to -lapi-ms-win-core-synch-l1-2-0 in the linker arg filter for windows-gnu targets, and drop the def-copy code. That def file ships with every Zig release and is the API set that actually exports WaitOnAddress / WakeByAddress*, so Zig builds the import library itself and nothing has to be written into its lib directory.

Verification

  • Added the rewrite to the existing windows-gnu filter unit test; full cargo test passes.
  • Reproduced the issue locally by deleting synchronization.def and making Zig 0.16.0's lib-common directory read-only, then confirmed the hello-windows fixture links for both x86_64-pc-windows-gnu and i686-pc-windows-gnu with this change.
  • zig cc ... -lapi-ms-win-core-synch-l1-2-0 also links on aarch64-windows-gnu.

🤖 Generated with Claude Code

https://claude.ai/code/session_018Tpbe6r8eorFnMJuxGNKDz

Zig doesn't ship a `synchronization.def` MinGW import library. The
previous workaround copied `api-ms-win-core-synch-l1-2-0.def` to
`synchronization.def` inside Zig's lib directory and silently ignored
failures, so on read-only Zig installs (distro packages, Nix, snap, a
root-owned `/usr/local`, system-wide `ziglang` pip package) the link
failed with:

    error: unable to find dynamic system library 'synchronization'

Rewrite `-lsynchronization` to `-lapi-ms-win-core-synch-l1-2-0` in the
linker wrapper instead. That def file ships with every Zig release and
is the API set that actually exports `WaitOnAddress`/`WakeByAddress*`,
so Zig generates the import library itself and nothing has to be
written into its lib directory.

Fixes #484

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Tpbe6r8eorFnMJuxGNKDz
@messense
messense enabled auto-merge (squash) September 14, 2026 12:23
@messense
messense merged commit fcc8f30 into main Sep 14, 2026
45 checks passed
@messense
messense deleted the fix-synchronization-import-lib branch September 14, 2026 12:42
@ClementNerma

Copy link
Copy Markdown

Wow so quick! Thank you very much :D

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.

Cannot build for x86_64-pc-windows-gnu from Linux

2 participants