Skip to main content

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'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.

Project details


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.0.tar.gz (44.0 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.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hatch_ziglang-0.2.0.tar.gz
  • Upload date:
  • Size: 44.0 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

Hashes for hatch_ziglang-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8db550a9a63d5d1ca37386de08ad73a4baf2b97d7a3645b2e681eb89f946a8b1
MD5 e757e9b3a6e58fa8dfbea4679c0664db
BLAKE2b-256 5399156e88c3796dda9ed32357525aee9512dd014b42f8b1ba8ab614bc27d9b2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hatch_ziglang-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 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

Hashes for hatch_ziglang-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6cb0c1f3194db49cd50d7e316e33491b63ef4027d1445e22bc57a6e6008a5047
MD5 2cc8d22bbb0ab29389bc40667d1e7b2c
BLAKE2b-256 b47bc907c9a919967fd565b588ecd6296e11d521e59cc167844bb888f3077899

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 Pingdom Monitoring Sentry Error logging StatusPage Status page