Skip to content
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
109 changes: 109 additions & 0 deletions .github/workflows/build-tree-sitter-languages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# SPDX-FileCopyrightText: 2026 The RISE Project
# SPDX-License-Identifier: MIT
---
# This workflow is based on: https://github.com/grantjenks/py-tree-sitter-languages/blob/v1.10.2/.github/workflows/release.yml
name: Build tree-sitter-languages wheels (riscv64)

on:
workflow_dispatch:
inputs:
version:
description: 'tree-sitter-languages version to build (git tag without the leading v, e.g. 1.10.2)'
required: true
default: '1.10.2'
pull_request:
paths:
- '.github/workflows/build-tree-sitter-languages.yml'
- 'patches/tree-sitter-languages/**'

concurrency:
group: ${{ github.workflow }}-${{ inputs.version || '1.10.2' }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

permissions:
contents: read # to fetch code (actions/checkout)

env:
# `inputs.version` is empty on pull_request events; default to 1.10.2 there.
TREE_SITTER_LANGUAGES_VERSION: ${{ inputs.version || '1.10.2' }}
MANYLINUX_RISCV64_IMAGE: quay.io/pypa/manylinux_2_39_riscv64
# build.py needs Language.build_library and core.pyx needs Language(path, name);
# both were removed in tree-sitter 0.22.
TREE_SITTER_SPEC: 'tree-sitter<0.22'
# Upstream pins cython==3.0.8, which predates free threading and cannot compile
# core.pyx under cp314t.
CYTHON_SPEC: 'cython==3.3.0'
# setuptools 79.0.0 dropped -shared from distutils' C++ link command, so
# build.py links languages.so as an executable and fails on `main`.
SETUPTOOLS_SPEC: 'setuptools<79'

jobs:
build_wheels:
name: Build tree-sitter-languages ${{ inputs.version || '1.10.2' }} ${{ matrix.python }}-manylinux_riscv64
runs-on: ubuntu-24.04-riscv
timeout-minutes: 240
strategy:
fail-fast: false
matrix:
python: ["cp312", "cp313", "cp314", "cp314t"]

steps:
- name: Checkout tree-sitter-languages v${{ env.TREE_SITTER_LANGUAGES_VERSION }}
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
repository: grantjenks/py-tree-sitter-languages
ref: v${{ env.TREE_SITTER_LANGUAGES_VERSION }}
persist-credentials: false

- name: Checkout python-wheels
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
path: python-wheels
persist-credentials: false

- name: Patch tree-sitter-languages source
run: git apply python-wheels/patches/tree-sitter-languages/${{ env.TREE_SITTER_LANGUAGES_VERSION }}/*.patch

- name: Build wheels
uses: pypa/cibuildwheel@1828c10ab37f080699c7b81cea34097c684a7074 # v4.2.0
with:
output-dir: wheelhouse/
only: ${{ matrix.python }}-manylinux_riscv64
env:
CIBW_MANYLINUX_RISCV64_IMAGE: ${{ env.MANYLINUX_RISCV64_IMAGE }}
# Upstream runs `pip install -e . && python build.py`, which resolves
# tree-sitter to whatever is newest; install the pinned one instead.
CIBW_BEFORE_BUILD: pip install "${{ env.CYTHON_SPEC }}" "${{ env.TREE_SITTER_SPEC }}" "${{ env.SETUPTOOLS_SPEC }}" wheel && python build.py
# setup.py imports Cython at module level and declares no build-system
# table, so the build has to see the preinstalled one.
CIBW_BUILD_FRONTEND: "pip; args: --no-build-isolation"
CIBW_TEST_REQUIRES: pytest ${{ env.TREE_SITTER_SPEC }}
# Assert the patched license_files glob still ships the 46 vendored
# grammar licences, then run upstream's suite over all 48 grammars.
CIBW_TEST_COMMAND: >-
python -c "import importlib.metadata as md; f = [str(p) for p in md.files('tree_sitter_languages') if '.dist-info/licenses/vendor/' in str(p)]; assert len(f) == 46, f"
&& pytest --showlocals {package}/tests

- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: tree-sitter-languages-${{ env.TREE_SITTER_LANGUAGES_VERSION }}-${{ matrix.python }}-manylinux_riscv64
path: wheelhouse/*.whl
if-no-files-found: error

publish:
name: Publish tree-sitter-languages ${{ inputs.version || '1.10.2' }} to GitLab
needs: [build_wheels]
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
- name: Publish wheels and open docs PR
uses: riseproject-dev/python-wheels/actions/publish-wheels@main
with:
artifact-pattern: tree-sitter-languages-${{ env.TREE_SITTER_LANGUAGES_VERSION }}-*-manylinux_riscv64
gitlab-username: ${{ vars.GITLAB_DEPLOY_USER }}
gitlab-token: ${{ secrets.GITLAB_DEPLOY_TOKEN }}
gitlab-project-id: ${{ vars.GITLAB_PROJECT_ID }}
gh-token: ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
From 52a0626b7c2b214658681758ae9fd4562904c814 Mon Sep 17 00:00:00 2001
From: Ludovic Henry <git@ludovic.dev>
Date: Wed, 26 Aug 2026 20:41:24 +0200
Subject: [PATCH] ship the vendored grammar licences in the wheel

Upstream-Status: To upstream [not yet submitted; the same gap exists in every tree_sitter_languages wheel on PyPI, so it needs a maintainer discussion rather than a drive-by PR]

languages.so is the 48 grammar repositories listed in repos.txt compiled
into one shared library, and every one of them carries its own MIT or
Apache-2.0 licence whose binary-redistribution clause requires the
copyright notice to travel with the binary. The built wheel ships only
tree_sitter_languages' own LICENSE.

setuptools' default license_files glob only looks at the project root, so
the vendored files need naming explicitly; the project's own LICENSE is
listed alongside them because setting license_files replaces the default
glob rather than extending it. build.py has already cloned vendor/ by the
time the wheel is built, so the 46 grammars that ship a licence file at
their pinned commit land in dist-info/licenses/. tree-sitter-ql and
tree-sitter-fixed-form-fortran carry no licence file at the commits
repos.txt pins.

Signed-off-by: Ludovic Henry <git@ludovic.dev>
---
setup.py | 1 +
1 file changed, 1 insertion(+)

diff --git a/setup.py b/setup.py
index f5b2ae0..e87f6ed 100644
--- a/setup.py
+++ b/setup.py
@@ -20,6 +20,7 @@ setuptools.setup(
author_email='contact@grantjenks.com',
url='https://github.com/grantjenks/py-tree-sitter-languages',
license='Apache 2.0',
+ license_files=['LICENSE', 'vendor/*/LICENSE*'],
ext_modules=cythonize('tree_sitter_languages/core.pyx', language_level='3'),
packages=['tree_sitter_languages'],
package_data={'tree_sitter_languages': ['languages.so', 'languages.dll']},
--
2.50.1 (Apple Git-155)

Loading