Skip to content

Commit dd90602

Browse files
committedMar 20, 2025
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 4b511e4 commit dd90602

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
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
vscalar = []

‎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

+12
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

@@ -152,10 +153,21 @@ mod build_bundled {
152153

153154
cfg.cpp(true)
154155
.flag_if_supported("-std=c++11")
156+
.flag_if_supported("-stdlib=libc++")
155157
.flag_if_supported("/bigobj")
156158
.warnings(false)
157159
.flag_if_supported("-w");
158160

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

0 commit comments

Comments
 (0)