fix(build): locate CUDA static libs on distro-packaged toolkits - #687
Open
passabilities wants to merge 1 commit into
Open
fix(build): locate CUDA static libs on distro-packaged toolkits#687passabilities wants to merge 1 commit into
passabilities wants to merge 1 commit into
Conversation
llama-cpp-sys-2 emits `cargo:rustc-link-lib=static=cudart_static` and
delegates library-path discovery to find_cuda_helper, which only probes
$CUDA_LIBRARY_PATH/lib64, /opt/cuda/lib64 and /usr/local/cuda*/lib64.
Distro CUDA packages (e.g. Ubuntu's nvidia-cuda-toolkit) install into
/usr and put the libraries in /usr/lib/<triple>, so none of those paths
exist. rustc then receives the `-l static=` flags with no `-L` path and
the build fails with:
error: could not find native static library `cudart_static`,
perhaps an -L flag is missing?
Probe the common locations before building and export a matching
`-L native=` in RUSTFLAGS. Conventional locations are checked first so
/usr/local/cuda installs keep their existing behaviour, and a missing
libcudart_static.a only warns rather than aborting.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
./build-gpu.shfails on Linux machines that use a distro-packaged CUDA toolkit:The build gets as far as
Detected GPU feature: cudaand then dies while compilingllama-cpp-sys-2.Root cause
llama-cpp-sys-2/build.rsemitscargo:rustc-link-lib=static=cudart_static(pluscublas_static,culibos) and delegates-Lpath discovery tofind_cuda_helper. That crate'sfind_cuda_lib_dirs()only probes$CUDA_LIBRARY_PATH,/opt/cuda/lib64and/usr/local/cuda*/lib64.Distro packages such as Ubuntu's
nvidia-cuda-toolkitinstall into/usr, puttingnvccat/usr/bin/nvccand the libraries in/usr/lib/x86_64-linux-gnu. None of the probed paths exist, so rustc receives the-l static=flags with zero-Lpaths and the link fails.This reproduces in isolation: a two-line crate with
#[link(name = "cudart_static", kind = "static")]fails identically without-L, and succeeds with-L native=/usr/lib/x86_64-linux-gnu.Fix
Both
frontend/build-gpu.shandfrontend/dev-gpu.shnow locate the CUDA static libraries before building and export a matching-L native=intoRUSTFLAGS.The block only runs when
TAURI_GPU_FEATURE = cudaonlinux-gnu, and probes in this order:$CUDA_PATH/lib64$CUDA_HOME/lib64../lib64/usr/local/cuda/lib64/opt/cuda/lib64/usr/lib/$(uname -m)-linux-gnu/usr/lib64The first directory containing
libcudart_static.awins. Conventional locations are checked before the multiarch path, so existing/usr/local/cudaand/opt/cudainstalls keep their current behaviour.RUSTFLAGSis appended to rather than overwritten.If no candidate matches, the script prints a warning pointing at
CUDA_PATHand continues rather than aborting, since the link step may still succeed on setups this heuristic does not cover.Related Issue
No existing issue covers this specific link failure. Related Linux build reports: #305, #587.
Type of Change
Testing
On Ubuntu 24.04 with
nvidia-cuda-toolkit(nvcc 12.0 at/usr/bin/nvcc, no/usr/local/cuda*):llama-cpp-sys-2with the error above..deband.AppImagebundles.lddon the resulting binary confirms CUDA is genuinely linked:libcudart.so.12,libcublas.so.12,libcublasLt.so.12,libcuda.so.1.Shell-script only; no effect on macOS or Windows, or on Linux builds that are not using the
cudafeature.Documentation
Checklist
Screenshots (if applicable)
N/A — build script change only.
Additional Notes
The probe order deliberately prefers the conventional CUDA install locations so that machines with a vendor toolkit under
/usr/local/cudaare unaffected. The multiarch path is only reached when nothing more specific matched.