Skip to content

Commit 8b59233

Browse files
committed
Update clang wheel packaging and add CI workflows
1 parent 8fbc6a8 commit 8b59233

File tree

11 files changed

+190
-177
lines changed

11 files changed

+190
-177
lines changed

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
8+
- package-ecosystem: "pip"
9+
directory: "/"
10+
schedule:
11+
interval: "weekly"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Auto-update LLVM Version
2+
on:
3+
workflow_dispatch:
4+
schedule:
5+
- cron: '0 10 * * 1'
6+
jobs:
7+
update-dep:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
- name: Check and update LLVM version
12+
id: check-llvm
13+
run: |
14+
old_version="$(grep -Po '(?<=LLVM_VERSION )\d+(\.\d+)+' llvm_version.cmake)"
15+
echo "Old version: $old_version"
16+
echo "old_version=$old_version" >> $GITHUB_OUTPUT
17+
18+
new_version=$(git -c 'versionsort.suffix=-' \
19+
ls-remote --exit-code --refs --sort='version:refname' --tags https://github.com/llvm/llvm-project 'llvmorg-*.*.*'\
20+
| grep -Po '\d+\.\d+(\.\d+)?$' \
21+
| tail --lines=1)
22+
23+
echo "New version: $new_version"
24+
echo "new_version=$new_version" >> $GITHUB_OUTPUT
25+
26+
if [ "$old_version" != "$new_version" ]; then
27+
echo "set(LLVM_VERSION $new_version)" > llvm_version.cmake
28+
curl -L https://github.com/llvm/llvm-project/releases/download/llvmorg-${new_version}/clang-${new_version}.src.tar.xz -o clang-${new_version}.src.tar.xz
29+
hash=$(sha256sum clang-${new_version}.src.tar.xz | cut -d ' ' -f1)
30+
echo "set(LLVM_SHA256 $hash)" >> llvm_version.cmake
31+
echo "LLVM version updated"
32+
else
33+
echo "No change in LLVM version"
34+
fi
35+
36+
- name: Create Pull Request
37+
uses: peter-evans/create-pull-request@v7
38+
with:
39+
token: ${{ secrets.GITHUB_TOKEN }}
40+
commit-message: Update LLVM to version ${{ steps.check-llvm.outputs.new_version }}
41+
title: Update LLVM version (${{ steps.check-llvm.outputs.new_version }})
42+
body: |
43+
- Update LLVM version to ${{ steps.check-llvm.outputs.new_version }}
44+
Auto-generated by ${{ github.server_url }}/${{ github.repository }}/runs/${{ github.job }}?check_suite_focus=true
45+
author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
46+
branch: llvm-version-update/${{ steps.check-llvm.outputs.new_version }}

