hatch-ziglang
A Hatch build hook that compiles a Zig extension into the wheel, against the building interpreter, with no out-of-band step.
uv build / pip wheel / cibuildwheel produce a correct, platform-tagged wheel: the .so is built
during the wheel build against sys.executable, and your build.zig installs it into the package as
_<package><EXT_SUFFIX>.
Usage
Add the build requirement and configure the hook in pyproject.toml:
[build-system]
requires = ["hatchling", "hatch-ziglang", "ziglang==0.16.0"]
build-backend = "hatchling.build"
[tool.hatch.build.targets.wheel.hooks.zig]
package = "yourpkg"
optimize = "ReleaseFast" # optional; Zig -Doptimize mode (default ReleaseFast)
| key | required | description |
|---|---|---|
package |
yes | the import package directory; artifact is <package>/_<package><EXT_SUFFIX> |
optimize |
no | Zig -Doptimize mode (default ReleaseFast) |
HATCH_ZIG_BUILD_MODE overrides optimize at build time.
What build.zig receives
The hook runs zig build -Doptimize=<mode> [-Dtarget=...] and passes the interpreter paths through
two environment variables your build.zig reads:
HATCH_ZIG_PYTHON_INCLUDE- the building interpreter'splatincludeHATCH_ZIG_EXT_SUFFIX- the building interpreter'sEXT_SUFFIX(e.g..cpython-312-darwin.so)
On Windows it also passes the import library so the .pyd can link pythonXY.lib:
HATCH_ZIG_PYTHON_LIBDIR- thelibsdirectory undersys.base_prefixHATCH_ZIG_PYTHON_LIB- the bare lib name (e.g.python314,python314tfor free-threaded)
On macOS under cibuildwheel, the hook reads ARCHFLAGS and MACOSX_DEPLOYMENT_TARGET to emit a
matching -Dtarget=<arch>-macos[.<min>], so the compiled .so and the wheel tag agree and delocate
accepts the repaired wheel.
Zig is resolved from a zig on PATH, falling back to the ziglang pip package (python -m ziglang),
which works inside cibuildwheel's manylinux containers.
Metadata
Release files for hatch-ziglang 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| hatch_ziglang-0.2.1.tar.gz | 44.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hatch_ziglang-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 50.7 kB
Release files / hatch_ziglang-0.2.1.tar.gz
| Download URL | hatch_ziglang-0.2.1.tar.gz |
|---|---|
| Size | 44.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4827e55dce94d24ba785023a443e761081f70d549b5ad6e84c13a6c7d487e32a
|
|
BLAKE2b-256 checksum How to use checksums |
6778938d813424bbfbedd9c02dced45b61ad182fe08e86b300c2b158873123f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.33 {"installer":{"name":"uv","version":"0.11.33","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / hatch_ziglang-0.2.1-py3-none-any.whl
| Download URL | hatch_ziglang-0.2.1-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
44e5eeb0e860fe6af735a3d5bc89b514d225274ab6f34aba711a1d3ace8dcc9b
|
|
BLAKE2b-256 checksum How to use checksums |
52ce63d328edcb13344c853dca221542d8bf111fd49f388ba4c8b9d475c3abbc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.33 {"installer":{"name":"uv","version":"0.11.33","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|