Skip to content

Commit 093115e

Browse files
committed
Link against dynamic C++ stdlib on Android by default.
It's a configurable feature that can be disabled if needed, but I got a bunch of linker errors about unavailable C++ symbols from the static c++.a for some reason.
1 parent 73b2e07 commit 093115e

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

llama-cpp-2/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ tracing = { workspace = true }
1818
encoding_rs = { workspace = true }
1919

2020
[features]
21-
default = ["openmp"]
21+
default = ["openmp", "android-shared-stdcxx"]
2222
cuda = ["llama-cpp-sys-2/cuda"]
2323
metal = ["llama-cpp-sys-2/metal"]
2424
dynamic-link = ["llama-cpp-sys-2/dynamic-link"]
2525
vulkan = ["llama-cpp-sys-2/vulkan"]
2626
native = ["llama-cpp-sys-2/native"]
2727
openmp = ["llama-cpp-sys-2/openmp"]
2828
sampler = []
29+
# Only has an impact on Android.
30+
android-shared-stdcxx = ["llama-cpp-sys-2/shared-stdcxx"]
2931

3032

3133
[target.'cfg(all(target_os = "macos", any(target_arch = "aarch64", target_arch = "arm64")))'.dependencies]

llama-cpp-sys-2/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,5 @@ dynamic-link = []
7171
vulkan = []
7272
native = []
7373
openmp = []
74+
# Only has an impact on Android.
75+
shared-stdcxx = []

llama-cpp-sys-2/build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ fn main() {
263263
panic!("Unsupported Android target {target}");
264264
}
265265
config.define("GGML_LLAMAFILE", "OFF");
266+
if cfg!(feature = "shared-stdcxx") {
267+
println!("cargo:rustc-link-lib=dylib=stdc++");
268+
println!("cargo:rustc-link-lib=c++_shared");
269+
}
266270
}
267271

268272
if cfg!(feature = "vulkan") {

0 commit comments

Comments
 (0)