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
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ echo
echo "Running smoketests"

uv venv --allow-existing --quiet "$VENV_DIR"
uv pip install --python "$VENV_DIR/bin/python" --quiet "cffi>=1.17.1" >/dev/null
uv pip install --python "$VENV_DIR/bin/python" --reinstall --no-deps --quiet dist/*.whl >/dev/null

for toml in */pyproject.toml; do
Expand Down
1 change: 0 additions & 1 deletion raylib/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
raylib-src/
raylib/install/
raylib/*.modified
raylib/_raylib_cffi*
128 changes: 50 additions & 78 deletions raylib/build.sh
Original file line number Diff line number Diff line change
@@ -1,119 +1,91 @@
#!/usr/bin/env bash
set -e
set -euo pipefail

DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
cd "$DIR"

INSTALL_DIR="$DIR/raylib/install"

NJOBS="$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)"
CC="ccache ${CC:-cc}"
if command -v ccache &>/dev/null; then
CC="ccache ${CC:-cc}"
else
CC="${CC:-cc}"
fi

is_linux_aarch64() {
[[ "$(uname)" == "Linux" && ( "$(uname -m)" == "aarch64" || "$(uname -m)" == "arm64" ) ]]
}

# Detect platform: PLATFORM_COMMA for comma devices, PLATFORM_DESKTOP otherwise
RAYLIB_PLATFORM="${RAYLIB_PLATFORM:-PLATFORM_DESKTOP}"
if [ -f /TICI ]; then
RAYLIB_PLATFORM="PLATFORM_COMMA"
if [ -n "${RAYLIB_PLATFORM:-}" ]; then
echo "RAYLIB_PLATFORM is no longer supported; use RAYLIB_BACKEND=desktop or RAYLIB_BACKEND=comma" >&2
exit 1
fi
export RAYLIB_PLATFORM

# Install build dependencies
if [[ "$(uname)" == "Linux" ]]; then
if [ "$RAYLIB_PLATFORM" = "PLATFORM_COMMA" ]; then
# comma device: needs DRM/EGL/GLES headers (usually already present on AGNOS)
# apt may fail on devices due to read-only rootfs or package conflicts — that's OK
if command -v apt-get &>/dev/null; then
if [ "$(id -u)" -eq 0 ]; then
apt-get update && apt-get install -y libdrm-dev libgbm-dev libgles2-mesa-dev libegl1-mesa-dev || true
else
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
dnf install -y libX11-devel libXcursor-devel libXrandr-devel libXinerama-devel libXi-devel mesa-libGL-devel
elif command -v apt-get &>/dev/null; then
if [ "$(id -u)" -eq 0 ]; then
apt-get update && apt-get install -y libxcursor-dev libxi-dev libxinerama-dev libxrandr-dev libgl-dev
else
sudo apt-get update && sudo apt-get install -y libxcursor-dev libxi-dev libxinerama-dev libxrandr-dev libgl-dev
fi
fi

RAYLIB_BACKEND="${RAYLIB_BACKEND:-}"
if [ -z "$RAYLIB_BACKEND" ]; then
RAYLIB_BACKEND="desktop"
if [ -f /AGNOS ] || [ -f /TICI ]; then
RAYLIB_BACKEND="comma"
fi
fi

case "$RAYLIB_BACKEND" in
desktop|comma) ;;
*)
echo "Unsupported RAYLIB_BACKEND=$RAYLIB_BACKEND; expected desktop or comma" >&2
exit 1
;;
esac

# Clone and build raylib C library
RAYLIB_COMMIT="d9d7cc1353ec0f73c97e84ddf0973983d1ee25e2"
RAYLIB_COMMIT="dff603f4f122163900469e73d113deacd9ec9817"

if [ ! -d "raylib-src/.git" ]; then
rm -rf raylib-src
git clone --depth 1 -b platform-offscreen --no-tags https://github.com/commaai/raylib.git raylib-src
git clone --depth 1 -b master --no-tags https://github.com/commaai/raylib.git raylib-src
fi

cd raylib-src
git remote set-url origin https://github.com/commaai/raylib.git
git fetch --depth 1 origin "$RAYLIB_COMMIT"
git reset --hard "$RAYLIB_COMMIT"

cd src
make clean
make -j"$NJOBS" PLATFORM="$RAYLIB_PLATFORM" CC="${CC:-gcc}"

cd "$DIR"

# Install lib + headers
rm -rf "$INSTALL_DIR"
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
build_raylib() {
local platform="$1"
local output="$2"

cd raylib-src/src
cd "$DIR/raylib-src/src"
make clean
make -j"$NJOBS" PLATFORM=PLATFORM_OFFSCREEN CC="${CC:-gcc}"
cp libraylib.a "$INSTALL_DIR/lib/libraylib_offscreen.a"
make -j"$NJOBS" PLATFORM="$platform" CC="${CC:-gcc}"
cp libraylib.a "$INSTALL_DIR/lib/$output"
cd "$DIR"
}

if is_linux_aarch64; then
echo "Building desktop backend..."
build_raylib PLATFORM_DESKTOP libraylib_desktop.a

# 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
echo "Building comma backend..."
build_raylib PLATFORM_COMMA libraylib_comma.a
else
if [ "$RAYLIB_BACKEND" = "comma" ]; then
build_raylib PLATFORM_COMMA libraylib_comma.a
else
build_raylib PLATFORM_DESKTOP libraylib_desktop.a
fi
fi

# Download raygui header
RAYGUI_COMMIT="76b36b597edb70ffaf96f046076adc20d67e7827"
RAYGUI_COMMIT="1e03efca48c50c5ea4b4a053d5bf04bad58d3e43"
curl -fsSLo "$INSTALL_DIR/include/raygui.h" \
"https://raw.githubusercontent.com/raysan5/raygui/$RAYGUI_COMMIT/src/raygui.h"

Expand Down
109 changes: 109 additions & 0 deletions raylib/build_cffi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Based on commaai/raylib-python-cffi (commit a32e910)
# Modified to use local install paths and compile standalone.

import os
import platform
import re
import subprocess
import sys

from cffi import FFI

ROOT = os.path.dirname(os.path.abspath(__file__))
PACKAGE_DIR = os.path.join(ROOT, "raylib")
RAYLIB_INCLUDE_PATH = os.path.join(PACKAGE_DIR, "install", "include")
RAYLIB_LIB_PATH = os.path.join(PACKAGE_DIR, "install", "lib")

sys.path.insert(0, PACKAGE_DIR)
from _backend import BACKEND_ARCHIVES, BACKEND_CFFI_MODULES, BACKEND_LINK_ARGS, detect_backend # noqa: E402
from validate_bindings import validate_static_bindings # noqa: E402

RAYLIB_BACKEND = detect_backend()
RAYLIB_CFFI_MODULE = os.getenv("RAYLIB_CFFI_MODULE", f"raylib.{BACKEND_CFFI_MODULES[RAYLIB_BACKEND]}")

ffibuilder = FFI()


def _raylib_archive():
archive = os.path.join(RAYLIB_LIB_PATH, BACKEND_ARCHIVES[RAYLIB_BACKEND])
if not os.path.isfile(archive):
raise FileNotFoundError(f"{archive} not found. Please run build.sh first.")
return archive


def pre_process_header(filename, remove_function_bodies=False):
print("Pre-processing " + filename)
with open(filename, "r") as f:
filetext = "".join([line for line in f if '#include' not in line])
command = ['gcc', '-CC', '-P', '-undef', '-nostdinc', '-DRL_MATRIX_TYPE',
'-DRL_QUATERNION_TYPE', '-DRL_VECTOR4_TYPE', '-DRL_VECTOR3_TYPE', '-DRL_VECTOR2_TYPE',
'-DRLAPI=', '-DPHYSACDEF=', '-DRAYGUIDEF=', '-DRMAPI=',
'-dDI', '-E', '-']
filetext = subprocess.run(command, text=True, input=filetext, stdout=subprocess.PIPE, check=True).stdout
filetext = filetext.replace("va_list", "void *")
if remove_function_bodies:
filetext = re.sub('\n{\n(.|\n)*?\n}\n', ';', filetext)
return "\n".join([line for line in filetext.splitlines() if not line.startswith("#")])


def build_ffi():
raylib_archive = _raylib_archive()

raylib_h = os.path.join(RAYLIB_INCLUDE_PATH, "raylib.h")
rlgl_h = os.path.join(RAYLIB_INCLUDE_PATH, "rlgl.h")
raymath_h = os.path.join(RAYLIB_INCLUDE_PATH, "raymath.h")
raygui_h = os.path.join(RAYLIB_INCLUDE_PATH, "raygui.h")

for header in (raylib_h, rlgl_h, raymath_h, raygui_h):
if not os.path.isfile(header):
raise FileNotFoundError(f"{header} not found. Please run build.sh first.")

ffi_includes = """
#include "raylib.h"
#include "rlgl.h"
#include "raymath.h"
#define RAYGUI_IMPLEMENTATION
#define RAYGUI_SUPPORT_RICONS
#include "raygui.h"
"""

ffibuilder.cdef(pre_process_header(raylib_h))
ffibuilder.cdef(pre_process_header(rlgl_h))
ffibuilder.cdef(pre_process_header(raymath_h, True))
ffibuilder.cdef(pre_process_header(raygui_h))

validate_static_bindings(PACKAGE_DIR, RAYLIB_INCLUDE_PATH)

if platform.system() == "Darwin":
print("BUILDING FOR MAC")
extra_link_args = [
raylib_archive,
'-framework', 'OpenGL',
'-framework', 'Cocoa',
'-framework', 'IOKit',
'-framework', 'CoreFoundation',
'-framework', 'CoreVideo',
]
extra_compile_args = ["-Wno-error=incompatible-function-pointer-types"]
else:
print("BUILDING FOR LINUX")
extra_link_args = [
raylib_archive,
'-lm', '-lpthread', '-lrt', '-ldl', '-latomic',
*BACKEND_LINK_ARGS[RAYLIB_BACKEND],
]
extra_compile_args = ["-Wno-incompatible-pointer-types"]

print("extra_link_args: " + str(extra_link_args))
ffibuilder.set_source(RAYLIB_CFFI_MODULE,
ffi_includes,
py_limited_api=True,
include_dirs=[RAYLIB_INCLUDE_PATH],
extra_link_args=extra_link_args,
extra_compile_args=extra_compile_args,
libraries=[])


if __name__ == "__main__":
build_ffi()
ffibuilder.compile(verbose=True, tmpdir=ROOT)
12 changes: 8 additions & 4 deletions raylib/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
[build-system]
requires = ["setuptools>=64", "wheel", "cffi>=1.17.1"]
requires = ["setuptools>=70.1", "cffi>=1.17.1"]
build-backend = "setuptools.build_meta"

[project]
name = "raylib"
version = "5.5.0.8"
version = "6.0.0.0"
description = "raylib + pyray Python bindings (commaai fork)"
requires-python = ">=3.8"
dependencies = ["cffi>=1.17.1"]

[tool.setuptools]
include-package-data = false

[tool.setuptools.packages.find]
include = ["raylib*", "pyray*"]
include = ["raylib", "pyray"]
namespaces = false

[tool.setuptools.package-data]
raylib = ["install/**/*", "_raylib_cffi*.so"]
raylib = ["_raylib_cffi*.so", "install/include/*.h", "install/lib/*.a"]
Loading
Loading