scikit-build-core
[!NOTE]
We have a public Scikit-build community meeting every month!
Join us on Google Meet on the third
Friday of every month at 12:00 PM EST. We also have a developer's meeting on
the first Friday of every month at the same time. Our past meeting minutes are
available here.
Scikit-build-core is a build backend for Python that uses CMake to build
extension modules. It has a simple yet powerful static configuration system in
pyproject.toml, and supports almost unlimited flexibility via CMake. It was
initially developed to support the demanding needs of scientific users, but can
build any sort of package that uses CMake.
Scikit-build-core is a ground-up rewrite of the classic Scikit-build. The key
features of scikit-build classic (which is setuptools based) are also present
here:
- Great support for or by most OSs, compilers, IDEs, and libraries
- Support for C++ features and other languages like Fortran
- Support for multithreaded builds
- Simple CMakeFiles.txt instead of up to thousands of lines of fragile
setuptools/distutils code
- Cross-compile support for Apple Silicon and Windows ARM
Scikit-build-core was built using Python packaging standards developed after
scikit-build (classic) was written. Using it directly provides the following
features over classic Scikit-build:
- Better warnings, errors, and logging
- No warning about unused variables
- Automatically adds Ninja and/or CMake only as required
- No dependency on setuptools, distutils, or wheel
- Powerful config system, including config options support
- Automatic inclusion of site-packages in
CMAKE_PREFIX_PATH
- FindPython is backported if running on CMake < 3.26.1 (configurable), supports
PyPY SOABI & Limited API / Stable ABI
- Limited API / Stable ABI and pythonless tags supported via config option
- No slow generator search, ninja/make or MSVC used by default, respects
CMAKE_GENERATOR
- SDists are reproducible by default (UNIX, Python 3.9+, uncompressed comparison
recommended)
- Support for caching between builds (opt-in by setting
build-dir
) - Support for writing out to extra wheel folders (scripts, headers, data)
- Support for selecting install components and build targets
- Dedicated entrypoints for module and prefix directories
- Several integrated dynamic metadata plugins (proposing standardized support
soon)
- Experimental editable mode support, with optional experimental auto rebuilds
on import and optional in-place mode
- Supports WebAssembly (Emscripten/Pyodide).
- Supports free-threaded Python 3.13.
The following limitations are present compared to classic scikit-build:
- The minimum supported CMake is 3.15
- The minimum supported Python is 3.7
Some known missing features that will be developed soon:
- Wheels are not fully reproducible yet (nor are they in most others systems,
including setuptools)
- Several editable mode caveats (mentioned in the docs).
Other backends are also planned:
- Setuptools integration highly experimental
- Hatchling plugin highly experimental
The recommended interface is the native pyproject builder. There is also a WIP
setuptools-based interface that is being developed to provide a transition path
for classic scikit-build, and a WIP Hatchling plugin. Both might be moved to
standalone packages in the future.
[!WARNING]
Only the pyproject-based builder should be used; the setuptools backend is
experimental and likely to move to a separate package before being declared
stable, and internal API is still being solidified. A future version of this
package will support creating new build extensions.
Example
To use scikit-build-core, add it to your build-system.requires
, and specify
the scikit_build_core.build
builder as your build-system.build-backend
. You
do not need to specify cmake
or ninja
; scikit-build-core will require them
automatically if the system versions are not sufficient.
[build-system]
requires = ["scikit-build-core"]
build-backend = "scikit_build_core.build"
[project]
name = "scikit_build_simplest"
version = "0.0.1"
You can (and should) specify the rest of the entries in project
, but these are
the minimum to get started.
An example CMakeLists.txt
:
cmake_minimum_required(VERSION 3.15...3.30)
project(${SKBUILD_PROJECT_NAME} LANGUAGES C)
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
Python_add_library(_module MODULE src/module.c WITH_SOABI)
install(TARGETS _module DESTINATION ${SKBUILD_PROJECT_NAME})
Scikit-build-core will backport FindPython from CMake 3.26.1 to older versions
of Python, and will handle PyPy for you if you are building from PyPy. You will
need to install everything you want into the full final path inside site-modules
(so you will usually prefix everything by the package name).
More examples are in the
tests/packages.
Configuration
All configuration options can be placed in pyproject.toml
, passed via
-C
/--config-setting
in build or -C
/--config-settings
in pip
, or set
as environment variables. tool.scikit-build
is used in toml, skbuild.
for
-C
options, or SKBUILD_*
for environment variables. The defaults are listed
below:
[tool.scikit-build]
cmake.version = ""
cmake.args = []
cmake.define = {}
cmake.verbose = ""
cmake.build-type = "Release"
cmake.source-dir = "."
cmake.targets = ""
ninja.version = ">=1.5"
ninja.make-fallback = true
logging.level = "WARNING"
sdist.include = []
sdist.exclude = []
sdist.reproducible = true
sdist.cmake = false
wheel.packages = ["src/<package>", "python/<package>", "<package>"]
wheel.py-api = ""
wheel.expand-macos-universal-tags = false
wheel.install-dir = ""
wheel.license-files = ["LICEN[CS]E*", "COPYING*", "NOTICE*", "AUTHORS*"]
wheel.cmake = true
wheel.platlib = ""
wheel.exclude = []
wheel.build-tag = ""
backport.find-python = "3.26.1"
editable.mode = "redirect"
editable.verbose = true
editable.rebuild = false
build.tool-args = []
build.targets = []
build.verbose = false
install.components = []
install.strip = true
generate[].path = ""
generate[].template = ""
generate[].template-path = ""
generate[].location = "install"
messages.after-failure = ""
messages.after-success = ""
metadata = {}
strict-config = true
experimental = false
minimum-version = "0.10"
build-dir = ""
fail = false
Most CMake environment variables should be supported, and CMAKE_ARGS
can be
used to set extra CMake args. ARCHFLAGS
is used to specify macOS universal2 or
cross-compiles, just like setuptools.
You can also specify [[tool.scikit-build.overrides]]
to customize values for
different systems. See the docs for details.
Other projects for building
Scikit-build-core is a binary build backend. There are also other binary build
backends:
- py-build-cmake: A different attempt at a standards compliant builder for
CMake. Strong focus on cross-compilation. Uses Flit internals.
- cmeel: A different attempt at a standards compliant builder for CMake.
Focus on building an ecosystem around a special unimportable folder in
site-packages (similar to scikit-build's usage of
cmake.*
entrypoints, but
folder-based). - meson-python: A meson-based build backend; has some maintainer overlap
with scikit-build-core.
- maturin: A build backend for Rust projects, using Cargo.
- enscons: A SCons based backend, not very actively developed (but it
predates all the others in modern standard support!)
If you don't need a binary build, you don't need to use a binary build backend!
There are some very good Python build backends; we recommend hatchling as a
good balance between good defaults for beginners and good support for advanced
use cases. This is the tool scikit-build-core itself uses.
Acknowledgements
Support for this work was provided by NSF grant OAC-2209877. Any opinions,
findings, and conclusions or recommendations expressed in this material are
those of the author(s) and do not necessarily reflect the views of the National
Science Foundation.