A Hatch build hook that compiles a Zig extension into the wheel.
Project description
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 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hatch_ziglang-0.1.0.tar.gz.
File metadata
- Download URL: hatch_ziglang-0.1.0.tar.gz
- Upload date:
- Size: 43.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13fd0e5e00b274aec17c7a48b3e4dec385e9262510c2a9bbe37d48da9341f23d
|
|
| MD5 |
a3e92c6fc8d4335a1035f861f0e1d0cf
|
|
| BLAKE2b-256 |
209c4ce91426fdaf180e81ef30ba85ed59290efd6713abbdca1163588167d0da
|
File details
Details for the file hatch_ziglang-0.1.0-py3-none-any.whl.
File metadata
- Download URL: hatch_ziglang-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8da6d9ac8d2f80235438def34ccd8320372259e40b731014fbd8367a5bd7fa64
|
|
| MD5 |
b9f6390e96846b5f092fbfe40af299fa
|
|
| BLAKE2b-256 |
8000cf57a48383c75ad09a4cb5da4a2c5901107ed6709d90c7515bd4818ab283
|