@@ -820,6 +820,18 @@ fn main() {
820820 config. define ( "LLAMA_USE_SYSTEM_GGML" , "ON" ) ;
821821 }
822822
823+ if cfg ! ( feature = "dynamic-backends" ) {
824+ // Pre-create the backends directory so CMake can install MODULE libs there.
825+ // GGML_BACKEND_DIR causes backends to install to this known path instead of
826+ // CMAKE_INSTALL_BINDIR, making them easy to locate in downstream build scripts.
827+ let backends_dir = out_dir. join ( "backends" ) ;
828+ std:: fs:: create_dir_all ( & backends_dir) . unwrap ( ) ;
829+ config. define ( "GGML_BACKEND_DL" , "ON" ) ;
830+ config. define ( "GGML_CPU_ALL_VARIANTS" , "ON" ) ;
831+ config. define ( "GGML_BACKEND_DIR" , backends_dir. to_str ( ) . unwrap ( ) ) ;
832+ // BUILD_SHARED_LIBS=ON is already set above via the dynamic-link feature.
833+ }
834+
823835 // General
824836 config
825837 . profile ( & profile)
@@ -828,6 +840,10 @@ fn main() {
828840
829841 let build_dir = config. build ( ) ;
830842
843+ if cfg ! ( feature = "dynamic-backends" ) {
844+ println ! ( "cargo:backends_dir={}" , out_dir. join( "backends" ) . display( ) ) ;
845+ }
846+
831847 // Build mtmd directly with cc::Build, bypassing the cmake tools build.
832848 // Using LLAMA_BUILD_TOOLS=ON would pull in all tools (batched-bench, quantize, etc.)
833849 // and their CMakeLists.txt files, which are not included in the crate package.
0 commit comments