Note: The contents of this repository are a proof of concept and highly experimental. Not recommended for production use.
A minimal PEP 517 compliant build backend that uses Conan to build Python C/C++ extensions.
git clone https://github.com/conan-io/conan-py-build.git
cd conan-py-build
pip install -e .- Create a
pyproject.tomlfor your package:
[build-system]
# TODO: Change to requires = ["conan-py-build"] once published to PyPI
# For now, install manually: pip install -e .
requires = []
build-backend = "conan_py_build.build"
[project]
name = "mypackage"
version = "0.1.0"- Create a
conanfile.pywith your C++ dependencies and build logic:
from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout
class MyPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeToolchain", "CMakeDeps"
def layout(self):
cmake_layout(self)
def requirements(self):
self.requires("fmt/12.1.0")
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()- Build the wheel:
# --no-build-isolation is only needed to test while conan-py-build is not published to PyPI
pip wheel . --no-build-isolation -w dist/ -vvvFor a complete basic working example, see the basic example.
Pass configuration options via --config-settings:
| Option | Description | Default |
|---|---|---|
host-profile |
Conan profile for host context | default |
build-profile |
Conan profile for build context | default |
build-dir |
Persistent build directory | temp dir |
Jinja profiles in examples/profiles/: include(default) + wheel tags. Set CONAN_CPYTHON_VERSION to the full version (e.g. 3.12.12).
Example:
export CONAN_CPYTHON_VERSION=3.12.12
pip wheel . --no-build-isolation \
--config-settings="host-profile=examples/profiles/linux.jinja" \
--config-settings="build-dir=./build" \
-w dist/See the examples/ directory for complete working examples:
- basic: Simple Python extension using the
fmtlibrary
MIT License - see LICENSE for details.