@@ -179,7 +179,7 @@ fn main() {
179179 let target_dir = get_cargo_target_dir ( ) . unwrap ( ) ;
180180 let manifest_dir = env:: var ( "CARGO_MANIFEST_DIR" ) . expect ( "Failed to get CARGO_MANIFEST_DIR" ) ;
181181 let llama_src = Path :: new ( & manifest_dir) . join ( "llama.cpp" ) ;
182- let build_shared_libs = cfg ! ( feature = "cuda" ) || cfg ! ( feature = " dynamic-link") ;
182+ let build_shared_libs = cfg ! ( feature = "dynamic-link" ) ;
183183
184184 let build_shared_libs = std:: env:: var ( "LLAMA_BUILD_SHARED_LIBS" )
185185 . map ( |v| v == "1" )
@@ -352,6 +352,10 @@ fn main() {
352352
353353 if cfg ! ( feature = "cuda" ) {
354354 config. define ( "GGML_CUDA" , "ON" ) ;
355+
356+ if cfg ! ( feature = "cuda-no-vmm" ) {
357+ config. define ( "GGML_CUDA_NO_VMM" , "ON" ) ;
358+ }
355359 }
356360
357361 // Android doesn't have OpenMP support AFAICT and openmp is a default feature. Do this here
@@ -391,6 +395,31 @@ fn main() {
391395 ) ;
392396 println ! ( "cargo:rustc-link-search={}" , build_dir. display( ) ) ;
393397
398+ if cfg ! ( feature = "cuda" ) && !build_shared_libs {
399+ println ! ( "cargo:rerun-if-env-changed=CUDA_PATH" ) ;
400+
401+ for lib_dir in find_cuda_helper:: find_cuda_lib_dirs ( ) {
402+ println ! ( "cargo:rustc-link-search=native={}" , lib_dir. display( ) ) ;
403+ }
404+
405+ // Logic from ggml-cuda/CMakeLists.txt
406+ println ! ( "cargo:rustc-link-lib=static=cudart_static" ) ;
407+ if matches ! ( target_os, TargetOs :: Windows ( _) ) {
408+ println ! ( "cargo:rustc-link-lib=static=cublas" ) ;
409+ println ! ( "cargo:rustc-link-lib=static=cublasLt" ) ;
410+ } else {
411+ println ! ( "cargo:rustc-link-lib=static=cublas_static" ) ;
412+ println ! ( "cargo:rustc-link-lib=static=cublasLt_static" ) ;
413+ }
414+
415+ // Need to link against libcuda.so unless GGML_CUDA_NO_VMM is defined.
416+ if !cfg ! ( feature = "cuda-no-vmm" ) {
417+ println ! ( "cargo:rustc-link-lib=cuda" ) ;
418+ }
419+
420+ println ! ( "cargo:rustc-link-lib=static=culibos" ) ;
421+ }
422+
394423 // Link libraries
395424 let llama_libs_kind = if build_shared_libs { "dylib" } else { "static" } ;
396425 let llama_libs = extract_lib_names ( & out_dir, build_shared_libs) ;
0 commit comments