Skip to main content

st_zig

A setuptools extension for compiling native extensions with Zig.

st_zig is a lightweight standalone package that enables setuptools to use Zig as a C/C++ compiler. By leveraging the standalone ziglang package, which is available for all PyPI-supported target platforms, this tool allows native extensions to be compiled directly on user devices.

This approach eliminates the need for users to install additional build tools, simplifying the setup process. Additionally, it removes the complexity of managing platform-specific compiler flags, particularly on Windows.

Usage

To use this package, simply add it as build requirement to your project.

Direct

The easier option to use is directly using st_zig.build_meta as build backend, which is a proxy to setuptools.build_meta and simply uses st_zig.enforce_via_build_ext during the import.

pyproject.toml

[build-system]
requires = ["st_zig"]
build-backend = "st_zig.build_meta"

Indirect

Alternatively enforce_via_build_ext or enforce_via_env can be used. st_zig.enforce_via_build_ext patches build_ext so that it picks st_zig.ZigCompiler. st_zig.enforce_via_env modifies the sysconfig read by python to make the UnixCompiler use zig, this doesn't seem to work on Windows anymore though. The UnixCompiler class, while primarily designed for Unix-like systems, works seamlessly on Windows as well. This is because Zig includes a bundled version of Clang, which ensures compatibility with Unix-style compiler flags across all platforms, including Windows.

Mind that the UnixCompiler class just describes unix focussed compilers like gcc and clang, it also works just fine on Windows. As Zig basically ships clang, you can use the same clang unix flags on all systems.

Example

setup.py

from setuptools import Extension, setup
# Add the following to your setup.py to enable Zig as the compiler
from st_zig import enforce_via_build_ext
enforce_via_build_ext()


setup(
    name="testc",
    ext_modules=[
        Extension(
            "testc",
            ["test.cpp"],
            language="c++",
            # Adjust the compile arguments based on your project's requirements
            extra_compile_args=["-std=c++23"],
        ),  # Note: The above example uses C++23. Modify the flag as needed for your project.
    ],
)

pyproject.toml

[build-system]
requires = ["setuptools", "st_zig"]
build-backend = "setuptools.build_meta"

# Add any additional configuration options below as needed
...

Metadata

Release files for st-zig 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for st-zig 0.1.1
File Size Uploaded
st_zig-0.1.1.tar.gz 4.6 kB Details

Release files / st_zig-0.1.1.tar.gz

Download URL st_zig-0.1.1.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ee2df3f5b8543b6adfb16e3bcaad4751fdc41d1910c0aa3371c48cd4a92d91a7
BLAKE2b-256 checksum
How to use checksums
922e1f13fab950acce03b842dbe54ecfe9e39dc7c59ff779a7f3c7c9ad0ec23f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 18, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page