ziglang / zig-pypi

The Zig programming language, packaged for PyPI
https://pypi.org/project/ziglang/
MIT License
151 stars 18 forks source link

Build wheels for Windows 32-bit (i.e., `ziglang-0.X.Y-py3-none-win32.whl`) #18

Closed agriyakhetarpal closed 6 months ago

agriyakhetarpal commented 6 months ago

Description

Hi! I see on https://ziglang.org/download/ that since versions v0.10.0 and later the Zig programming language has had 32-bit binaries, and it now regularly publishes binaries for development versions of v0.13.0 at the time of writing; I wonder if it would be possible to build 32-bit Windows wheels based on those binaries and ship them with PyPI as well.

Proposed implementation

I see that make_wheels.py is used to build wheels instead of the traditional setup.py format, and no source distributions are distributed, as described in #2 – that makes sense.

I think this should be done by:

  1. adding an x86-windows key-value pair to the ZIG_PYTHON_PLATFORMS constant, and
  2. the platform tag for the wheel should then be mapped to win32 – which is the value of sysconfig.get_platform(), mostly, but it can be better extracted from wheel.bdist.wheel.get_tag in these lines: https://github.com/ziglang/zig-pypi/blob/33c05bb038fb2fc37cde1496e415dcbb1297bc6f/make_wheels.py#L130-L135
  3. and then these lines https://github.com/ziglang/zig-pypi/blob/33c05bb038fb2fc37cde1496e415dcbb1297bc6f/make_wheels.py#L152-L165 can then download this extra platform with urllib and package the binary up into an extra wheel without ABI tags as usual.

The command-line argument parser can then work as usual, just with a new available option.

Additional context

I would be happy to implement the changes myself here – they look quite minimal, and would be happy to get a chance to contribute :) I have decided to open an issue first to gauge thoughts from maintainers and core developers.

I'm using zig cc as a build-time dependency for my Python package for cross-compiling uses, where the absence of a 32-bit Windows wheel would break building off of the source distribution (since a source distribution isn't planned or worth any use for Zig and just wheels are uploaded). I can very well remove that breakage with a conditional dependency specifier in the form of something like

[build-system]
requires = [
  "setuptools>=64",
  "wheel==0.42.0",
  "ziglang==0.11.0; platform_machine != 'x86' and platform_system == 'Windows'",
  ]
build-backend = "setuptools.build_meta"

to restrict it for just this platform and architecture (while keeping it for others), but since PyPI's Zig isn't being built from source, I thought I should really propose the addition here.

agriyakhetarpal commented 6 months ago

Ah, I see that there have been issues with Zig on i386 before :) based on #8 and https://github.com/ziglang/zig/issues/537. I still think providing a binary through PyPI would be useful even if the release is not offering top-tier support for users, considering that the Downloads page has it.

whitequark commented 6 months ago

I still think providing a binary through PyPI would be useful even if the release is not offering top-tier support for users, considering that the Downloads page has it.

Sure--happy to merge a PR!

whitequark commented 6 months ago

I built 32-bit wheels, can you please confirm that these wheels work well? https://mega.nz/file/MlwliBoL#FtiKyeygLHczynTRKPpvexm-ET1clP-g4hHrIqaqZgY

whitequark commented 6 months ago

I didn't test them on Windows but on a 32-bit wineprefix they work fine.

agriyakhetarpal commented 6 months ago

I think so, too. I don't have easy access to a Windows build :) thanks for the merge!

whitequark commented 6 months ago

I've uploaded both 0.11.0 and 0.12.0 win32 wheels to PyPI.

https://pypi.org/project/ziglang/0.12.0/ https://pypi.org/project/ziglang/0.11.0/