fish-cpp: symlink libcuda.so stub into /usr/local/lib (CMAKE_LIBRARY_PATH alone didn't work)

Second attempt's CMAKE_LIBRARY_PATH + LIBRARY_PATH didn't get picked
up by ggml's nested CMake — same linker errors as the first run.

Robust fix: symlink the stub at /usr/local/cuda/lib64/stubs/libcuda.so
into /usr/local/lib (which ld searches unconditionally) and provide
both libcuda.so AND libcuda.so.1 (the SONAME ggml-cuda's
libggml-cuda.so links against). ldconfig refreshes the cache.

The symlinks live only in the build stage. The runtime image inherits
the real driver-provided libcuda.so.1 via NVIDIA's container runtime
mount, so the stubs never get used at execution time.
This commit is contained in:
vh
2026-04-28 01:20:01 -07:00
parent ee35fcd0a9
commit dd571a3529
+11 -7
View File
@@ -27,14 +27,18 @@ RUN git clone --recurse-submodules https://github.com/rodrigomatta/s2.cpp.git \
WORKDIR /src/s2.cpp
# CUDA Driver API symbols (cuMemSetAccess, cuDeviceGet, etc.) live in
# libcuda.so which the NVIDIA driver provides at RUNTIME via --gpus
# mount. At build time there's no GPU, so we use the stubs library
# at /usr/local/cuda/lib64/stubs/ which provides the symbols for
# linking but is NOT runnable. The runtime image uses the real
# driver-provided libcuda.so via NVIDIA's container runtime.
ENV LIBRARY_PATH=/usr/local/cuda/lib64/stubs:${LIBRARY_PATH}
# libcuda.so which the NVIDIA driver provides at RUNTIME. Build-time
# uses the stubs library at /usr/local/cuda/lib64/stubs/. CMake's
# find_library doesn't reliably pick it up via CMAKE_LIBRARY_PATH for
# nested ggml-cuda builds — the most robust fix is symlinking the stub
# into /usr/local/lib (which ld checks unconditionally) AND providing
# libcuda.so.1 (the SONAME ggml-cuda links against). The symlinks live
# only in this build stage; the runtime image gets the real driver-
# provided libcuda.so.1 via NVIDIA's container runtime.
RUN ln -s /usr/local/cuda/lib64/stubs/libcuda.so /usr/local/lib/libcuda.so \
&& ln -s /usr/local/cuda/lib64/stubs/libcuda.so /usr/local/lib/libcuda.so.1 \
&& ldconfig
RUN cmake -G Ninja -B build -DCMAKE_BUILD_TYPE=Release -DS2_CUDA=ON \
-DCMAKE_LIBRARY_PATH=/usr/local/cuda/lib64/stubs \
&& cmake --build build --parallel $(nproc) --target s2
# ── Stage 2: runtime — slim image with the binary + python shim ────────