Skip to main content

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's platinclude
  • HATCH_ZIG_EXT_SUFFIX - the building interpreter's EXT_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 - the libs directory under sys.base_prefix
  • HATCH_ZIG_PYTHON_LIB - the bare lib name (e.g. python314, python314t for 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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hatch_ziglang-0.2.1.tar.gz (44.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hatch_ziglang-0.2.1-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file hatch_ziglang-0.2.1.tar.gz.

File metadata

  • Download URL: hatch_ziglang-0.2.1.tar.gz
  • Upload date:
  • Size: 44.2 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for hatch_ziglang-0.2.1.tar.gz
Algorithm Hash digest
SHA256 4827e55dce94d24ba785023a443e761081f70d549b5ad6e84c13a6c7d487e32a
MD5 f6566c140fec9645de28dd1feab2b97a
BLAKE2b-256 6778938d813424bbfbedd9c02dced45b61ad182fe08e86b300c2b158873123f7

See more details on using hashes here.

File details

Details for the file hatch_ziglang-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: hatch_ziglang-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for hatch_ziglang-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 44e5eeb0e860fe6af735a3d5bc89b514d225274ab6f34aba711a1d3ace8dcc9b
MD5 2295a129dfd8e671ed0364d6daacb36a
BLAKE2b-256 52ce63d328edcb13344c853dca221542d8bf111fd49f388ba4c8b9d475c3abbc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page