Skip to content

Commit 0f52002

Browse files
authored
Merge pull request ggml-org#10 from alugha/missing-symbols
Link against C++ standard library and macOS Accelerate framework
2 parents b81c6c9 + 15dbd58 commit 0f52002

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

sys/build.rs

+27
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ use std::env;
44
use std::path::PathBuf;
55

66
fn main() {
7+
let target = env::var("TARGET").unwrap();
8+
// Link C++ standard library
9+
if let Some(cpp_stdlib) = get_cpp_link_stdlib(&target) {
10+
println!("cargo:rustc-link-lib=dylib={}", cpp_stdlib);
11+
}
12+
// Link macOS Accelerate framework for matrix calculations
13+
if target.contains("apple") {
14+
println!("cargo:rustc-link-lib=framework=Accelerate");
15+
}
16+
717
println!("cargo:rustc-link-search={}", env::var("OUT_DIR").unwrap());
818
println!("cargo:rustc-link-lib=static=whisper");
919
println!("cargo:rerun-if-changed=wrapper.h");
@@ -66,3 +76,20 @@ fn main() {
6676
.status()
6777
.expect("Failed to clean whisper build directory");
6878
}
79+
80+
// From https://github.com/alexcrichton/cc-rs/blob/fba7feded71ee4f63cfe885673ead6d7b4f2f454/src/lib.rs#L2462
81+
fn get_cpp_link_stdlib(target: &str) -> Option<&'static str> {
82+
if target.contains("msvc") {
83+
None
84+
} else if target.contains("apple") {
85+
Some("c++")
86+
} else if target.contains("freebsd") {
87+
Some("c++")
88+
} else if target.contains("openbsd") {
89+
Some("c++")
90+
} else if target.contains("android") {
91+
Some("c++_shared")
92+
} else {
93+
Some("stdc++")
94+
}
95+
}

0 commit comments

Comments
 (0)