.github/workflows/release.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Build and Release on PyPI
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
tags:
7+
- v*
8+
9+
jobs:
10+
build-release:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
- uses: actions/setup-python@v5
17+
with:
18+
python-version: '3.13'
19+
- name: Build wheel
20+
run: |
21+
pip install build twine
22+
python -m build
23+
python -m twine check dist/*
24+
- name: Upload Python package dist artifacts
25+
uses: actions/upload-artifact@v4
26+
with:
27+
name: python-package-dist
28+
path: dist
29+
30+
pypi-publish:
31+
name: Upload release to PyPI
32+
runs-on: ubuntu-latest
33+
needs: build-release
34+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
35+
environment:
36+
name: pypi
37+
url: https://pypi.org/p/clang
38+
permissions:
39+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
40+
steps:
41+
- name: Download Python package dist artifacts
42+
uses: actions/download-artifact@v4
43+
with:
44+
name: python-package-dist
45+
path: dist
46+
- name: Publish package distributions to PyPI
47+
uses: pypa/gh-action-pypi-publish@release/v1

CMakeLists.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(clang NONE)
3+
4+
include(ExternalProject)
5+
6+
include(llvm_version.cmake)
7+
8+
# Set the URL and local paths
9+
set(CLANG_TARBALL_URL "https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang-${LLVM_VERSION}.src.tar.xz")
10+
set(CLANG_TARBALL "${CMAKE_BINARY_DIR}/clang-${LLVM_VERSION}.src.tar.xz")
11+
set(CLANG_SOURCE_DIR "${CMAKE_BINARY_DIR}/clang-src")
12+
set(PYTHON_BINDINGS_OUTPUT "${CLANG_SOURCE_DIR}/bindings/python/clang/")
13+
14+
# Download the tarball using ExternalProject_Add
15+
ExternalProject_Add(clang
16+
URL ${CLANG_TARBALL_URL}
17+
URL_HASH SHA256=${LLVM_SHA256}
18+
DOWNLOAD_DIR ${CMAKE_BINARY_DIR}
19+
SOURCE_DIR ${CLANG_SOURCE_DIR}
20+
CONFIGURE_COMMAND ""
21+
BUILD_COMMAND ""
22+
INSTALL_COMMAND ""
23+
LOG_DOWNLOAD OFF
24+
DOWNLOAD_EXTRACT_TIMESTAMP ON
25+
)
26+
27+
# Define installation so that scikit-build packages the python files into the wheel
28+
install(DIRECTORY ${PYTHON_BINDINGS_OUTPUT} DESTINATION clang USE_SOURCE_PERMISSIONS)

README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
Clang Python ppackage for pypi
2-
------------------------------
1+
# Clang Python package for PyPI
32

43
This is the python bindings subdir of llvm clang repository.
54
https://github.com/llvm/llvm-project/tree/main/clang/bindings/python
65

76
The debian packages are pulled from llvm repo, extracted and pushed to pypi.
87

9-
Installation
10-
------------
8+
## Installation
119

12-
`pip install clang`
10+
You can install the package using pip:
1311

14-
For a specific version
12+
```bash
13+
pip install clang
14+
```
1515

16-
`pip install clang==14`
16+
Or for a specific version:
17+
18+
```bash
19+
pip install clang==14
20+
```
21+
22+
## License
23+
24+
This project is licensed under the Apache-2.0 License with LLVM exception. See the LICENSE file for more details.

llvm_version.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
set(LLVM_VERSION 18.1.8)
2+
set(LLVM_SHA256 5724fe0a13087d5579104cedd2f8b3bc10a212fb79a0fcdac98f4880e19f4519)

make-from-packages.py

Lines changed: 0 additions & 118 deletions
This file was deleted.

packages.lst

Lines changed: 0 additions & 14 deletions
This file was deleted.

pyproject.toml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[build-system]
2+
requires = ["scikit-build-core"]
3+
build-backend = "scikit_build_core.build"
4+
5+
[project]
6+
name = "clang"
7+
description = "libclang python bindings"
8+
readme = "README.md"
9+
license = { text = "Apache-2.0 with LLVM exception" }
10+
authors = [
11+
{ name = "LLVM team - pypi upload by Loic Jaquemet" }
12+
]
13+
keywords = ["llvm", "clang", "libclang"]
14+
classifiers = [
15+
"Intended Audience :: Developers",
16+
"License :: OSI Approved :: Apache Software License",
17+
"Development Status :: 5 - Production/Stable",
18+
"Topic :: Software Development :: Compilers",
19+
"Programming Language :: Python :: 3",
20+
]
21+
dynamic = ["version"]
22+
23+
[project.urls]
24+
Homepage = "http://clang.llvm.org/"
25+
Download = "http://llvm.org/releases/download.html"
26+
27+
[dependecy-groups]
28+
dev = ["build", "twine"]
29+
30+
[tool.scikit-build]
31+
wheel.py-api = "py3"
32+
wheel.platlib = false
33+
wheel.license-files = []
34+
35+
[tool.scikit-build.metadata.version]
36+
provider = "scikit_build_core.metadata.regex"
37+
input = "llvm_version.cmake"
38+
regex = '''(?sx)
39+
set\(\s*LLVM_VERSION\s+(?P<version>\d+(?:\.\d+)+)\s*\)
40+
'''
41+
result = "{version}"

requirements.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)