Skip to content

Commit 144d94d

Browse files
author
z.murodov
committed
cv(runtime): enforce software GL (LIBGL_ALWAYS_SOFTWARE, llvmpipe), preload GLX/dispatch chain; debug: add ldd output for libGL; build: add libc-bin
1 parent 6c766fe commit 144d94d

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

nixpacks.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Ensure Python is present for Nixpacks Python phase, plus native deps for OpenCV/MediaPipe
33
nixPkgs = ['python311', 'libGL', 'libglvnd', 'pkg-config', 'glib', 'zlib', 'mesa', 'xorg.libX11', 'xorg.libXext', 'xorg.libXrender']
44
cmds = [
5-
'apt-get update -y && DEBIAN_FRONTEND=noninteractive apt-get install -y libgl1 libglvnd0 libglx-mesa0 libgl1-mesa-dri libopengl0 libegl1 libgles2 libglib2.0-0 libxext6 libxrender1 libxfixes3 libsm6 libxcb1 libxau6 libxdmcp6 libglx0 libx11-6 libx11-xcb1 libxrandr2 libxxf86vm1 libxdamage1 libxshmfence1 libdrm2 libexpat1 libstdc++6 libgcc-s1 && ldconfig'
5+
'apt-get update -y && DEBIAN_FRONTEND=noninteractive apt-get install -y libgl1 libglvnd0 libglx-mesa0 libgl1-mesa-dri libopengl0 libegl1 libgles2 libglib2.0-0 libxext6 libxrender1 libxfixes3 libsm6 libxcb1 libxau6 libxdmcp6 libglx0 libx11-6 libx11-xcb1 libxrandr2 libxxf86vm1 libxdamage1 libxshmfence1 libdrm2 libexpat1 libstdc++6 libgcc-s1 libc-bin && ldconfig'
66
]
77

88
[start]

src/backend/api/system_routes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,13 @@ async def cv_debug():
8888
except OSError as e:
8989
info.setdefault("dlopen_errors", []).append({lib: str(e)})
9090

91+
# If libGL exists, run ldd to see unresolved deps
92+
import subprocess
93+
for p in info.get("libgl_candidates", [])[:1]:
94+
try:
95+
out = subprocess.check_output(["/usr/bin/ldd", p], text=True, stderr=subprocess.STDOUT)
96+
info["ldd_libGL"] = out
97+
except Exception as e:
98+
info["ldd_error"] = str(e)
99+
91100
return info

src/cv/video_processor.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
# Force CPU path for MediaPipe in headless servers (Railway)
99
os.environ.setdefault("MEDIAPIPE_DISABLE_GPU", "1")
10+
os.environ.setdefault("OPENCV_DISABLE_GPU", "1")
11+
os.environ.setdefault("LIBGL_ALWAYS_SOFTWARE", "1")
12+
os.environ.setdefault("MESA_LOADER_DRIVER_OVERRIDE", "llvmpipe")
1013

1114
# Ensure system GL libraries are discoverable at runtime (Railway Ubuntu 24.04)
1215
# Some builds use Nix python which may not see apt-installed libs unless we extend LD_LIBRARY_PATH
@@ -48,6 +51,13 @@
4851

4952
# 2) Fallback to sonames if absolute paths failed
5053
if not _loaded_gl:
54+
# Try preloading GL dispatch/GLX chain first
55+
for _dep in ("/usr/lib/x86_64-linux-gnu/libGLdispatch.so.0", "/usr/lib/x86_64-linux-gnu/libGLX.so.0"):
56+
try:
57+
if os.path.exists(_dep):
58+
ctypes.CDLL(_dep, mode=getattr(ctypes, "RTLD_GLOBAL", 0))
59+
except OSError:
60+
pass
5161
for _lib in ("libGL.so.1", "libGL.so"):
5262
try:
5363
ctypes.CDLL(_lib, mode=getattr(ctypes, "RTLD_GLOBAL", 0))

0 commit comments

Comments
 (0)