Skip to content

Commit

Permalink
Merge pull request #95 from ssciwr/use_scikit_build_core
Browse files Browse the repository at this point in the history
Use scikit-build-core instead of scikit-build
  • Loading branch information
dokempf authored Mar 21, 2024
2 parents a483c18 + b5c6200 commit afba506
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 122 deletions.
32 changes: 19 additions & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,25 @@ jobs:
skip: ["*manylinux*", "*musllinux*"]
include:
# initially generate all 10 matrix combinations with qemu on ubuntu:
- os: ubuntu-20.04
- os: ubuntu-latest
use_qemu: true
# modify the x86_64 and i686 jobs generated above to disable qemu
- os: ubuntu-20.04
- os: ubuntu-latest
arch: "x86_64"
use_qemu: false
- os: ubuntu-20.04
- os: ubuntu-latest
arch: "i686"
use_qemu: false
# additional runs (they define skip="" to ensure they cannot be combined with any matrix combinations)
- os: windows-2019
- os: windows-latest
arch: "AMD64"
use_qemu: false
skip: ""
- os: windows-2019
- os: windows-latest
arch: "x86"
use_qemu: false
skip: ""
- os: macos-11
- os: macos-latest
arch: "x86_64"
use_qemu: false
skip: ""
Expand All @@ -70,11 +70,17 @@ jobs:
if: runner.os == 'Windows' && ((!matrix.use_qemu) || fromJSON(env.USE_QEMU))
run: git config --system core.longpaths true

- name: Set up msvc on Windows
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{ matrix.arch }}

- name: Override LLVM version (${{ github.event.inputs.llvm_version }})
if: github.event.inputs.llvm_version
run: |
echo "set(CLANG_FORMAT_VERSION ${{ github.event.inputs.llvm_version }})" > clang-format_version.cmake
echo "set(CLANG_FORMAT_WHEEL_VERSION ${{ github.event.inputs.wheel_version }})" >> clang-format_version.cmake
echo "${{ github.event.inputs.llvm_version }}.${{ github.event.inputs.wheel_version }}" > clang-format_version.txt
cat clang-format_version.txt
- name: Set up QEMU
uses: docker/[email protected]
Expand All @@ -95,16 +101,16 @@ jobs:

build-sdist:
name: Build source distribution
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Override LLVM version (${{ github.event.inputs.llvm_version }})
if: github.event.inputs.llvm_version
run: |
echo "set(CLANG_FORMAT_VERSION ${{ github.event.inputs.llvm_version }})" > clang-format_version.cmake
echo "set(CLANG_FORMAT_WHEEL_VERSION ${{ github.event.inputs.wheel_version }})" >> clang-format_version.cmake
echo "${{ github.event.inputs.llvm_version }}.${{ github.event.inputs.wheel_version }}" > clang-format_version.txt
cat clang-format_version.txt
- name: Build SDist
run: pipx run build --sdist
Expand All @@ -117,7 +123,7 @@ jobs:
test-sdist:
name: Test build from source distribution
needs: [build-sdist]
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -152,7 +158,7 @@ jobs:
upload_pypi:
name: Upload to PyPI
needs: [build-wheels, build-sdist, test-sdist]
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
permissions:
id-token: write
if: github.repository_owner == 'ssciwr'
Expand Down
34 changes: 24 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
project(clang-format-wheel)
cmake_minimum_required(VERSION 3.16)
cmake_minimum_required(VERSION 3.16...3.28)
project(${SKBUILD_PROJECT_NAME} VERSION ${SKBUILD_PROJECT_VERSION})

# Include the "single source of truth" for the clang-format version
include(clang-format_version.cmake)
string(REPLACE "-" "" CLANG_FORMAT_VERSION_SHORT "${CLANG_FORMAT_VERSION}")
message(STATUS "clang-format-wheel version: ${SKBUILD_PROJECT_VERSION}")
string(REGEX MATCH "^([0-9]+)\.([0-9]+)\.([0-9]+)" CLANG_FORMAT_VERSION "${SKBUILD_PROJECT_VERSION}")
message(STATUS "clang-format version: ${CLANG_FORMAT_VERSION}")

