{"id":1704,"library":"scikit-build-core","title":"scikit-build-core - CMake Build Backend","description":"scikit-build-core is a modern, PEP 517/660 compliant build backend for Python projects that use CMake to build native extensions. It streamlines the integration of C, C++, or Fortran code with Python packaging, handling everything from project configuration to wheel and sdist generation. The current version is 0.12.2, with a fairly active release cadence, typically releasing minor bugfix or feature updates every few weeks.","status":"active","version":"0.12.2","language":"en","source_language":"en","source_url":"https://github.com/scikit-build/scikit-build-core","tags":["build system","cmake","packaging","backend","native extensions","pyproject.toml"],"install":[{"cmd":"pip install scikit-build-core","lang":"bash","label":"Install scikit-build-core"}],"dependencies":[],"imports":[],"quickstart":{"code":"mkdir my_cmake_project\ncd my_cmake_project\n\n# pyproject.toml\ncat <<EOF > pyproject.toml\n[build-system]\nrequires = [\"scikit-build-core>=0.12.0\", \"cmake>=3.15\"]\nbuild-backend = \"scikit_build_core.build\"\n\n[project]\nname = \"my_package\"\nversion = \"0.1.0\"\nauthors = [\n  { name=\"Your Name\", email=\"you@example.com\" },\n]\ndescription = \"A minimal example with scikit-build-core\"\nreadme = \"README.md\"\nrequires-python = \">=3.8\"\nclassifiers = [\n    \"Programming Language :: Python :: 3\",\n    \"License :: OSI Approved :: MIT License\",\n    \"Operating System :: OS Independent\",\n]\n\n[tool.scikit-build]\ncmake.minimum-version = \"3.15\"\nEOF\n\n# CMakeLists.txt\ncat <<EOF > CMakeLists.txt\ncmake_minimum_required(VERSION 3.15...3.27)\nproject(my_package LANGUAGES CXX)\nadd_library(mylib SHARED mylib.cpp)\n\ninstall(TARGETS mylib DESTINATION .)\nEOF\n\n# mylib.cpp\nmkdir -p src\ncat <<EOF > src/mylib.cpp\n#include <iostream>\n\nextern \"C\" void greet() {\n    std::cout << \"Hello from C++!\" << std::endl;\n}\nEOF\n\n# my_package/__init__.py\nmkdir -p my_package\ncat <<EOF > my_package/__init__.py\nimport os\nimport sys\nfrom pathlib import Path\n\n# Find the built native library (e.g., _mylib.so, _mylib.pyd)\n# This is a common pattern, but scikit-build-core can also inject helpers.\n# For a proper package, you'd typically use `from . import _mylib`\n# assuming the native library is packaged correctly.\n\ndef _load_native_library():\n    # This simple example assumes the library is in the package root after install\n    # In a real scenario, use proper packaging tools or scikit-build-core's\n    # built-in module finder to locate and load.\n    # For demonstration, we'll simulate direct loading.\n    try:\n        # On Linux/macOS, it's typically 'libmylib.so' or 'libmylib.dylib'\n        # On Windows, it's 'mylib.dll' or '_mylib.pyd'\n        if sys.platform == 'win32':\n            _mylib = Path(__file__).parent / 'mylib.dll' # Or '_mylib.pyd'\n        elif sys.platform == 'darwin':\n            _mylib = Path(__file__).parent / 'libmylib.dylib'\n        else:\n            _mylib = Path(__file__).parent / 'libmylib.so'\n\n        # This simple example doesn't actually load the C++ library\n        # for direct python binding calls, as that requires pybind11/nanobind.\n        # The greet() function below will just print a Python message.\n        print(f\"[my_package] Simulating loading native library: {_mylib.name}\")\n    except Exception as e:\n        print(f\"[my_package] Could not load native library: {e}\")\n\n_load_native_library()\n\ndef greet():\n    print(\"Hello from Python via my_package!\")\n\nEOF\n\npip install build\npython -m build\npip install dist/*.whl --force-reinstall\n\npython -c \"from my_package import greet; greet()\"\n","lang":"bash","description":"To use scikit-build-core, you primarily configure your project via `pyproject.toml`. This minimal example demonstrates how to set up `pyproject.toml` to declare `scikit-build-core` as the build backend, alongside a basic `CMakeLists.txt` and a dummy C++ source file. The Python `__init__.py` shows where the native library would typically be loaded. After running `python -m build`, `scikit-build-core` invokes CMake to build your native extension and then packages it into a wheel. You'll need CMake and a C++ compiler installed on your system to run this."},"warnings":[{"fix":"Upgrade your project's Python version to 3.8 or newer, or pin `scikit-build-core` to a version prior to 0.11.0.","message":"Python 3.7 support has been removed since version 0.11.0. Projects requiring Python 3.7 must pin `scikit-build-core<0.11.0`.","severity":"breaking","affected_versions":">=0.11.0"},{"fix":"Review your sdist content after upgrading. If you rely on files in ignored directories being included, you might need to adjust your `sdist.include` configuration or explicitly set `sdist.inclusion-mode = \"classic\"` in `pyproject.toml`.","message":"The default `sdist.inclusion-mode` changed in 0.12.0 from 'classic' to a new mode that no longer traverses ignored directories unless files are explicitly allowed. This can affect which files are included in your source distributions (sdist).","severity":"gotcha","affected_versions":">=0.12.0"},{"fix":"Ensure your `pyproject.toml` has `[tool.scikit-build]` and `minimum-version` is set to `0.12` or higher to explicitly opt into modern behavior and avoid potential future PyPI upload rejections.","message":"PyPI no longer accepts non-normalized SDist names. `scikit-build-core` versions >=0.12.2 now always normalize SDist names, even if `minimum-version` is set to 0.4 or older. Projects with older `minimum-version` settings should still update their `minimum-version` to explicitly support this change and avoid future issues.","severity":"breaking","affected_versions":">=0.12.2 (SDist generation), <0.12.2 (PyPI upload)"},{"fix":"Avoid using Python 3.13.4 on Windows for building projects with `scikit-build-core`. Use a different Python 3.13.x version or an earlier/later stable release.","message":"Python 3.13.4 on Windows is known to have issues with certain build processes. `scikit-build-core` versions >=0.11.5 will warn about this specific Python version.","severity":"gotcha","affected_versions":"Python 3.13.4 on Windows (specific runtime)"},{"fix":"Install CMake and a suitable C/C++ compiler (e.g., GCC, Clang, MSVC) on your system. For `build-system.requires` in `pyproject.toml`, it's recommended to include `cmake>=X.Y` (where X.Y is your minimum required CMake version) to ensure the build environment explicitly checks for CMake.","message":"`scikit-build-core` requires CMake and a compatible C/C++ compiler toolchain to be installed and available in the system's PATH. This is not managed by pip.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}