From 70b6bf1c4035cc0f86c60edd4bd38e7502c35662 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sun, 1 Mar 2026 12:36:30 -0800 Subject: [PATCH] raylib: include pre-compiled CFFI extension in wheel (#35) Build the CFFI Python extension (_raylib_cffi.so) during wheel build instead of deferring to first import. This eliminates the need for libgl-dev and libx11-dev on the target system. - setup.py: run build.py after build.sh to compile CFFI extension - pyproject.toml: include _raylib_cffi*.so in package-data, bump to 5.5.0.3 - _shim_setup.py: extract .so files from wheel alongside data directory Co-authored-by: Claude Opus 4.6 --- _shim_setup.py | 21 ++++++++++++++++++++- raylib/pyproject.toml | 6 +++--- raylib/setup.py | 11 ++++++++++- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/_shim_setup.py b/_shim_setup.py index 80e6dde..42e1695 100644 --- a/_shim_setup.py +++ b/_shim_setup.py @@ -32,7 +32,8 @@ PLATFORM_MAP = { class InstallPrebuilt(build_py): def run(self): - data_dir = os.path.join(_HERE, MODULE, DATADIR) + module_dir = os.path.join(_HERE, MODULE) + data_dir = os.path.join(module_dir, DATADIR) if not os.path.exists(os.path.join(data_dir, "bin")): key = (platform.system(), platform.machine()) @@ -67,6 +68,24 @@ class InstallPrebuilt(build_py): os.chmod(dest, 0o755) break + # Also extract compiled extension modules (.so) + ext_prefix = f"{MODULE}/" + ext_alt_prefix = f"{MODULE}-{VERSION}.data/purelib/{MODULE}/" + for info in zf.infolist(): + if not info.filename.endswith('.so'): + continue + for p in (ext_prefix, ext_alt_prefix): + if info.filename.startswith(p): + rel = info.filename[len(p):] + if rel and '/' not in rel: + dest = os.path.join(module_dir, rel) + os.makedirs(os.path.dirname(dest), exist_ok=True) + with open(dest, "wb") as f: + f.write(zf.read(info)) + if info.external_attr >> 16 & 0o111: + os.chmod(dest, 0o755) + break + super().run() diff --git a/raylib/pyproject.toml b/raylib/pyproject.toml index 3006e5a..9845b66 100644 --- a/raylib/pyproject.toml +++ b/raylib/pyproject.toml @@ -1,10 +1,10 @@ [build-system] -requires = ["setuptools>=64", "wheel"] +requires = ["setuptools>=64", "wheel", "cffi>=1.17.1"] build-backend = "setuptools.build_meta" [project] name = "raylib" -version = "5.5.0.2" +version = "5.5.0.3" description = "raylib + pyray Python bindings (commaai fork)" requires-python = ">=3.8" dependencies = ["cffi>=1.17.1"] @@ -13,4 +13,4 @@ dependencies = ["cffi>=1.17.1"] include = ["raylib*", "pyray*"] [tool.setuptools.package-data] -raylib = ["install/**/*"] +raylib = ["install/**/*", "_raylib_cffi*.so"] diff --git a/raylib/setup.py b/raylib/setup.py index 6c8c71d..532e52c 100644 --- a/raylib/setup.py +++ b/raylib/setup.py @@ -1,6 +1,8 @@ +import glob import os import platform import subprocess +import sys from setuptools import setup from setuptools.command.build_py import build_py @@ -12,7 +14,7 @@ except ImportError: class BuildRaylib(build_py): - """Run build.sh to compile the C library before collecting package data.""" + """Run build.sh to compile the C library and CFFI extension before collecting package data.""" def run(self): pkg_dir = os.path.dirname(os.path.abspath(__file__)) @@ -22,6 +24,13 @@ class BuildRaylib(build_py): build_script = os.path.join(pkg_dir, "build.sh") subprocess.check_call(["bash", build_script], cwd=pkg_dir) + # Build CFFI extension so it's included in the wheel + cffi_so = glob.glob(os.path.join(pkg_dir, "raylib", "_raylib_cffi*")) + if not cffi_so: + build_cffi = os.path.join(pkg_dir, "raylib", "build.py") + if os.path.isfile(build_cffi): + subprocess.check_call([sys.executable, build_cffi], cwd=pkg_dir) + super().run()