Scikit-build
Scikit-build is a Python build system that acts as a glue layer between `setuptools` and `CMake` to facilitate the building of CPython C/C++/Fortran/Cython extensions. It is currently at version 0.19.0 and has an active development cycle, with a focus on fixing bugs and improving compatibility. The next generation, `scikit-build-core`, is under active development and offers a more modern, standalone approach without direct reliance on `setuptools`.
Warnings
- breaking Python 3.7 support was dropped in scikit-build 0.19.0. Ensure your projects target Python 3.8 or newer.
- breaking Scikit-build 0.19.0 includes updates for changes in newer `setuptools` versions (e.g., setuptools 74) and `CMake 4`. The `dry-run` option was also removed due to setuptools changes. Older versions of setuptools may no longer be compatible.
- gotcha Scikit-build is the 'classic' setuptools-based integration. For new projects, consider `scikit-build-core`, which is a ground-up rewrite that acts as a standalone build backend without direct `setuptools` dependency and offers improved features and stability.
- gotcha Editable installs using `scikit-build` (classic) often do not work correctly with recent versions of `setuptools`.
- gotcha The `_skbuild` cache directory may need to be manually deleted between builds, especially if changing the Python interpreter or encountering unexpected build issues.
- breaking Minimum required CMake version is 3.5 since scikit-build 0.18.0. Additionally, older CMake versions (<3.24) may break when a library is specified, as fixed in 0.17.1.
- deprecated The behavior of directly driving the CMake build of a module via `setup.py` (`python setup.py build_ext --inplace`) is considered legacy and is no longer the recommended approach. Scikit-build's primary utility is driving the generation of Python distributables for PyPI.
Install
-
pip install scikit-build
Imports
- setup
from skbuild import setup
Quickstart
# pyproject.toml
[build-system]
requires = ["setuptools>=42", "scikit-build>=0.13", "cmake>=3.18", "ninja"]
build-backend = "setuptools.build_meta"
[project]
name = "hello-cpp"
version = "0.0.1"
# setup.py
# This file would be in the same directory as pyproject.toml
# In a 'hello' subdirectory, you would have a '_hello.cxx' and '__init__.py'
# In the project root, you would also have a 'CMakeLists.txt'
from skbuild import setup
setup(
name="hello-cpp",
version="0.0.1",
description="A minimal C++ extension package using scikit-build",
author='The scikit-build team',
license="MIT",
packages=['hello'],
python_requires=">=3.8",
)
# CMakeLists.txt (example content, not runnable Python):
# cmake_minimum_required(VERSION 3.18...3.22)
# project(hello CXX)
# find_package(PythonExtensions REQUIRED)
# add_library(_hello MODULE hello/_hello.cxx)
# python_extension_module(_hello)
# install(TARGETS _hello LIBRARY DESTINATION hello)