Skip to content
Draft
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
47 changes: 47 additions & 0 deletions .github/actions/install-test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Install the wheel and run the tests
description: >
Installs the built wheel into a clean virtual environment for one Python and
runs the installed-wheel checks, the binding tests and the conformance corpus
from a copy of tests/ outside the checkout, with python -I.
inputs:
python:
description: Python version
required: true
runs:
using: composite
steps:
- uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python }}
- name: Install the wheel into a clean environment
shell: bash
run: |
env="$RUNNER_TEMP/clean-${{ inputs.python }}"
python -m venv "$env"
if [ "$RUNNER_OS" = Windows ]; then py="$env/Scripts/python.exe"; else py="$env/bin/python"; fi
echo "PY=$py" >> "$GITHUB_ENV"
"$py" -m pip install --no-index --no-deps "$GITHUB_WORKSPACE"/dist/*.whl
"$py" -m pip list
# Tests run from a copy outside the checkout so the source tree cannot be imported.
rm -rf "$RUNNER_TEMP/run" && mkdir "$RUNNER_TEMP/run"
cp -r tests "$RUNNER_TEMP/run/tests"
- name: Installed-wheel checks
shell: bash
working-directory: ${{ runner.temp }}/run
env:
UKIRYU_WHEEL_EVIDENCE: ${{ github.workspace }}/evidence/wheel.json
run: '"$PY" -I -m unittest discover -s tests/wheel -v'
- name: Binding tests against the installed wheel
if: ${{ !cancelled() }}
shell: bash
working-directory: ${{ runner.temp }}/run
run: '"$PY" -I -m unittest discover -s tests -p "test_[vae]*.py" -v'
- name: Conformance corpus against the installed wheel
if: ${{ !cancelled() }}
shell: bash
working-directory: ${{ runner.temp }}/run
env:
CI: 'true'
UKIRYU_CONFORMANCE_DIR: ${{ github.workspace }}/ukiryu-rs/corpus/conformance
UKIRYU_CORPUS_REPORT: ${{ github.workspace }}/corpus-report-${{ inputs.python }}.json
run: '"$PY" -I -m unittest discover -s tests -p "test_corpus.py" -v'
149 changes: 149 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
name: Wheels

# Per-platform wheels that carry the pinned ukiryu-rs C library, installed
# into clean environments (in the same job, so one slow runner type does not
# hold the others back) and run against the conformance corpus. Nothing is
# published: the wheels are workflow artifacts only.

on:
pull_request:
push:
branches: [main]
workflow_dispatch:

permissions:
contents: read

concurrency:
group: wheels-${{ github.ref }}
cancel-in-progress: true

env:
RUST_TOOLCHAIN: 1.95.0

jobs:
build:
name: ${{ matrix.name }}
runs-on: ${{ matrix.runner }}
timeout-minutes: 90
strategy:
fail-fast: false
matrix:
include:
- name: linux-x86_64
runner: ubuntu-24.04
plat: manylinux_2_28_x86_64
container: quay.io/pypa/manylinux_2_28_x86_64
- name: linux-aarch64
runner: ubuntu-24.04-arm
plat: manylinux_2_28_aarch64
container: quay.io/pypa/manylinux_2_28_aarch64
- name: macos-arm64
runner: macos-15
plat: macosx_11_0_arm64
deployment: '11.0'
- name: macos-x86_64
runner: macos-15-intel
plat: macosx_10_15_x86_64
deployment: '10.15'
- name: windows-x86_64
runner: windows-2022
plat: win_amd64
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-python@v5
with:
python-version: '3.13'
- name: Build the core library in the manylinux image
if: matrix.container
run: |
docker run --rm -v "$GITHUB_WORKSPACE:/w" -w /w/ukiryu-rs "${{ matrix.container }}" bash -euxo pipefail -c '
curl -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain "'"$RUST_TOOLCHAIN"'"
. "$HOME/.cargo/env"
cargo build -p ukiryu-ffi --release --locked
chown -R '"$(id -u):$(id -g)"' /w/ukiryu-rs/target
'
echo "LIBRARY=$GITHUB_WORKSPACE/ukiryu-rs/target/release/libukiryu_ffi.so" >> "$GITHUB_ENV"
- uses: dtolnay/rust-toolchain@stable
if: ${{ !matrix.container }}
with:
toolchain: 1.95.0
- uses: Swatinem/rust-cache@v2
if: ${{ !matrix.container }}
with:
workspaces: ukiryu-rs
key: wheel-${{ matrix.name }}
- name: Build the core library
if: ${{ !matrix.container }}
shell: bash
working-directory: ukiryu-rs
env:
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.deployment }}
# Static CRT: the wheel must not need the Visual C++ redistributable.
RUSTFLAGS: ${{ runner.os == 'Windows' && '-C target-feature=+crt-static' || '' }}
run: |
cargo build -p ukiryu-ffi --release --locked
case "$RUNNER_OS" in
macOS) lib=libukiryu_ffi.dylib ;;
Windows) lib=ukiryu_ffi.dll ;;
esac
echo "LIBRARY=$GITHUB_WORKSPACE/ukiryu-rs/target/release/$lib" >> "$GITHUB_ENV"
- name: Build tools
shell: bash
run: |
python -m pip install "setuptools>=70.1" wheel
case "$RUNNER_OS" in
Linux) python -m pip install auditwheel ;;
Windows) python -m pip install pefile ;;
esac
- name: Build the wheel
shell: bash
run: |
test -f "$LIBRARY"
python scripts/build_wheel.py "$LIBRARY" "${{ matrix.plat }}" dist
ls -l dist
- name: Check the wheel and record hashes
shell: bash
run: |
mkdir -p evidence
python scripts/check_wheel.py dist/*.whl "${{ matrix.plat }}" evidence/wheel.json
- uses: actions/upload-artifact@v4
with:
name: wheel-${{ matrix.name }}
path: |
dist/*.whl
evidence/wheel.json
if-no-files-found: error
- name: Install and test on Python 3.9
uses: ./.github/actions/install-test
with:
python: '3.9'
- name: Install and test on Python 3.13
if: ${{ !cancelled() }}
uses: ./.github/actions/install-test
with:
python: '3.13'
- name: Corpus on the manylinux glibc baseline
if: ${{ !cancelled() && matrix.container }}
shell: bash
run: |
image="${{ matrix.container }}"
docker run --rm -v "$GITHUB_WORKSPACE:/w" -e CI=true \
-e UKIRYU_WHEEL_EVIDENCE=/w/evidence/wheel.json \
-e UKIRYU_CONFORMANCE_DIR=/w/ukiryu-rs/corpus/conformance "$image" bash -euxo pipefail -c '
/opt/python/cp39-cp39/bin/python -m venv /tmp/clean
/tmp/clean/bin/python -m pip install --no-index --no-deps /w/dist/*.whl
mkdir /tmp/run && cp -r /w/tests /tmp/run/tests && cd /tmp/run
ldd --version | head -1
/tmp/clean/bin/python -I -m unittest discover -s tests/wheel -v
/tmp/clean/bin/python -I -m unittest discover -s tests -p "test_corpus.py" -v
'
- uses: actions/upload-artifact@v4
if: always()
with:
name: corpus-report-${{ matrix.name }}
path: corpus-report-*.json
if-no-files-found: warn

15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,18 @@ PYTHONPATH=src python -m unittest discover -s tests

The corpus test runs the shared conformance corpus through the public Python
API and pins how many rows each operation runs.

## Platform wheels

`.github/workflows/wheels.yml` builds one wheel per platform, each carrying
the pinned core's C library at `ukiryu/lib/`: Linux x86_64 and aarch64 (built
in a manylinux_2_28 image), macOS arm64 and x86_64, and Windows x86_64. The
wheels are tagged `py3-none-<platform>`; there is no sdist and nothing is
published. `scripts/check_wheel.py` checks the library's glibc, macOS
deployment or Windows import baseline from the binary and records the wheel,
library and core hashes. Each wheel is then installed into a clean
environment, outside the source tree, and runs the binding tests and the
conformance corpus against the installed package.

The package name, version and Python floor in `pyproject.toml` are the values
the repository already uses; they are not a ratified release contract.
25 changes: 25 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[build-system]
requires = ["setuptools>=70.1", "wheel"]
build-backend = "setuptools.build_meta"

# The name, version and Python floor below are what the repository already
# uses (src/ukiryu/__init__.py and the CI matrix). They are build inputs for
# the wheel gate and are not a ratified release contract: the package
# metadata is an owner decision and nothing here is published.
[project]
name = "ukiryu"
dynamic = ["version"]
requires-python = ">=3.9"
description = "Python binding for the Ukiryu core, over its C ABI."
readme = "README.md"

[tool.setuptools]
package-dir = {"" = "src"}
packages = ["ukiryu"]
include-package-data = false

[tool.setuptools.package-data]
ukiryu = ["lib/*"]

[tool.setuptools.dynamic]
version = {attr = "ukiryu.__version__"}
47 changes: 47 additions & 0 deletions scripts/build_wheel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Build one platform wheel around a built ukiryu-ffi library.

Usage: python scripts/build_wheel.py LIBRARY PLATFORM_TAG OUT_DIR

Copies LIBRARY to src/ukiryu/lib/ under the name the loader expects, builds
a wheel tagged py3-none-PLATFORM_TAG with pip (no isolation, no sdist), and
removes the copy again. Needs setuptools>=70.1 and wheel installed.
"""

import os
import shutil
import subprocess
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "src"))

from ukiryu._ffi import library_file_name # noqa: E402


def main() -> int:
if len(sys.argv) != 4:
sys.stderr.write(__doc__)
return 2
library, plat, out = Path(sys.argv[1]), sys.argv[2], Path(sys.argv[3])
if not library.is_file():
sys.stderr.write("library not found: %s\n" % library)
return 2
lib_dir = ROOT / "src" / "ukiryu" / "lib"
shutil.rmtree(lib_dir, ignore_errors=True)
shutil.rmtree(ROOT / "build", ignore_errors=True)
lib_dir.mkdir(parents=True)
shutil.copy2(library, lib_dir / library_file_name())
out.mkdir(parents=True, exist_ok=True)
try:
subprocess.run([sys.executable, "-m", "pip", "wheel", str(ROOT), "--no-deps",
"--no-build-isolation", "-w", str(out)],
check=True, env=dict(os.environ, UKIRYU_WHEEL_PLAT=plat))
finally:
shutil.rmtree(lib_dir, ignore_errors=True)
shutil.rmtree(ROOT / "build", ignore_errors=True)
return 0


if __name__ == "__main__":
sys.exit(main())
Loading
Loading