Skip to content

feat: use a submodule for ninja sources #278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # required for versioneer to find tags
fetch-depth: 0 # required for setuptools_scm to find tags
submodules: 'recursive'

- name: Set up QEMU
uses: docker/[email protected]
Expand Down Expand Up @@ -97,7 +98,8 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # required for versioneer to find tags
fetch-depth: 0 # required for setuptools_scm to find tags
submodules: 'recursive'

- name: Build SDist
run: pipx run build --sdist
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "ninja-upstream"]
path = ninja-upstream
url = https://github.com/Kitware/ninja.git
54 changes: 13 additions & 41 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,28 @@ project(NinjaPythonDistributions)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_MODULE_PATH})

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

include(NinjaUrls)

function(check_archive_var archive_var)
if(NOT DEFINED "${archive_var}_url")
message(FATAL_ERROR "Failed to determine which archive to download: '${archive_var}_url' variable is not defined")
endif()
if(NOT DEFINED "${archive_var}_sha256")
message(FATAL_ERROR "Could you make sure variable '${archive_var}_sha256' is defined ?")
endif()
endfunction()

set(src_archive "unix_source")
if(WIN32)
set(src_archive "windows_source")
endif()
check_archive_var("${src_archive}")

message(STATUS "*********************************************")
message(STATUS "************************************")
message(STATUS "Ninja Python Distribution")
message(STATUS "")
message(STATUS " BUILD_VERBOSE : ${BUILD_VERBOSE}")
message(STATUS " RUN_NINJA_TEST : ${RUN_NINJA_TEST}")
message(STATUS "")
message(STATUS " ARCHIVE_DOWNLOAD_DIR : ${ARCHIVE_DOWNLOAD_DIR}")
message(STATUS "")
message(STATUS " src_archive : ${src_archive}")
message(STATUS " <src_archive>_url : ${${src_archive}_url}")
message(STATUS " <src_archive>_sha256 : ${${src_archive}_sha256}")
message(STATUS "*********************************************")

set(ep_download_no_progress_args)
if(NOT BUILD_VERBOSE)
set(ep_download_no_progress_args
DOWNLOAD_NO_PROGRESS 1
)
endif()
message(STATUS " RUN_NINJA_TEST : ${RUN_NINJA_TEST}")
message(STATUS "************************************")

include(FetchContent)
FetchContent_Declare(
ninja
URL ${${src_archive}_url}
URL_HASH SHA256=${${src_archive}_sha256}
DOWNLOAD_DIR ${ARCHIVE_DOWNLOAD_DIR}
${ep_download_no_progress_args}
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ninja-upstream
)
FetchContent_MakeAvailable(ninja)

if(RUN_NINJA_TEST)
add_custom_target(
run_ninja_test ALL "$<TARGET_FILE:ninja_test>"
DEPENDS ninja_test
WORKING_DIRECTORY "$<TARGET_FILE_DIR:ninja_test>"
)
endif()

install(TARGETS ninja COMPONENT python DESTINATION "${SKBUILD_SCRIPTS_DIR}")
install(FILES "${ninja_SOURCE_DIR}/misc/ninja_syntax.py" COMPONENT python DESTINATION ninja)
8 changes: 0 additions & 8 deletions NinjaUrls.cmake

This file was deleted.

2 changes: 0 additions & 2 deletions constraints.txt

This file was deleted.

1 change: 1 addition & 0 deletions ninja-upstream
Submodule ninja-upstream added at 95dee2
5 changes: 1 addition & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,13 @@ def bump(session: nox.Session) -> None:
else:
version = args.version

deps = nox.project.load_toml("scripts/update_ninja_version.py")["dependencies"]
session.install(*deps)

extra = ["--quiet"] if args.commit else []
session.run("python", "scripts/update_ninja_version.py", "--upstream-repository", args.upstream_repository, version, *extra)

if args.commit:
session.run("git", "switch", "-c", f"update-to-ninja-{version}", external=True)
files = (
"NinjaUrls.cmake",
"ninja-upstream",
"README.rst",
"tests/test_ninja.py",
"docs/update_ninja_version.rst",
Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ wheel.expand-macos-universal-tags = true
metadata.version.provider = "scikit_build_core.metadata.setuptools_scm"
metadata.readme.provider = "scikit_build_core.metadata.fancy_pypi_readme"
install.components = ["python"]
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"]


[[tool.scikit-build.generate]]
Expand Down Expand Up @@ -98,6 +99,13 @@ musllinux-ppc64le-image = "musllinux_1_1"
musllinux-s390x-image = "musllinux_1_1"
musllinux-armv7l-image = "musllinux_1_2"

[tool.cibuildwheel.config-settings]
"cmake.define.RUN_NINJA_TEST" = "ON"

[[tool.cibuildwheel.overrides]]
select = ["*-win_arm64",]
config-settings."cmake.define.RUN_NINJA_TEST" = "OFF"

[[tool.cibuildwheel.overrides]]
select = "*-macos*"
inherit.environment = "append"
Expand Down
Loading
Loading