{"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.","language":"python","status":"active","last_verified":"Thu Apr 09","install":{"commands":["pip install scikit-build-core"],"cli":{"name":"scikit-build-core","version":"sh: 1: scikit-build-core: not found"}},"imports":[],"auth":{"required":false,"env_vars":[]},"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.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]},"compatibility":null}