Skip to content

Commit a3d975b

Browse files
update to raylib 6.0 (#80)
* update to raylib 6.0 * rm offscreen * dual backend * clean that up * cleanup * lil more * fix macOS * fix raylib wheel smoke tests and dev files * limit smoke test bootstrap deps * cleanup:
1 parent 35376e5 commit a3d975b

14 files changed

Lines changed: 420 additions & 330 deletions

build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ echo
6868
echo "Running smoketests"
6969

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

7374
for toml in */pyproject.toml; do

raylib/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
raylib-src/
22
raylib/install/
3-
raylib/*.modified
43
raylib/_raylib_cffi*

raylib/build.sh

Lines changed: 50 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,91 @@
11
#!/usr/bin/env bash
2-
set -e
2+
set -euo pipefail
33

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

77
INSTALL_DIR="$DIR/raylib/install"
88

99
NJOBS="$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)"
10-
CC="ccache ${CC:-cc}"
10+
if command -v ccache &>/dev/null; then
11+
CC="ccache ${CC:-cc}"
12+
else
13+
CC="${CC:-cc}"
14+
fi
15+
16+
is_linux_aarch64() {
17+
[[ "$(uname)" == "Linux" && ( "$(uname -m)" == "aarch64" || "$(uname -m)" == "arm64" ) ]]
18+
}
1119

12-
# Detect platform: PLATFORM_COMMA for comma devices, PLATFORM_DESKTOP otherwise
13-
RAYLIB_PLATFORM="${RAYLIB_PLATFORM:-PLATFORM_DESKTOP}"
14-
if [ -f /TICI ]; then
15-
RAYLIB_PLATFORM="PLATFORM_COMMA"
20+
if [ -n "${RAYLIB_PLATFORM:-}" ]; then
21+
echo "RAYLIB_PLATFORM is no longer supported; use RAYLIB_BACKEND=desktop or RAYLIB_BACKEND=comma" >&2
22+
exit 1
1623
fi
17-
export RAYLIB_PLATFORM
18-
19-
# Install build dependencies
20-
if [[ "$(uname)" == "Linux" ]]; then
21-
if [ "$RAYLIB_PLATFORM" = "PLATFORM_COMMA" ]; then
22-
# comma device: needs DRM/EGL/GLES headers (usually already present on AGNOS)
23-
# apt may fail on devices due to read-only rootfs or package conflicts — that's OK
24-
if command -v apt-get &>/dev/null; then
25-
if [ "$(id -u)" -eq 0 ]; then
26-
apt-get update && apt-get install -y libdrm-dev libgbm-dev libgles2-mesa-dev libegl1-mesa-dev || true
27-
else
28-
sudo apt-get update && sudo apt-get install -y libdrm-dev libgbm-dev libgles2-mesa-dev libegl1-mesa-dev || true
29-
fi
30-
fi
31-
elif [ "$RAYLIB_PLATFORM" = "PLATFORM_OFFSCREEN" ]; then
32-
# offscreen (CI): needs EGL/GL dev packages (no X11)
33-
if command -v apt-get &>/dev/null; then
34-
if [ "$(id -u)" -eq 0 ]; then
35-
apt-get update && apt-get install -y libegl-dev libgl-dev
36-
else
37-
sudo apt-get update && sudo apt-get install -y libegl-dev libgl-dev
38-
fi
39-
fi
40-
else
41-
# desktop: needs X11/GL dev packages
42-
if command -v dnf &>/dev/null; then
43-
dnf install -y libX11-devel libXcursor-devel libXrandr-devel libXinerama-devel libXi-devel mesa-libGL-devel
44-
elif command -v apt-get &>/dev/null; then
45-
if [ "$(id -u)" -eq 0 ]; then
46-
apt-get update && apt-get install -y libxcursor-dev libxi-dev libxinerama-dev libxrandr-dev libgl-dev
47-
else
48-
sudo apt-get update && sudo apt-get install -y libxcursor-dev libxi-dev libxinerama-dev libxrandr-dev libgl-dev
49-
fi
50-
fi
24+
25+
RAYLIB_BACKEND="${RAYLIB_BACKEND:-}"
26+
if [ -z "$RAYLIB_BACKEND" ]; then
27+
RAYLIB_BACKEND="desktop"
28+
if [ -f /AGNOS ] || [ -f /TICI ]; then
29+
RAYLIB_BACKEND="comma"
5130
fi
5231
fi
5332

33+
case "$RAYLIB_BACKEND" in
34+
desktop|comma) ;;
35+
*)
36+
echo "Unsupported RAYLIB_BACKEND=$RAYLIB_BACKEND; expected desktop or comma" >&2
37+
exit 1
38+
;;
39+
esac
40+
5441
# Clone and build raylib C library
55-
RAYLIB_COMMIT="d9d7cc1353ec0f73c97e84ddf0973983d1ee25e2"
42+
RAYLIB_COMMIT="dff603f4f122163900469e73d113deacd9ec9817"
5643

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

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

66-
cd src
67-
make clean
68-
make -j"$NJOBS" PLATFORM="$RAYLIB_PLATFORM" CC="${CC:-gcc}"
69-
7054
cd "$DIR"
7155

7256
# Install lib + headers
7357
rm -rf "$INSTALL_DIR"
7458
mkdir -p "$INSTALL_DIR"/{lib,include}
7559

76-
cp raylib-src/src/libraylib.a "$INSTALL_DIR/lib/"
7760
cp raylib-src/src/raylib.h raylib-src/src/raymath.h raylib-src/src/rlgl.h "$INSTALL_DIR/include/"
7861

79-
# On x86_64 Linux, also build the offscreen variant for CI headless rendering
80-
if [[ "$(uname)" == "Linux" && "$(uname -m)" == "x86_64" && "$RAYLIB_PLATFORM" != "PLATFORM_OFFSCREEN" ]]; then
81-
echo "Building offscreen variant..."
82-
83-
# Install EGL/GL dev packages needed for offscreen build + bundling
84-
if command -v dnf &>/dev/null; then
85-
dnf install -y mesa-libEGL-devel mesa-libGL-devel libglvnd-opengl libglvnd-core-devel 2>/dev/null || true
86-
elif command -v apt-get &>/dev/null; then
87-
if [ "$(id -u)" -eq 0 ]; then
88-
apt-get update && apt-get install -y libegl-dev libgl-dev
89-
else
90-
sudo apt-get update && sudo apt-get install -y libegl-dev libgl-dev
91-
fi
92-
fi
62+
build_raylib() {
63+
local platform="$1"
64+
local output="$2"
9365

94-
cd raylib-src/src
66+
cd "$DIR/raylib-src/src"
9567
make clean
96-
make -j"$NJOBS" PLATFORM=PLATFORM_OFFSCREEN CC="${CC:-gcc}"
97-
cp libraylib.a "$INSTALL_DIR/lib/libraylib_offscreen.a"
68+
make -j"$NJOBS" PLATFORM="$platform" CC="${CC:-gcc}"
69+
cp libraylib.a "$INSTALL_DIR/lib/$output"
9870
cd "$DIR"
71+
}
72+
73+
if is_linux_aarch64; then
74+
echo "Building desktop backend..."
75+
build_raylib PLATFORM_DESKTOP libraylib_desktop.a
9976

100-
# Bundle GLVND dispatchers so offscreen rendering works without extra system packages
101-
MESA_DIR="$INSTALL_DIR/lib/mesa"
102-
mkdir -p "$MESA_DIR"
103-
ldconfig 2>/dev/null || true
104-
for lib in libEGL.so.1 libOpenGL.so.0 libGLdispatch.so.0; do
105-
src="$(ldconfig -p 2>/dev/null | grep "$lib" | grep -E 'x86.64|libc6,' | awk '{print $NF}' | head -1)"
106-
if [ -n "$src" ] && [ -f "$src" ]; then
107-
cp -L "$src" "$MESA_DIR/"
108-
# Create unversioned symlink for the linker
109-
base="${lib%%.so.*}"
110-
ln -sf "$lib" "$MESA_DIR/${base}.so"
111-
fi
112-
done
77+
echo "Building comma backend..."
78+
build_raylib PLATFORM_COMMA libraylib_comma.a
79+
else
80+
if [ "$RAYLIB_BACKEND" = "comma" ]; then
81+
build_raylib PLATFORM_COMMA libraylib_comma.a
82+
else
83+
build_raylib PLATFORM_DESKTOP libraylib_desktop.a
84+
fi
11385
fi
11486

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

raylib/build_cffi.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Based on commaai/raylib-python-cffi (commit a32e910)
2+
# Modified to use local install paths and compile standalone.
3+
4+
import os
5+
import platform
6+
import re
7+
import subprocess
8+
import sys
9+
10+
from cffi import FFI
11+
12+
ROOT = os.path.dirname(os.path.abspath(__file__))
13+
PACKAGE_DIR = os.path.join(ROOT, "raylib")
14+
RAYLIB_INCLUDE_PATH = os.path.join(PACKAGE_DIR, "install", "include")
15+
RAYLIB_LIB_PATH = os.path.join(PACKAGE_DIR, "install", "lib")
16+
17+
sys.path.insert(0, PACKAGE_DIR)
18+
from _backend import BACKEND_ARCHIVES, BACKEND_CFFI_MODULES, BACKEND_LINK_ARGS, detect_backend # noqa: E402
19+
from validate_bindings import validate_static_bindings # noqa: E402
20+
21+
RAYLIB_BACKEND = detect_backend()
22+
RAYLIB_CFFI_MODULE = os.getenv("RAYLIB_CFFI_MODULE", f"raylib.{BACKEND_CFFI_MODULES[RAYLIB_BACKEND]}")
23+
24+
ffibuilder = FFI()
25+
26+
27+
def _raylib_archive():
28+
archive = os.path.join(RAYLIB_LIB_PATH, BACKEND_ARCHIVES[RAYLIB_BACKEND])
29+
if not os.path.isfile(archive):
30+
raise FileNotFoundError(f"{archive} not found. Please run build.sh first.")
31+
return archive
32+
33+
34+
def pre_process_header(filename, remove_function_bodies=False):
35+
print("Pre-processing " + filename)
36+
with open(filename, "r") as f:
37+
filetext = "".join([line for line in f if '#include' not in line])
38+
command = ['gcc', '-CC', '-P', '-undef', '-nostdinc', '-DRL_MATRIX_TYPE',
39+
'-DRL_QUATERNION_TYPE', '-DRL_VECTOR4_TYPE', '-DRL_VECTOR3_TYPE', '-DRL_VECTOR2_TYPE',
40+
'-DRLAPI=', '-DPHYSACDEF=', '-DRAYGUIDEF=', '-DRMAPI=',
41+
'-dDI', '-E', '-']
42+
filetext = subprocess.run(command, text=True, input=filetext, stdout=subprocess.PIPE, check=True).stdout
43+
filetext = filetext.replace("va_list", "void *")
44+
if remove_function_bodies:
45+
filetext = re.sub('\n{\n(.|\n)*?\n}\n', ';', filetext)
46+
return "\n".join([line for line in filetext.splitlines() if not line.startswith("#")])
47+
48+
49+
def build_ffi():
50+
raylib_archive = _raylib_archive()
51+
52+
raylib_h = os.path.join(RAYLIB_INCLUDE_PATH, "raylib.h")
53+
rlgl_h = os.path.join(RAYLIB_INCLUDE_PATH, "rlgl.h")
54+
raymath_h = os.path.join(RAYLIB_INCLUDE_PATH, "raymath.h")
55+
raygui_h = os.path.join(RAYLIB_INCLUDE_PATH, "raygui.h")
56+
57+
for header in (raylib_h, rlgl_h, raymath_h, raygui_h):
58+
if not os.path.isfile(header):
59+
raise FileNotFoundError(f"{header} not found. Please run build.sh first.")
60+
61+
ffi_includes = """
62+
#include "raylib.h"
63+
#include "rlgl.h"
64+
#include "raymath.h"
65+
#define RAYGUI_IMPLEMENTATION
66+
#define RAYGUI_SUPPORT_RICONS
67+
#include "raygui.h"
68+
"""
69+
70+
ffibuilder.cdef(pre_process_header(raylib_h))
71+
ffibuilder.cdef(pre_process_header(rlgl_h))
72+
ffibuilder.cdef(pre_process_header(raymath_h, True))
73+
ffibuilder.cdef(pre_process_header(raygui_h))
74+
75+
validate_static_bindings(PACKAGE_DIR, RAYLIB_INCLUDE_PATH)
76+
77+
if platform.system() == "Darwin":
78+
print("BUILDING FOR MAC")
79+
extra_link_args = [
80+
raylib_archive,
81+
'-framework', 'OpenGL',
82+
'-framework', 'Cocoa',
83+
'-framework', 'IOKit',
84+
'-framework', 'CoreFoundation',
85+
'-framework', 'CoreVideo',
86+
]
87+
extra_compile_args = ["-Wno-error=incompatible-function-pointer-types"]
88+
else:
89+
print("BUILDING FOR LINUX")
90+
extra_link_args = [
91+
raylib_archive,
92+
'-lm', '-lpthread', '-lrt', '-ldl', '-latomic',
93+
*BACKEND_LINK_ARGS[RAYLIB_BACKEND],
94+
]
95+
extra_compile_args = ["-Wno-incompatible-pointer-types"]
96+
97+
print("extra_link_args: " + str(extra_link_args))
98+
ffibuilder.set_source(RAYLIB_CFFI_MODULE,
99+
ffi_includes,
100+
py_limited_api=True,
101+
include_dirs=[RAYLIB_INCLUDE_PATH],
102+
extra_link_args=extra_link_args,
103+
extra_compile_args=extra_compile_args,
104+
libraries=[])
105+
106+
107+
if __name__ == "__main__":
108+
build_ffi()
109+
ffibuilder.compile(verbose=True, tmpdir=ROOT)

raylib/pyproject.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
[build-system]
2-
requires = ["setuptools>=64", "wheel", "cffi>=1.17.1"]
2+
requires = ["setuptools>=70.1", "cffi>=1.17.1"]
33
build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "raylib"
7-
version = "5.5.0.8"
7+
version = "6.0.0.0"
88
description = "raylib + pyray Python bindings (commaai fork)"
99
requires-python = ">=3.8"
1010
dependencies = ["cffi>=1.17.1"]
1111

12+
[tool.setuptools]
13+
include-package-data = false
14+
1215
[tool.setuptools.packages.find]
13-
include = ["raylib*", "pyray*"]
16+
include = ["raylib", "pyray"]
17+
namespaces = false
1418

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

0 commit comments

Comments
 (0)