Skip to content

Commit 954f619

Browse files
Insert the header file directly into the string as the linker is not able to find the file
1 parent 0be7b48 commit 954f619

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

llama-cpp-sys-2/build.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ fn main() {
209209
fn metal_hack(build: &mut cc::Build) {
210210
const GGML_METAL_METAL_PATH: &str = "llama.cpp/ggml-metal.metal";
211211
const GGML_METAL_PATH: &str = "llama.cpp/ggml-metal.m";
212+
const GGML_COMMON_PATH: &str = "llama.cpp/ggml-common.h";
212213

213214
let out_dir = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR is not defined"));
214215

@@ -220,6 +221,18 @@ fn metal_hack(build: &mut cc::Build) {
220221
.replace('\r', "\\r")
221222
.replace('\"', "\\\"");
222223

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+
223236
let ggml_metal =
224237
std::fs::read_to_string(GGML_METAL_PATH).expect("Could not read ggml-metal.m");
225238

@@ -231,7 +244,7 @@ fn metal_hack(build: &mut cc::Build) {
231244
// Replace the runtime read of the file with a compile-time string
232245
let ggml_metal = ggml_metal.replace(
233246
needle,
234-
&format!(r#"NSString * src = @"{ggml_metal_metal}";"#),
247+
&format!(r#"NSString * src = @"{includged_ggml_metal_metal}";"#),
235248
);
236249

237250
let patched_ggml_metal_path = out_dir.join("ggml-metal.m");

0 commit comments

Comments
 (0)