Skip to content

fix: auto-generate .def file for zig + windows-gnu to export PyInit symbol#3079

Merged
messense merged 1 commit intoPyO3:mainfrom
messense:fix/zig-windows-gnu-pyinit-export
Mar 10, 2026
Merged

fix: auto-generate .def file for zig + windows-gnu to export PyInit symbol#3079
messense merged 1 commit intoPyO3:mainfrom
messense:fix/zig-windows-gnu-pyinit-export

Conversation

@messense
Copy link
Member

When using zig as the linker for windows-gnu targets, the PyInit_<module> symbol is not exported, causing Python to fail to import the module.

This generates a .def file in target/maturin/ that explicitly exports the symbol, passed to the linker via -C link-arg.

Also refactors target/maturin directory creation into a shared ensure_target_maturin_dir() helper used by compile and repair.

Fixes #922

…t` symbol

When using zig as the linker for windows-gnu targets, the `PyInit_<module>`
symbol is not exported, causing Python to fail to import the module.

This generates a `.def` file in `target/maturin/` that explicitly exports the
symbol, passed to the linker via `-C link-arg`.

Also refactors `target/maturin` directory creation into a shared
`ensure_target_maturin_dir()` helper used by compile and repair.

Fixes PyO3#922
@messense messense force-pushed the fix/zig-windows-gnu-pyinit-export branch from 1143c9b to 58ef24f Compare March 10, 2026 00:22
@messense messense merged commit ef0e0a6 into PyO3:main Mar 10, 2026
44 of 45 checks passed
@messense messense deleted the fix/zig-windows-gnu-pyinit-export branch March 10, 2026 01:44
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.

maturin build --target x86_64-pc-windows-gnu --zig results in a broken module

1 participant