Install C extension sdists without requiring a pre-installed compiler

I’ve been playing around with the Zig toolchain. One very interesting thing I found recently is that Zig’s toolchain, being completely self-contained, portable, and extremely compact, is being distributed on PyPI as an installable Python package. Combining with the fact that the Zig compiler has first-class support compiling C code, this means any sdist can acquire a working C compiler by simply adding ziglang as a PEP 517 build dependency. With some glue code around the compiler, I was able to produce a PEP 517 backend (using Flit internals) that can produce non-pure wheels that Works On My Machines™ by only declarative pyproject.toml definitions, without setuptools or an external compiler setup.

Project: zlig · PyPI

Example: zlig/examples/demo at main · uranusjr/zlig · GitHub

This thing is likely not very useful itself, but I feel the Zig compiler route is very much worth investigating for anyone interested in improving the native module landscape beyond what we have in setuptools.

18 Likes

A great step forward in distribution :100:

Very nice, but I would challenge “extremely compact” when the ziglang wheels are 60+MB downloads.

Sorry for necrobumping this, but I came here through this OP comment. I was at PyCon Italy this week and Loris Cro (VP of community of Zig) gave a talk exactly about this. The live is here: the talk should start at 3:02:26 and lasts for some ~30 minutes.

Definitely not “extremely compact” but I wouldn’t bother over the size. It’s just a build-time dependency and the libraries that would benefit from that are already quite big. IIUC, this would also mean you have to run less VMs in your CI and install fewer dependencies from PyPI.