Skip to content

Commit 8009f0b

Browse files
committed
fix: do not require Ninja
This should prevent bootstrapping issues between CMake PyPI distribution and Ninja PyPI distribution when building either one from sources.
1 parent 66eddd4 commit 8009f0b

File tree

2 files changed

+58
-7
lines changed

2 files changed

+58
-7
lines changed

_build_backend/backend.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os
2+
3+
from scikit_build_core import build as _orig
4+
5+
if hasattr(_orig, "prepare_metadata_for_build_editable"):
6+
prepare_metadata_for_build_editable = _orig.prepare_metadata_for_build_editable
7+
if hasattr(_orig, "prepare_metadata_for_build_wheel"):
8+
prepare_metadata_for_build_wheel = _orig.prepare_metadata_for_build_wheel
9+
build_editable = _orig.build_editable
10+
build_wheel = _orig.build_wheel
11+
build_sdist = _orig.build_sdist
12+
get_requires_for_build_editable = _orig.get_requires_for_build_editable
13+
get_requires_for_build_sdist = _orig.get_requires_for_build_sdist
14+
15+
16+
def strtobool(value: str) -> bool:
17+
"""
18+
Converts a environment variable string into a boolean value.
19+
"""
20+
if not value:
21+
return False
22+
value = value.lower()
23+
if value.isdigit():
24+
return bool(int(value))
25+
return value not in {"n", "no", "off", "false", "f"}
26+
27+
28+
def get_requires_for_build_wheel(config_settings=None):
29+
packages_orig = _orig.get_requires_for_build_wheel(config_settings)
30+
allow_ninja = any(
31+
strtobool(os.environ.get(var, ""))
32+
for var in ("CMAKE_PYTHON_DIST_FORCE_NINJA_DEP", "CMAKE_PYTHON_DIST_ALLOW_NINJA_DEP")
33+
)
34+
packages = []
35+
for package in packages_orig:
36+
package_name = package.lower().split(">")[0].strip()
37+
if package_name == "cmake":
38+
msg = f"CMake PyPI distibution requires {package} to be available on the build system"
39+
raise ValueError(msg)
40+
if package_name == "ninja" and not allow_ninja:
41+
continue
42+
packages.append(package)
43+
return packages

pyproject.toml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[build-system]
2-
requires = ["scikit-build-core"]
3-
build-backend = "scikit_build_core.build"
2+
requires = ["scikit-build-core>=0.10"]
3+
build-backend = "backend"
4+
backend-path = ["_build_backend"]
45

56
[project]
67
name = "cmake"
@@ -51,10 +52,10 @@ cpack = "cmake:cpack"
5152
ctest = "cmake:ctest"
5253

5354
[tool.scikit-build]
54-
minimum-version = "0.8"
55+
minimum-version = "build-system.requires"
5556
build-dir = "build/{wheel_tag}"
56-
cmake.version = "" # We are cmake, so don't request cmake
57-
ninja.make-fallback = false
57+
cmake.version = ">=3.13" # Since 3.24.0, CMake requires CMake 3.13+ to build itself
58+
ninja.make-fallback = true
5859
wheel.py-api = "py3"
5960
wheel.expand-macos-universal-tags = true
6061
wheel.install-dir = "cmake/data"
@@ -65,22 +66,29 @@ template = '''
6566
version = "${version}"
6667
'''
6768

69+
[[tool.scikit-build.overrides]]
70+
if.env.CMAKE_PYTHON_DIST_FORCE_NINJA_DEP = true
71+
ninja.make-fallback = false
72+
6873

6974
[tool.cibuildwheel]
7075
build = "cp39-*"
7176
test-extras = "test"
7277
test-command = "pytest {project}/tests"
7378
build-verbosity = 1
7479
build-frontend = "build[uv]"
80+
environment = { CMAKE_PYTHON_DIST_FORCE_NINJA_DEP = "1" }
7581
musllinux-x86_64-image = "musllinux_1_1"
7682
musllinux-i686-image = "musllinux_1_1"
7783
musllinux-aarch64-image = "musllinux_1_1"
7884
musllinux-ppc64le-image = "musllinux_1_1"
7985
musllinux-s390x-image = "musllinux_1_1"
8086
musllinux-armv7l-image = "musllinux_1_2"
8187

82-
[tool.cibuildwheel.macos.environment]
83-
MACOSX_DEPLOYMENT_TARGET = "10.10"
88+
[[tool.cibuildwheel.overrides]]
89+
select = "*-macos*"
90+
inherit.environment = "append"
91+
environment = { MACOSX_DEPLOYMENT_TARGET = "10.10" }
8492

8593
[tool.cibuildwheel.linux]
8694
before-all = "./scripts/manylinux-build-and-install-openssl.sh"

0 commit comments

Comments
 (0)