Compare commits
8 Commits
json11/v20
...
raylib/v5.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2341b89849 | ||
|
|
7d158432af | ||
|
|
c81badf4a5 | ||
|
|
122939fdf2 | ||
|
|
9690fd5160 | ||
|
|
c835b206c6 | ||
|
|
70b6bf1c40 | ||
|
|
d67b3e906e |
@@ -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()
|
||||
|
||||
|
||||
|
||||
@@ -6,11 +6,18 @@ cd "$DIR"
|
||||
|
||||
INSTALL_DIR="$DIR/raylib/install"
|
||||
|
||||
# Idempotent: skip if already built
|
||||
# Idempotent: skip if already fully built
|
||||
# On x86_64 Linux, also require the offscreen variant
|
||||
NEED_OFFSCREEN=0
|
||||
if [[ "$(uname)" == "Linux" && "$(uname -m)" == "x86_64" ]]; then
|
||||
NEED_OFFSCREEN=1
|
||||
fi
|
||||
if [ -f "$INSTALL_DIR/lib/libraylib.a" ]; then
|
||||
if [ "$NEED_OFFSCREEN" -eq 0 ] || [ -f "$INSTALL_DIR/lib/libraylib_offscreen.a" ]; then
|
||||
echo "raylib already present, skipping build."
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
NJOBS="$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)"
|
||||
|
||||
@@ -33,6 +40,15 @@ if [[ "$(uname)" == "Linux" ]]; then
|
||||
sudo apt-get update && sudo apt-get install -y libdrm-dev libgbm-dev libgles2-mesa-dev libegl1-mesa-dev || true
|
||||
fi
|
||||
fi
|
||||
elif [ "$RAYLIB_PLATFORM" = "PLATFORM_OFFSCREEN" ]; then
|
||||
# offscreen (CI): needs EGL/GL dev packages (no X11)
|
||||
if command -v apt-get &>/dev/null; then
|
||||
if [ "$(id -u)" -eq 0 ]; then
|
||||
apt-get update && apt-get install -y libegl-dev libgl-dev
|
||||
else
|
||||
sudo apt-get update && sudo apt-get install -y libegl-dev libgl-dev
|
||||
fi
|
||||
fi
|
||||
else
|
||||
# desktop: needs X11/GL dev packages
|
||||
if command -v dnf &>/dev/null; then
|
||||
@@ -48,10 +64,10 @@ if [[ "$(uname)" == "Linux" ]]; then
|
||||
fi
|
||||
|
||||
# Clone and build raylib C library
|
||||
RAYLIB_COMMIT="aa6ade09ac4bfb2847a356535f2d9f87e49ab089"
|
||||
RAYLIB_COMMIT="d9d7cc1353ec0f73c97e84ddf0973983d1ee25e2"
|
||||
|
||||
if [ ! -d "raylib-src" ]; then
|
||||
git clone -b master --no-tags https://github.com/commaai/raylib.git raylib-src
|
||||
git clone -b platform-offscreen --no-tags https://github.com/commaai/raylib.git raylib-src
|
||||
fi
|
||||
|
||||
cd raylib-src
|
||||
@@ -71,6 +87,42 @@ mkdir -p "$INSTALL_DIR"/{lib,include}
|
||||
cp raylib-src/src/libraylib.a "$INSTALL_DIR/lib/"
|
||||
cp raylib-src/src/raylib.h raylib-src/src/raymath.h raylib-src/src/rlgl.h "$INSTALL_DIR/include/"
|
||||
|
||||
# On x86_64 Linux, also build the offscreen variant for CI headless rendering
|
||||
if [[ "$(uname)" == "Linux" && "$(uname -m)" == "x86_64" && "$RAYLIB_PLATFORM" != "PLATFORM_OFFSCREEN" ]]; then
|
||||
echo "Building offscreen variant..."
|
||||
|
||||
# Install EGL/GL dev packages needed for offscreen build + bundling
|
||||
if command -v dnf &>/dev/null; then
|
||||
dnf install -y mesa-libEGL-devel mesa-libGL-devel libglvnd-opengl libglvnd-core-devel 2>/dev/null || true
|
||||
elif command -v apt-get &>/dev/null; then
|
||||
if [ "$(id -u)" -eq 0 ]; then
|
||||
apt-get update && apt-get install -y libegl-dev libgl-dev
|
||||
else
|
||||
sudo apt-get update && sudo apt-get install -y libegl-dev libgl-dev
|
||||
fi
|
||||
fi
|
||||
|
||||
cd raylib-src/src
|
||||
make clean
|
||||
make -j"$NJOBS" PLATFORM=PLATFORM_OFFSCREEN
|
||||
cp libraylib.a "$INSTALL_DIR/lib/libraylib_offscreen.a"
|
||||
cd "$DIR"
|
||||
|
||||
# Bundle GLVND dispatchers so offscreen rendering works without extra system packages
|
||||
MESA_DIR="$INSTALL_DIR/lib/mesa"
|
||||
mkdir -p "$MESA_DIR"
|
||||
ldconfig 2>/dev/null || true
|
||||
for lib in libEGL.so.1 libOpenGL.so.0 libGLdispatch.so.0; do
|
||||
src="$(ldconfig -p 2>/dev/null | grep "$lib" | grep -E 'x86.64|libc6,' | awk '{print $NF}' | head -1)"
|
||||
if [ -n "$src" ] && [ -f "$src" ]; then
|
||||
cp -L "$src" "$MESA_DIR/"
|
||||
# Create unversioned symlink for the linker
|
||||
base="${lib%%.so.*}"
|
||||
ln -sf "$lib" "$MESA_DIR/${base}.so"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Download raygui header
|
||||
RAYGUI_COMMIT="76b36b597edb70ffaf96f046076adc20d67e7827"
|
||||
curl -fsSLo "$INSTALL_DIR/include/raygui.h" \
|
||||
|
||||
@@ -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.7"
|
||||
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"]
|
||||
|
||||
@@ -1,26 +1,60 @@
|
||||
import os
|
||||
import platform as _platform
|
||||
|
||||
DIR = os.path.join(os.path.dirname(__file__), "install")
|
||||
LIB_DIR = os.path.join(DIR, "lib")
|
||||
INCLUDE_DIR = os.path.join(DIR, "include")
|
||||
|
||||
|
||||
def _detect_platform():
|
||||
"""Auto-detect the raylib platform. In CI on Linux x86_64, use offscreen EGL rendering."""
|
||||
explicit = os.environ.get("RAYLIB_PLATFORM", "")
|
||||
if explicit:
|
||||
return explicit
|
||||
if os.environ.get("CI") and _platform.system() == "Linux" and _platform.machine() == "x86_64":
|
||||
return "PLATFORM_OFFSCREEN"
|
||||
return ""
|
||||
|
||||
|
||||
def smoketest():
|
||||
assert os.path.isfile(os.path.join(LIB_DIR, "libraylib.a")), "libraylib.a not found"
|
||||
assert os.path.isfile(os.path.join(INCLUDE_DIR, "raylib.h")), "raylib.h not found"
|
||||
|
||||
|
||||
# Build CFFI extension on first import if not already compiled
|
||||
# Build CFFI extension on first import if not already compiled,
|
||||
# or rebuild if the target platform changed since last build.
|
||||
def _ensure_cffi_built():
|
||||
import glob
|
||||
import subprocess
|
||||
import sys
|
||||
pkg_dir = os.path.dirname(__file__)
|
||||
if not glob.glob(os.path.join(pkg_dir, "_raylib_cffi*")):
|
||||
platform_marker = os.path.join(pkg_dir, ".raylib_platform")
|
||||
requested = _detect_platform()
|
||||
|
||||
# Export so build.py picks it up
|
||||
if requested:
|
||||
os.environ["RAYLIB_PLATFORM"] = requested
|
||||
# Mesa llvmpipe for software rendering in headless CI
|
||||
if requested == "PLATFORM_OFFSCREEN":
|
||||
os.environ.setdefault("LIBGL_ALWAYS_SOFTWARE", "1")
|
||||
|
||||
cffi_files = glob.glob(os.path.join(pkg_dir, "_raylib_cffi*"))
|
||||
|
||||
# Rebuild if platform changed
|
||||
if cffi_files and requested:
|
||||
built_for = open(platform_marker).read().strip() if os.path.isfile(platform_marker) else ""
|
||||
if built_for != requested:
|
||||
for f in cffi_files:
|
||||
os.remove(f)
|
||||
cffi_files = []
|
||||
|
||||
if not cffi_files:
|
||||
build_script = os.path.join(pkg_dir, "build.py")
|
||||
if os.path.isfile(build_script) and os.path.isfile(os.path.join(LIB_DIR, "libraylib.a")):
|
||||
try:
|
||||
subprocess.check_call([sys.executable, build_script], cwd=os.path.dirname(pkg_dir))
|
||||
with open(platform_marker, "w") as f:
|
||||
f.write(requested)
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ def build_ffi():
|
||||
'-framework', 'CoreVideo',
|
||||
]
|
||||
libraries = []
|
||||
extra_compile_args = ["-Wno-error=incompatible-function-pointer-types", "-D_CFFI_NO_LIMITED_API"]
|
||||
extra_compile_args = ["-Wno-error=incompatible-function-pointer-types"]
|
||||
else:
|
||||
print("BUILDING FOR LINUX")
|
||||
extra_link_args = [
|
||||
@@ -104,15 +104,26 @@ def build_ffi():
|
||||
if RAYLIB_PLATFORM == "PLATFORM_COMMA":
|
||||
extra_link_args.remove('-lGL')
|
||||
extra_link_args += ['-lGLESv2', '-lEGL', '-lgbm', '-ldrm']
|
||||
elif RAYLIB_PLATFORM == "PLATFORM_OFFSCREEN":
|
||||
# Use offscreen variant if available, otherwise fall back to default
|
||||
offscreen_lib = os.path.join(RAYLIB_LIB_PATH, 'libraylib_offscreen.a')
|
||||
if os.path.isfile(offscreen_lib):
|
||||
extra_link_args[extra_link_args.index('-lraylib')] = '-lraylib_offscreen'
|
||||
extra_link_args.remove('-lGL')
|
||||
# Use bundled GLVND dispatchers if available, with RPATH for runtime
|
||||
mesa_dir = os.path.join(RAYLIB_LIB_PATH, 'mesa')
|
||||
if os.path.isdir(mesa_dir):
|
||||
extra_link_args += [f'-L{mesa_dir}', f'-Wl,-rpath,$ORIGIN/install/lib/mesa']
|
||||
extra_link_args += ['-lOpenGL', '-lEGL']
|
||||
else:
|
||||
extra_link_args += ['-lX11']
|
||||
extra_compile_args = ["-Wno-incompatible-pointer-types", "-D_CFFI_NO_LIMITED_API"]
|
||||
extra_compile_args = ["-Wno-incompatible-pointer-types"]
|
||||
libraries = []
|
||||
|
||||
print("extra_link_args: " + str(extra_link_args))
|
||||
ffibuilder.set_source("raylib._raylib_cffi",
|
||||
ffi_includes,
|
||||
py_limited_api=False,
|
||||
py_limited_api=True,
|
||||
include_dirs=[RAYLIB_INCLUDE_PATH],
|
||||
extra_link_args=extra_link_args,
|
||||
extra_compile_args=extra_compile_args,
|
||||
|
||||
@@ -1 +1 @@
|
||||
__version__ = "5.5.0.2"
|
||||
__version__ = "5.5.0.7"
|
||||
@@ -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()
|
||||
|
||||
|
||||
|
||||
29
release.sh
29
release.sh
@@ -58,9 +58,28 @@ for toml in sorted(pathlib.Path(".").glob("*/pyproject.toml")):
|
||||
pkg_dir = tmp_dir / pkg
|
||||
mod_dir = pkg_dir / module
|
||||
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")
|
||||
|
||||
deps = data.get("project", {}).get("dependencies", [])
|
||||
|
||||
lines = [
|
||||
"[build-system]",
|
||||
'requires = ["setuptools>=64", "wheel", \'tomli; python_version < \"3.11\"\']',
|
||||
@@ -73,18 +92,22 @@ for toml in sorted(pathlib.Path(".").glob("*/pyproject.toml")):
|
||||
'requires-python = ">=3.8"',
|
||||
]
|
||||
|
||||
if deps:
|
||||
lines.append(f"dependencies = {json.dumps(deps)}")
|
||||
|
||||
if scripts:
|
||||
lines += ["", "[project.scripts]"]
|
||||
for name, target in scripts.items():
|
||||
lines.append(f'"{name}" = {json.dumps(target)}')
|
||||
|
||||
find_include = [f"{module}*"] + extra_packages
|
||||
lines += [
|
||||
"",
|
||||
"[tool.setuptools.packages.find]",
|
||||
f'include = ["{module}*"]',
|
||||
f"include = {json.dumps(find_include)}",
|
||||
"",
|
||||
"[tool.setuptools.package-data]",
|
||||
f'{module} = ["{datadir}/**/*"]',
|
||||
f'{module} = ["{datadir}/**/*", "*.so"]',
|
||||
"",
|
||||
"[tool.shim]",
|
||||
f'repo_url = "{repo_url}"',
|
||||
|
||||
Reference in New Issue
Block a user