Skip to content

Commit 8646f01

Browse files
committed
Support building on Android
* Remove `-stdlib=libstdc++` flag on Android since it breaks the build * Add `bundled-android-static-libstdcpp` feature for selecting the static C++ runtime (I.e. https://developer.android.com/ndk/guides/cpp-support#use_clang_directly)
1 parent 2bd811e commit 8646f01

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

crates/duckdb/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ name = "duckdb"
2020
[features]
2121
default = []
2222
bundled = ["libduckdb-sys/bundled"]
23+
bundled-android-static-libstdcpp = ["libduckdb-sys/bundled-android-static-libstdcpp"]
2324
json = ["libduckdb-sys/json", "bundled"]
2425
parquet = ["libduckdb-sys/parquet", "bundled"]
2526
vtab = []

crates/libduckdb-sys/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ exclude = ["duckdb-sources"]
1818
[features]
1919
default = ["vcpkg", "pkg-config"]
2020
bundled = ["cc"]
21+
bundled-android-static-libstdcpp = ["bundled"]
2122
buildtime_bindgen = ["bindgen", "pkg-config", "vcpkg"]
2223
json = ["bundled"]
2324
parquet = ["bundled"]

crates/libduckdb-sys/build.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fn main() {
3737
mod build_bundled {
3838
use std::{
3939
collections::{HashMap, HashSet},
40+
env,
4041
path::Path,
4142
};
4243

@@ -151,11 +152,20 @@ mod build_bundled {
151152
cfg.cpp(true)
152153
.flag_if_supported("-std=c++11")
153154
.flag_if_supported("-stdlib=libc++")
154-
.flag_if_supported("-stdlib=libstdc++")
155155
.flag_if_supported("/bigobj")
156156
.warnings(false)
157157
.flag_if_supported("-w");
158158

159+
// The Android NDK doesn't build with this flag set.
160+
if env::var("CARGO_CFG_TARGET_OS").unwrap() != "android" {
161+
cfg.flag_if_supported("-stdlib=libstdc++");
162+
}
163+
164+
#[cfg(feature = "bundled-android-static-libstdcpp")]
165+
if env::var("CARGO_CFG_TARGET_OS").unwrap() == "android" {
166+
cfg.flag_if_supported("-static-libstdc++");
167+
}
168+
159169
if win_target() {
160170
cfg.define("DUCKDB_BUILD_LIBRARY", None);
161171
}

0 commit comments

Comments
 (0)