@@ -507,7 +507,7 @@ fn compile_metal(cx: &mut Build, cxx: &mut Build) {
507507 let common = LLAMA_PATH . join ( "ggml-common.h" ) ;
508508
509509 let input_file = File :: open ( ggml_metal_shader_path) . expect ( "Failed to open input file" ) ;
510- let mut output_file =
510+ let output_file =
511511 File :: create ( & ggml_metal_shader_out_path) . expect ( "Failed to create output file" ) ;
512512
513513 let output = Command :: new ( "sed" )
@@ -583,11 +583,35 @@ fn compile_metal(cx: &mut Build, cxx: &mut Build) {
583583 . file ( LLAMA_PATH . join ( "ggml-metal.m" ) ) ;
584584}
585585
586+ fn find_windows_vulkan_sdk ( ) -> PathBuf {
587+ // if the vulkan sdk is installed in the standard location then this should be pretty fast,
588+ // but we still must search recursively because we don't know the exact version number.
589+ // if it's installed somewhere else, this will take a while, but it's better than failing.
590+ let vulkan_root = Command :: new ( "powershell.exe" )
591+ . arg ( "-Command" )
592+ . arg ( r#"
593+ if (test-path -pathtype Container "/VulkanSDK") {
594+ $root = "/VulkanSDK"
595+ } else {
596+ $root = "/"
597+ }
598+ get-childitem -path $root -recurse -filter "vulkan.h" 2>$null | foreach-object { $_.directory.parent.parent.fullname }
599+ "# )
600+ . output ( )
601+ . expect ( "could not find vulkan.h" )
602+ . stdout ;
603+ let vulkan_root = String :: from_utf8_lossy (
604+ vulkan_root
605+ . split ( |c| * c == b'\n' )
606+ . next ( )
607+ . expect ( "could not find vulkan.h" ) ,
608+ ) ;
609+ PathBuf :: from ( vulkan_root. trim ( ) )
610+ }
611+
586612fn compile_vulkan ( cx : & mut Build , cxx : & mut Build ) -> & ' static str {
587613 println ! ( "Compiling Vulkan GGML.." ) ;
588614
589- // Vulkan gets linked through the ash crate.
590-
591615 if cfg ! ( debug_assertions) {
592616 cx. define ( "GGML_VULKAN_DEBUG" , None )
593617 . define ( "GGML_VULKAN_CHECK_RESULTS" , None )
@@ -602,12 +626,25 @@ fn compile_vulkan(cx: &mut Build, cxx: &mut Build) -> &'static str {
602626
603627 let lib_name = "ggml-vulkan" ;
604628
605- cxx. clone ( )
606- . include ( "./thirdparty/Vulkan-Headers/include/" )
607- . include ( LLAMA_PATH . as_path ( ) )
608- . file ( LLAMA_PATH . join ( "ggml-vulkan.cpp" ) )
609- . compile ( lib_name) ;
610-
629+ if cfg ! ( target_os = "windows" ) {
630+ let vulkan_root = find_windows_vulkan_sdk ( ) ;
631+ cxx. clone ( )
632+ . include ( vulkan_root. join ( "Include" ) )
633+ . include ( LLAMA_PATH . as_path ( ) )
634+ . file ( LLAMA_PATH . join ( "ggml-vulkan.cpp" ) )
635+ . compile ( lib_name) ;
636+ println ! (
637+ "cargo:rustc-link-search=native={}" ,
638+ vulkan_root. join( "Lib" ) . display( )
639+ ) ;
640+ println ! ( "cargo:rustc-link-lib=vulkan-1" ) ;
641+ } else {
642+ cxx. clone ( )
643+ . include ( LLAMA_PATH . as_path ( ) )
644+ . file ( LLAMA_PATH . join ( "ggml-vulkan.cpp" ) )
645+ . compile ( lib_name) ;
646+ println ! ( "cargo:rustc-link-lib=vulkan" ) ;
647+ }
611648 lib_name
612649}
613650
@@ -673,6 +710,7 @@ fn main() {
673710 push_warn_flags ( & mut cx, & mut cxx) ;
674711 push_feature_flags ( & mut cx, & mut cxx) ;
675712
713+ #[ allow( unused_variables) ]
676714 let feat_lib = if cfg ! ( feature = "vulkan" ) {
677715 Some ( compile_vulkan ( & mut cx, & mut cxx) )
678716 } else if cfg ! ( feature = "cuda" ) {
0 commit comments