@@ -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" )
@@ -355,6 +355,10 @@ fn main() {
355355
356356 if cfg ! ( feature = "cuda" ) {
357357 config. define ( "GGML_CUDA" , "ON" ) ;
358+
359+ if cfg ! ( feature = "cuda-no-vmm" ) {
360+ config. define ( "GGML_CUDA_NO_VMM" , "ON" ) ;
361+ }
358362 }
359363
360364 // Android doesn't have OpenMP support AFAICT and openmp is a default feature. Do this here
@@ -394,6 +398,31 @@ fn main() {
394398 ) ;
395399 println ! ( "cargo:rustc-link-search={}" , build_dir. display( ) ) ;
396400
401+ if cfg ! ( feature = "cuda" ) && !build_shared_libs {
402+ println ! ( "cargo:rerun-if-env-changed=CUDA_PATH" ) ;
403+
404+ for lib_dir in find_cuda_helper:: find_cuda_lib_dirs ( ) {
405+ println ! ( "cargo:rustc-link-search=native={}" , lib_dir. display( ) ) ;
406+ }
407+
408+ // Logic from ggml-cuda/CMakeLists.txt
409+ println ! ( "cargo:rustc-link-lib=static=cudart_static" ) ;
410+ if matches ! ( target_os, TargetOs :: Windows ( _) ) {
411+ println ! ( "cargo:rustc-link-lib=static=cublas" ) ;
412+ println ! ( "cargo:rustc-link-lib=static=cublasLt" ) ;
413+ } else {
414+ println ! ( "cargo:rustc-link-lib=static=cublas_static" ) ;
415+ println ! ( "cargo:rustc-link-lib=static=cublasLt_static" ) ;
416+ }
417+
418+ // Need to link against libcuda.so unless GGML_CUDA_NO_VMM is defined.
419+ if !cfg ! ( feature = "cuda-no-vmm" ) {
420+ println ! ( "cargo:rustc-link-lib=cuda" ) ;
421+ }
422+
423+ println ! ( "cargo:rustc-link-lib=static=culibos" ) ;
424+ }
425+
397426 // Link libraries
398427 let llama_libs_kind = if build_shared_libs { "dylib" } else { "static" } ;
399428 let llama_libs = extract_lib_names ( & out_dir, build_shared_libs) ;
0 commit comments