# Define a build rule clang-format
set(LLVM_DOWNLOAD_URL "https://github.com/llvm/llvm-project/releases/download/llvmorg-${CLANG_FORMAT_VERSION}/llvm-project-${CLANG_FORMAT_VERSION_SHORT}.src.tar.xz")
set(LLVM_DOWNLOAD_URL "https://github.com/llvm/llvm-project/releases/download/llvmorg-${CLANG_FORMAT_VERSION}/llvm-project-${CLANG_FORMAT_VERSION}.src.tar.xz")
include(ExternalProject)
ExternalProject_add(build-clang-format
URL "${LLVM_DOWNLOAD_URL}"
Expand All @@ -18,10 +18,14 @@ ExternalProject_add(build-clang-format
USES_TERMINAL_DOWNLOAD 1
USES_TERMINAL_CONFIGURE 1
USES_TERMINAL_BUILD 1
CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DLLVM_ENABLE_ZLIB=OFF -DLLVM_ENABLE_ZSTD=OFF -DLLVM_ENABLE_PROJECTS=clang
BUILD_COMMAND ${CMAKE_COMMAND} --build . --target clang-format
CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DLLVM_ENABLE_ZLIB=OFF -DLLVM_ENABLE_ZSTD=OFF -DLLVM_ENABLE_PROJECTS=clang -DLLVM_TARGETS_TO_BUILD=
BUILD_COMMAND ${CMAKE_COMMAND} --build . --target clang-format --config Release
)
set(clang-format-executable ${CMAKE_BINARY_DIR}/llvm/bin/clang-format${CMAKE_EXECUTABLE_SUFFIX})
set(config-subfolder "")
if(CMAKE_GENERATOR MATCHES "Visual Studio")
set(config-subfolder "Release")
endif()
set(clang-format-executable ${CMAKE_BINARY_DIR}/llvm/${config-subfolder}/bin/clang-format${CMAKE_EXECUTABLE_SUFFIX})

# Reduce the size of the executable by executing strip if it is present on the system
find_program(STRIP_EXECUTABLE strip)
Expand All @@ -39,7 +43,17 @@ endif()
install(
PROGRAMS
${clang-format-executable}
DESTINATION clang_format/data/bin
)
install(
PROGRAMS
${CMAKE_BINARY_DIR}/llvm-project/clang/tools/clang-format/clang-format-diff.py
RENAME clang_format_diff.py
DESTINATION clang_format
)
install(
PROGRAMS
${CMAKE_BINARY_DIR}/llvm-project/clang/tools/clang-format/git-clang-format
DESTINATION clang_format/data/bin
RENAME git_clang_format.py
DESTINATION clang_format
)
6 changes: 0 additions & 6 deletions MANIFEST.in

This file was deleted.

5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ The [clang-format-wheel repository](https://github.com/ssciwr/clang-format-wheel

In order to add a new release, the following steps are necessary:

* Edit the [version file](https://github.com/ssciwr/clang-format-wheel/blob/main/clang-format_version.cmake) to reflect the new version.
* Edit the [version file](https://github.com/ssciwr/clang-format-wheel/blob/main/clang-format_version.txt)
* In the form `llvm_version.wheel_version`, e.g. `18.0.2.1`
* Make a GitHub release to trigger the [GitHub Actions release workflow](https://github.com/ssciwr/clang-format-wheel/actions/workflows/release.yml). Alternatively, the workflow can be triggered manually.

On manual triggers, the following input variables are available:
Expand All @@ -54,7 +55,7 @@ The repository with the precommit hook is automatically updated using a schedule
This repository extends the great work of several other projects:

* `clang-format` itself is [provided by the LLVM project](https://github.com/llvm/llvm-project) under the Apache 2.0 License with LLVM exceptions.
* The build logic is based on [scikit-build](https://github.com/scikit-build/scikit-build) which greatly reduces the amount of low level code necessary to package `clang-format`.
* The build logic is based on [scikit-build-core](https://github.com/scikit-build/scikit-build-core) which greatly reduces the amount of low level code necessary to package `clang-format`.
* The `scikit-build` packaging examples of [CMake](https://github.com/scikit-build/cmake-python-distributions) and [Ninja](https://github.com/scikit-build/ninja-python-distributions) were very helpful in packaging `clang-format`.
* The CI build process is controlled by [cibuildwheel](https://github.com/pypa/cibuildwheel) which makes building wheels across a number of platforms a pleasant experience (!)

Expand Down
2 changes: 0 additions & 2 deletions clang-format_version.cmake

This file was deleted.

1 change: 1 addition & 0 deletions clang-format_version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18.1.1.0
15 changes: 0 additions & 15 deletions clang_format/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,5 @@ def _run(name):
executable = _get_executable(name)
return subprocess.call([executable] + sys.argv[1:])

def _run_python(name):
script = _get_executable(name)
# as MS Windows is not able to run Python scripts directly by name,
# we have to call the interpreter and pass the script as parameter
return subprocess.call([sys.executable, script] + sys.argv[1:])


def clang_format():
raise SystemExit(_run("clang-format"))


def clang_format_diff():
raise SystemExit(_run_python("clang-format-diff.py"))


def git_clang_format():
raise SystemExit(_run_python("git-clang-format"))
49 changes: 45 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,54 @@
[build-system]
requires = ["setuptools>=42", "wheel", "scikit-build", "cmake>=3.16", "ninja; platform_system!='Windows'"]
requires = ["scikit-build-core"]
build-backend = "scikit_build_core.build"

[project]
name = "clang-format"
dynamic = ["version"]
authors = [{name = "Dominic Kempf", email = "[email protected]"}]
license = { text = "Apache 2.0" }
description = "Clang-Format is an LLVM-based code formatting tool"
readme = "README.md"
classifiers = [
"Programming Language :: C",
"Programming Language :: C++",
"Operating System :: OS Independent",
"License :: OSI Approved :: Apache Software License",
"Intended Audience :: Developers",
"Topic :: Software Development :: Quality Assurance",
]

[tool.scikit-build.metadata.version]
provider = "scikit_build_core.metadata.regex"
regex = '^(?P<value>\d+\.\d+\.\d+(\.[1-9]\d*)?)'
input = "clang-format_version.txt"

[project.urls]
Clang = "http://clang.llvm.org/"
Documentation = "https://clang.llvm.org/docs/ClangFormat.html"
Download = "https://github.com/llvm/llvm-project/releases"
Source = "https://github.com/ssciwr/clang-format-wheel"

[project.scripts]
"clang-format" = "clang_format:clang_format"
"git-clang-format" = "clang_format.git_clang_format:main"
"clang-format-diff.py" = "clang_format.clang_format_diff:main"

[tool.scikit-build]
wheel.packages = ["clang_format"]
wheel.py-api = "py2.py3"
cmake.version = ">=3.16.0"
ninja.version = ">=1.10.0"
cmake.verbose = true
logging.level = "DEBUG"

[tool.cibuildwheel]
# Super-verbose output for debugging purpose
build-verbosity = 3
# Set CMAKE_GENERATOR env var which is respected by scikit-build-core to use Ninja on all platforms
environment = "CMAKE_GENERATOR=Ninja"

# We restrict ourselves to CPython 3.9 and then repair the wheels to be
# independent of the Python version - I have not found a different solution
# within cibuildwheel to achieve this.
# restrict to a single Python version as wheel does not depend on Python
build = "cp39-*"

# Testing commands for our wheels
Expand Down
70 changes: 0 additions & 70 deletions setup.py

This file was deleted.

0 comments on commit afba506

Please sign in to comment.