File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -209,6 +209,7 @@ fn main() {
209
209
fn metal_hack ( build : & mut cc:: Build ) {
210
210
const GGML_METAL_METAL_PATH : & str = "llama.cpp/ggml-metal.metal" ;
211
211
const GGML_METAL_PATH : & str = "llama.cpp/ggml-metal.m" ;
212
+ const GGML_COMMON_PATH : & str = "llama.cpp/ggml-common.h" ;
212
213
213
214
let out_dir = PathBuf :: from ( env:: var ( "OUT_DIR" ) . expect ( "OUT_DIR is not defined" ) ) ;
214
215
@@ -220,6 +221,18 @@ fn metal_hack(build: &mut cc::Build) {
220
221
. replace ( '\r' , "\\ r" )
221
222
. replace ( '\"' , "\\ \" " ) ;
222
223
224
+ let ggml_common = std:: fs:: read_to_string ( GGML_COMMON_PATH ) . expect ( "Could not read ggml-common.h" )
225
+ . replace ( '\\' , "\\ \\ " )
226
+ . replace ( '\n' , "\\ n" )
227
+ . replace ( '\r' , "\\ r" )
228
+ . replace ( '\"' , "\\ \" " ) ;
229
+
230
+ let includged_ggml_metal_metal = ggml_metal_metal. replace (
231
+ "#include \\ \" ggml-common.h\\ \" " ,
232
+ & format ! ( "{ggml_common}" )
233
+ ) ;
234
+ print ! ( "{}" , & includged_ggml_metal_metal) ;
235
+
223
236
let ggml_metal =
224
237
std:: fs:: read_to_string ( GGML_METAL_PATH ) . expect ( "Could not read ggml-metal.m" ) ;
225
238
@@ -231,7 +244,7 @@ fn metal_hack(build: &mut cc::Build) {
231
244
// Replace the runtime read of the file with a compile-time string
232
245
let ggml_metal = ggml_metal. replace (
233
246
needle,
234
- & format ! ( r#"NSString * src = @"{ggml_metal_metal }";"# ) ,
247
+ & format ! ( r#"NSString * src = @"{includged_ggml_metal_metal }";"# ) ,
235
248
) ;
236
249
237
250
let patched_ggml_metal_path = out_dir. join ( "ggml-metal.m" ) ;
You can’t perform that action at this time.
0 commit comments