Compare commits

..

3 Commits

Author SHA1 Message Date
Adeeb Shihadeh
70b6bf1c40 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 <noreply@anthropic.com>
2026-03-01 12:36:30 -08:00
Adeeb Shihadeh
d67b3e906e release: copy all Python sources and deps to shim branch (#34)
The shim branch was only copying __init__.py from each package,
which dropped Python source files needed for CFFI builds (build.py,
colors.py, defines.py, enums.py, version.py) and extra packages
like pyray. It also dropped project dependencies like cffi.

- Copy all .py files from the main module, not just __init__.py
- Copy extra packages listed in packages.find.include
- Preserve project dependencies in generated pyproject.toml
2026-03-01 12:04:48 -08:00
Adeeb Shihadeh
408cc4b949 add json11 package (#33)
* add libyuv package

* update libyuv to upstream 1922

* add json11 package
2026-03-01 11:29:13 -08:00
9 changed files with 186 additions and 7 deletions

View File

@@ -32,7 +32,8 @@ PLATFORM_MAP = {
class InstallPrebuilt(build_py): class InstallPrebuilt(build_py):
def run(self): 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")): if not os.path.exists(os.path.join(data_dir, "bin")):
key = (platform.system(), platform.machine()) key = (platform.system(), platform.machine())
@@ -67,6 +68,24 @@ class InstallPrebuilt(build_py):
os.chmod(dest, 0o755) os.chmod(dest, 0o755)
break 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() super().run()

41
json11/build.sh Executable file
View File

@@ -0,0 +1,41 @@
#!/usr/bin/env bash
set -euo pipefail
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
cd "$DIR"
VERSION="db00e9369a92aa74bf630a2ffb092a4b0b132c01"
INSTALL_DIR="$DIR/json11/install"
VERSION_FILE="$INSTALL_DIR/VERSION"
# Idempotent: skip if already built at this source revision.
if [ -f "$INSTALL_DIR/lib/libjson11.a" ] && [ -f "$INSTALL_DIR/include/json11/json11.hpp" ] && \
[ -f "$VERSION_FILE" ] && [ "$(cat "$VERSION_FILE")" = "$VERSION" ]; then
echo "json11 already present, skipping build."
exit 0
fi
if [ ! -d "$DIR/json11-src/.git" ]; then
git clone https://github.com/dropbox/json11.git json11-src
fi
git -C json11-src fetch --force origin
git -C json11-src checkout --force "$VERSION"
BUILD_DIR="$DIR/build"
rm -rf "$BUILD_DIR" "$INSTALL_DIR"
mkdir -p "$BUILD_DIR" "$INSTALL_DIR/lib" "$INSTALL_DIR/include/json11"
CXX="${CXX:-c++}"
AR="${AR:-ar}"
"$CXX" -std=c++11 -fPIC -O2 -c "$DIR/json11-src/json11.cpp" -o "$BUILD_DIR/json11.o"
"$AR" rcs "$INSTALL_DIR/lib/libjson11.a" "$BUILD_DIR/json11.o"
cp "$DIR/json11-src/json11.hpp" "$INSTALL_DIR/include/json11/json11.hpp"
echo "$VERSION" > "$VERSION_FILE"
# Keep workspace small and deterministic across builds.
rm -rf "$DIR/json11-src" "$BUILD_DIR"
echo "Installed json11 to $INSTALL_DIR"
du -sh "$INSTALL_DIR"

10
json11/json11/__init__.py Normal file
View File

@@ -0,0 +1,10 @@
import os
DIR = os.path.join(os.path.dirname(__file__), "install")
LIB_DIR = os.path.join(DIR, "lib")
INCLUDE_DIR = os.path.join(DIR, "include")
def smoketest():
assert os.path.isfile(os.path.join(LIB_DIR, "libjson11.a")), "libjson11.a not found"
assert os.path.isfile(os.path.join(INCLUDE_DIR, "json11", "json11.hpp")), "json11/json11.hpp not found"

15
json11/pyproject.toml Normal file
View File

@@ -0,0 +1,15 @@
[build-system]
requires = ["setuptools>=64", "wheel"]
build-backend = "setuptools.build_meta"
[project]
name = "json11"
version = "20170411.0"
description = "json11 JSON parser library (static build)"
requires-python = ">=3.8"
[tool.setuptools.packages.find]
include = ["json11*"]
[tool.setuptools.package-data]
json11 = ["install/**/*"]

61
json11/setup.py Normal file
View File

@@ -0,0 +1,61 @@
import os
import platform
import subprocess
from setuptools.command.build_py import build_py
try:
from wheel.bdist_wheel import bdist_wheel
except ImportError:
bdist_wheel = None
class BuildJson11(build_py):
"""Run build.sh to compile json11 before collecting package data."""
def run(self):
pkg_dir = os.path.dirname(os.path.abspath(__file__))
marker = os.path.join(pkg_dir, "json11", "install", "lib", "libjson11.a")
if not os.path.exists(marker):
build_script = os.path.join(pkg_dir, "build.sh")
subprocess.check_call(["bash", build_script], cwd=pkg_dir)
super().run()
cmdclass = {"build_py": BuildJson11}
if bdist_wheel is not None:
class PlatformWheel(bdist_wheel):
"""Produce a platform-specific, Python-version-agnostic wheel."""
def finalize_options(self):
super().finalize_options()
self.root_is_pure = False
def get_tag(self):
system = platform.system()
machine = platform.machine()
if system == "Linux":
plat = f"linux_{machine}"
elif system == "Darwin":
plat = "macosx_11_0_arm64"
else:
plat = f"{system.lower()}_{machine}"
return "py3", "none", plat
cmdclass["bdist_wheel"] = PlatformWheel
def setup():
from setuptools import setup as _setup
_setup(cmdclass=cmdclass)
if __name__ == "__main__":
setup()

View File

@@ -7,6 +7,7 @@ members = [
"ffmpeg", "ffmpeg",
"gcc-arm-none-eabi", "gcc-arm-none-eabi",
"git-lfs", "git-lfs",
"json11",
"libjpeg", "libjpeg",
"libyuv", "libyuv",
"ncurses", "ncurses",

View File

@@ -1,10 +1,10 @@
[build-system] [build-system]
requires = ["setuptools>=64", "wheel"] requires = ["setuptools>=64", "wheel", "cffi>=1.17.1"]
build-backend = "setuptools.build_meta" build-backend = "setuptools.build_meta"
[project] [project]
name = "raylib" name = "raylib"
version = "5.5.0.2" version = "5.5.0.3"
description = "raylib + pyray Python bindings (commaai fork)" description = "raylib + pyray Python bindings (commaai fork)"
requires-python = ">=3.8" requires-python = ">=3.8"
dependencies = ["cffi>=1.17.1"] dependencies = ["cffi>=1.17.1"]
@@ -13,4 +13,4 @@ dependencies = ["cffi>=1.17.1"]
include = ["raylib*", "pyray*"] include = ["raylib*", "pyray*"]
[tool.setuptools.package-data] [tool.setuptools.package-data]
raylib = ["install/**/*"] raylib = ["install/**/*", "_raylib_cffi*.so"]

View File

@@ -1,6 +1,8 @@
import glob
import os import os
import platform import platform
import subprocess import subprocess
import sys
from setuptools import setup from setuptools import setup
from setuptools.command.build_py import build_py from setuptools.command.build_py import build_py
@@ -12,7 +14,7 @@ except ImportError:
class BuildRaylib(build_py): 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): def run(self):
pkg_dir = os.path.dirname(os.path.abspath(__file__)) 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") build_script = os.path.join(pkg_dir, "build.sh")
subprocess.check_call(["bash", build_script], cwd=pkg_dir) 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() super().run()

View File

@@ -58,9 +58,28 @@ for toml in sorted(pathlib.Path(".").glob("*/pyproject.toml")):
pkg_dir = tmp_dir / pkg pkg_dir = tmp_dir / pkg
mod_dir = pkg_dir / module mod_dir = pkg_dir / module
mod_dir.mkdir(parents=True, exist_ok=True) mod_dir.mkdir(parents=True, exist_ok=True)
shutil.copy2(pathlib.Path(pkg) / module / "__init__.py", mod_dir / "__init__.py")
# copy all .py files from the main module
src_mod = pathlib.Path(pkg) / module
for py_file in src_mod.glob("*.py"):
shutil.copy2(py_file, mod_dir / py_file.name)
# copy extra packages (e.g. pyray for raylib)
include_patterns = data.get("tool", {}).get("setuptools", {}).get("packages", {}).get("find", {}).get("include", [])
extra_packages = []
for pattern in include_patterns:
p = pattern.rstrip("*")
if p and p != module and p != f"{module}/":
src_extra = pathlib.Path(pkg) / p
if src_extra.is_dir():
dst_extra = pkg_dir / p
shutil.copytree(src_extra, dst_extra, dirs_exist_ok=True)
extra_packages.append(pattern)
shutil.copy2(shim_setup, pkg_dir / "setup.py") shutil.copy2(shim_setup, pkg_dir / "setup.py")
deps = data.get("project", {}).get("dependencies", [])
lines = [ lines = [
"[build-system]", "[build-system]",
'requires = ["setuptools>=64", "wheel", \'tomli; python_version < \"3.11\"\']', 'requires = ["setuptools>=64", "wheel", \'tomli; python_version < \"3.11\"\']',
@@ -73,15 +92,19 @@ for toml in sorted(pathlib.Path(".").glob("*/pyproject.toml")):
'requires-python = ">=3.8"', 'requires-python = ">=3.8"',
] ]
if deps:
lines.append(f"dependencies = {json.dumps(deps)}")
if scripts: if scripts:
lines += ["", "[project.scripts]"] lines += ["", "[project.scripts]"]
for name, target in scripts.items(): for name, target in scripts.items():
lines.append(f'"{name}" = {json.dumps(target)}') lines.append(f'"{name}" = {json.dumps(target)}')
find_include = [f"{module}*"] + extra_packages
lines += [ lines += [
"", "",
"[tool.setuptools.packages.find]", "[tool.setuptools.packages.find]",
f'include = ["{module}*"]', f"include = {json.dumps(find_include)}",
"", "",
"[tool.setuptools.package-data]", "[tool.setuptools.package-data]",
f'{module} = ["{datadir}/**/*"]', f'{module} = ["{datadir}/**/*"]',