Skip to content

Commit 7a70669

Browse files
authored
feat: use a submodule for ninja sources (#278)
* feat: use a submodule for ninja sources * fix: respect RUN_NINJA_TEST option * fix: exclude unneeded files from SDist SDist goes from ~350kB to ~200kB
1 parent 0bf0047 commit 7a70669

9 files changed

+80
-198
lines changed

.github/workflows/build.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ jobs:
6464
steps:
6565
- uses: actions/checkout@v4
6666
with:
67-
fetch-depth: 0 # required for versioneer to find tags
67+
fetch-depth: 0 # required for setuptools_scm to find tags
68+
submodules: 'recursive'
6869

6970
- name: Set up QEMU
7071
uses: docker/[email protected]
@@ -97,7 +98,8 @@ jobs:
9798
steps:
9899
- uses: actions/checkout@v4
99100
with:
100-
fetch-depth: 0 # required for versioneer to find tags
101+
fetch-depth: 0 # required for setuptools_scm to find tags
102+
submodules: 'recursive'
101103

102104
- name: Build SDist
103105
run: pipx run build --sdist

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "ninja-upstream"]
2+
path = ninja-upstream
3+
url = https://github.com/Kitware/ninja.git

CMakeLists.txt

+13-41
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,28 @@ project(NinjaPythonDistributions)
55
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_MODULE_PATH})
66

77
# Options
8-
option(BUILD_VERBOSE "Display additional information while building (e.g download progress, ...)" OFF)
9-
option(RUN_NINJA_TEST "Run Ninja test suite" ON)
10-
set(ARCHIVE_DOWNLOAD_DIR "${CMAKE_BINARY_DIR}" CACHE PATH "Directory where to download archives")
8+
option(RUN_NINJA_TEST "Run Ninja test suite" OFF)
119

12-
include(NinjaUrls)
13-
14-
function(check_archive_var archive_var)
15-
if(NOT DEFINED "${archive_var}_url")
16-
message(FATAL_ERROR "Failed to determine which archive to download: '${archive_var}_url' variable is not defined")
17-
endif()
18-
if(NOT DEFINED "${archive_var}_sha256")
19-
message(FATAL_ERROR "Could you make sure variable '${archive_var}_sha256' is defined ?")
20-
endif()
21-
endfunction()
22-
23-
set(src_archive "unix_source")
24-
if(WIN32)
25-
set(src_archive "windows_source")
26-
endif()
27-
check_archive_var("${src_archive}")
28-
29-
message(STATUS "*********************************************")
10+
message(STATUS "************************************")
3011
message(STATUS "Ninja Python Distribution")
3112
message(STATUS "")
32-
message(STATUS " BUILD_VERBOSE : ${BUILD_VERBOSE}")
33-
message(STATUS " RUN_NINJA_TEST : ${RUN_NINJA_TEST}")
34-
message(STATUS "")
35-
message(STATUS " ARCHIVE_DOWNLOAD_DIR : ${ARCHIVE_DOWNLOAD_DIR}")
36-
message(STATUS "")
37-
message(STATUS " src_archive : ${src_archive}")
38-
message(STATUS " <src_archive>_url : ${${src_archive}_url}")
39-
message(STATUS " <src_archive>_sha256 : ${${src_archive}_sha256}")
40-
message(STATUS "*********************************************")
41-
42-
set(ep_download_no_progress_args)
43-
if(NOT BUILD_VERBOSE)
44-
set(ep_download_no_progress_args
45-
DOWNLOAD_NO_PROGRESS 1
46-
)
47-
endif()
13+
message(STATUS " RUN_NINJA_TEST : ${RUN_NINJA_TEST}")
14+
message(STATUS "************************************")
4815

4916
include(FetchContent)
5017
FetchContent_Declare(
5118
ninja
52-
URL ${${src_archive}_url}
53-
URL_HASH SHA256=${${src_archive}_sha256}
54-
DOWNLOAD_DIR ${ARCHIVE_DOWNLOAD_DIR}
55-
${ep_download_no_progress_args}
19+
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ninja-upstream
5620
)
5721
FetchContent_MakeAvailable(ninja)
5822

23+
if(RUN_NINJA_TEST)
24+
add_custom_target(
25+
run_ninja_test ALL "$<TARGET_FILE:ninja_test>"
26+
DEPENDS ninja_test
27+
WORKING_DIRECTORY "$<TARGET_FILE_DIR:ninja_test>"
28+
)
29+
endif()
30+
5931
install(TARGETS ninja COMPONENT python DESTINATION "${SKBUILD_SCRIPTS_DIR}")
6032
install(FILES "${ninja_SOURCE_DIR}/misc/ninja_syntax.py" COMPONENT python DESTINATION ninja)

NinjaUrls.cmake

-8
This file was deleted.

constraints.txt

-2
This file was deleted.

ninja-upstream

Submodule ninja-upstream added at 95dee2a

noxfile.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,13 @@ def bump(session: nox.Session) -> None:
9393
else:
9494
version = args.version
9595

96-
deps = nox.project.load_toml("scripts/update_ninja_version.py")["dependencies"]
97-
session.install(*deps)
98-
9996
extra = ["--quiet"] if args.commit else []
10097
session.run("python", "scripts/update_ninja_version.py", "--upstream-repository", args.upstream_repository, version, *extra)
10198

10299
if args.commit:
103100
session.run("git", "switch", "-c", f"update-to-ninja-{version}", external=True)
104101
files = (
105-
"NinjaUrls.cmake",
102+
"ninja-upstream",
106103
"README.rst",
107104
"tests/test_ninja.py",
108105
"docs/update_ninja_version.rst",

pyproject.toml

+8
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ wheel.expand-macos-universal-tags = true
5858
metadata.version.provider = "scikit_build_core.metadata.setuptools_scm"
5959
metadata.readme.provider = "scikit_build_core.metadata.fancy_pypi_readme"
6060
install.components = ["python"]
61+
sdist.exclude = ["**/.github", "/noxfile.py", "/ninja-python-distributions-logo.png", "/docs", "/scripts", "/ninja-upstream/doc", "!/ninja-upstream/misc", "/ninja-upstream/misc/**", "!/ninja-upstream/misc/ninja_syntax.py"]
6162

6263

6364
[[tool.scikit-build.generate]]
@@ -98,6 +99,13 @@ musllinux-ppc64le-image = "musllinux_1_1"
9899
musllinux-s390x-image = "musllinux_1_1"
99100
musllinux-armv7l-image = "musllinux_1_2"
100101

102+
[tool.cibuildwheel.config-settings]
103+
"cmake.define.RUN_NINJA_TEST" = "ON"
104+
105+
[[tool.cibuildwheel.overrides]]
106+
select = ["*-win_arm64",]
107+
config-settings."cmake.define.RUN_NINJA_TEST" = "OFF"
108+
101109
[[tool.cibuildwheel.overrides]]
102110
select = "*-macos*"
103111
inherit.environment = "append"

0 commit comments

Comments
 (0)