A dynamic versioning, Cython, PyBind11, and Raw C API building. Experimental.
Project description
Build Cub
A Hatch build hook for compiling native Python extensions. Supports Cython, PyBind11, Native C/C++, PyO3/Rust, and Gperf preprocessing with configuration-driven builds.
Features
- Multiple Backends: Cython, PyBind11, Native C/C++, PyO3/Rust, and Gperf support out of the box
- Configuration-Driven: All build settings defined in
bear_build.toml - Cross-Platform: Automatic compiler/linker arg selection for Unix and Windows
- Settings Inheritance: Define defaults once, override per-backend as needed
- Flexible Templates: Generate version files and headers with Jinja2 templates
- VCS Versioning: Automatic version extraction from git tags
NOTE
The project isn't fully ready yet so please do not use it quite yet.
Installation
pip install build-cub
With uv:
uv add build-cub
Quick Start
1. Add to your build system
In your pyproject.toml:
[build-system]
requires = ["hatchling", "build-cub"]
build-backend = "hatchling.build"
[tool.hatch.build.hooks.custom]
path = "hatch_build.py"
2. Create the build hook
Create hatch_build.py in your project root:
from build_cub.plugins import BuildCubHook
class CustomBuildHook(BuildCubHook):
PLUGIN_NAME = "custom"
3. Configure your build
Create bear_build.toml in your project root:
[general]
name = "my_package"
enabled = true
[defaults.settings]
extra_compile_args = ["-O3", "-ffast-math"]
extra_link_args = ["-O3"]
[cython]
enabled = true
targets = ["src/my_package/fast.pyx"]
[cython.compiler_directives]
language_level = "3"
boundscheck = false
wraparound = false
4. Build your package
uv build
# or
pip wheel .
Configuration Reference
General Settings
[general]
name = "my_package" # Package name
enabled = true # Master switch for all compilation
debug_symbols = false # Include debug symbols (-g flag)
Compiler Defaults
[defaults.settings]
extra_compile_args = ["-O3", "-std=c++20"]
extra_link_args = ["-O3"]
extra_compile_args_windows = ["/O2", "/std:c++20"]
extra_link_args_windows = ["/IGNORE:4099"]
include_dirs = []
library_dirs = []
libraries = []
[defaults.output_files]
lib_files = [".so", ".pyd"]
Cython Backend
[cython]
enabled = true
annotate = false # Generate HTML annotation files
quiet = true # Suppress compiler output
cleanup = true # Remove intermediate .c/.cpp files
targets = ["src/pkg/module.pyx"]
[cython.settings]
# Override defaults for this backend only
extra_compile_args = ["-O2"]
[cython.compiler_directives]
language_level = "3"
embedsignature = true
boundscheck = false
wraparound = false
cdivision = true
PyBind11 Backend
[pybind11]
enabled = true
targets = [
{ name = "bindings", sources = ["src/pkg/_cpp/bindings.cpp"] }
]
Native C/C++ Backend
[native]
enabled = true
targets = [
{ name = "core", sources = ["src/pkg/_c/core.c", "src/pkg/_cpp/utils.cpp"] }
]
PyO3 Backend
[pyo3]
enabled = true
release = true # Build in release mode (optimized)
quiet = false # Show cargo build output
features = [] # Cargo features to enable
Gperf Preprocessing
[gperf]
enabled = true
binary = "/usr/bin/gperf"
language = "C++"
Version Templates
Generate version files from Jinja2 templates:
[versioning.variables]
database = { major = 2, minor = 0, patch = 0 }
[[versioning.templates]]
output = "src/my_package/_version.py"
content = '''
__version__ = "{{ version.major }}.{{ version.minor }}.{{ version.patch }}"
__db_version__ = "{{ database.major }}.{{ database.minor }}.{{ database.patch }}"
'''
[[versioning.templates]]
output = "src/my_package/_cpp/version.hpp"
content = '''
#pragma once
constexpr int VERSION_MAJOR = {{ version.major }};
constexpr int DB_VERSION_MAJOR = {{ database.major }};
'''
The version variable is automatically injected from VCS (git tags).
Requirements
- Python 3.12+
- Hatchling build backend
- Backend-specific requirements:
- Cython backend:
cython - PyBind11 backend:
pybind11 - PyO3 backend: Rust toolchain (
rustup+cargo) - Gperf backend:
gperfbinary installed
- Cython backend:
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 Distributions
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 build_cub-0.0.27-py3-none-any.whl.
File metadata
- Download URL: build_cub-0.0.27-py3-none-any.whl
- Upload date:
- Size: 66.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c4786052ce75dca8f116439f6093007156bf4110ea02017214d3bdf25361e82
|
|
| MD5 |
d1eb8a47b6d330e2261837fcd98678d8
|
|
| BLAKE2b-256 |
069a38b327173dcb438ffc88f6a7871cef03784a10929d2b56d988d9b46ec8f3
|
Provenance
The following attestation bundles were made for build_cub-0.0.27-py3-none-any.whl:
Publisher:
build-wheels.yml on sicksubroutine/build-cub
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
build_cub-0.0.27-py3-none-any.whl -
Subject digest:
3c4786052ce75dca8f116439f6093007156bf4110ea02017214d3bdf25361e82 - Sigstore transparency entry: 1391833674
- Sigstore integration time:
-
Permalink:
sicksubroutine/build-cub@e536464d2ef06f8d18dd3d1307765c3ab41bcc32 -
Branch / Tag:
refs/tags/v0.0.27 - Owner: https://github.com/sicksubroutine
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@e536464d2ef06f8d18dd3d1307765c3ab41bcc32 -
Trigger Event:
push
-
Statement type: