Skip to content

Commit f41b36a

Browse files
authored
fix: build from sources with --no-binary=ninja (#276)
* fix: build from sources when forcing build from source * chore: remove unused config setting * chore: force reading CMake minimum version from CMakeLists.txt This disables the fallback to `>=3.15` if CMakeLists.txt can't be parsed properly.
1 parent bf388ce commit f41b36a

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

.github/workflows/build.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,11 @@ jobs:
128128
name: cibw-sdist
129129
path: sdist
130130

131+
- name: Ensure Ninja not present on the system
132+
run: if which ninja; then false; fi
133+
131134
- name: Install SDist
132-
run: pip install $(ls sdist/*.tar.gz)[test] -Ccmake.define.BUILD_CMAKE_FROM_SOURCE=OFF
135+
run: pip install --no-binary=ninja $(ls sdist/*.tar.gz)[test]
133136

134137
- name: Test installed SDist
135138
run: pip check && pytest ./tests

_build_backend/backend.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from __future__ import annotations
2+
3+
import os
4+
5+
from scikit_build_core import build as _orig
6+
7+
if hasattr(_orig, "prepare_metadata_for_build_editable"):
8+
prepare_metadata_for_build_editable = _orig.prepare_metadata_for_build_editable
9+
if hasattr(_orig, "prepare_metadata_for_build_wheel"):
10+
prepare_metadata_for_build_wheel = _orig.prepare_metadata_for_build_wheel
11+
build_editable = _orig.build_editable
12+
build_wheel = _orig.build_wheel
13+
build_sdist = _orig.build_sdist
14+
get_requires_for_build_editable = _orig.get_requires_for_build_editable
15+
get_requires_for_build_sdist = _orig.get_requires_for_build_sdist
16+
17+
def get_requires_for_build_wheel(config_settings=None):
18+
packages_orig = _orig.get_requires_for_build_wheel(config_settings)
19+
if os.environ.get("NINJA_PYTHON_DIST_ALLOW_NINJA_DEP", "0") != "0":
20+
return packages_orig
21+
packages = []
22+
for package in packages_orig:
23+
package_name = package.lower().split(">")[0].strip()
24+
if package_name == "ninja":
25+
# never request ninja from the ninja build
26+
continue
27+
packages.append(package)
28+
return packages

pyproject.toml

+13-5
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 = "ninja"
@@ -50,7 +51,9 @@ Homepage = "http://ninja-build.org/"
5051
"Source Code" = "https://github.com/scikit-build/ninja-python-distributions"
5152

5253
[tool.scikit-build]
53-
minimum-version = "0.9"
54+
minimum-version = "build-system.requires"
55+
cmake.version = "CMakeLists.txt" # Force parsing version from CMakeLists.txt and disable fallback to '>=3.15'
56+
ninja.make-fallback = true
5457
build-dir = "build/{wheel_tag}"
5558
wheel.py-api = "py3"
5659
wheel.expand-macos-universal-tags = true
@@ -88,6 +91,7 @@ build-verbosity = 1
8891
test-extras = "test"
8992
test-command = "pytest {project}/tests"
9093
test-skip = ["*-win_arm64", "*-macosx_universal2:arm64"]
94+
environment = { NINJA_PYTHON_DIST_ALLOW_NINJA_DEP = "1" }
9195
environment-pass = ["SETUPTOOLS_SCM_PRETEND_VERSION"]
9296
musllinux-x86_64-image = "musllinux_1_1"
9397
musllinux-i686-image = "musllinux_1_1"
@@ -96,20 +100,24 @@ musllinux-ppc64le-image = "musllinux_1_1"
96100
musllinux-s390x-image = "musllinux_1_1"
97101
musllinux-armv7l-image = "musllinux_1_2"
98102

99-
[tool.cibuildwheel.macos.environment]
100-
MACOSX_DEPLOYMENT_TARGET = "10.9"
103+
[[tool.cibuildwheel.overrides]]
104+
select = "*-macos*"
105+
inherit.environment = "append"
106+
environment = { MACOSX_DEPLOYMENT_TARGET = "10.9" }
101107

102108
[[tool.cibuildwheel.overrides]]
103109
select = "*-manylinux_{x86_64,i686}"
104110
manylinux-x86_64-image = "manylinux2010"
105111
manylinux-i686-image = "manylinux2010"
106112
build-frontend = "pip"
113+
inherit.environment = "append"
107114
environment = { LDFLAGS = "-static-libstdc++" }
108115
inherit.test-command = "prepend"
109116
test-command = "pip check"
110117

111118
[[tool.cibuildwheel.overrides]]
112119
select = "*-musllinux_*"
120+
inherit.environment = "append"
113121
environment = { LDFLAGS = "-static-libstdc++ -static-libgcc" }
114122

115123
[[tool.cibuildwheel.overrides]]

0 commit comments

Comments
 (0)