Skip to content

Commit 7ba911b

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 ef1432f commit 7ba911b

File tree

3 files changed

+15
-0
lines changed

3 files changed

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

+13
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,6 +153,7 @@ 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");
@@ -161,10 +163,21 @@ mod build_bundled {
161163
Ok(v) => v != "false" && v != "0",
162164
Err(_) => false,
163165
};
166+
164167
if !is_debug {
165168
cfg.define("NDEBUG", None);
166169
}
167170

171+
// The Android NDK doesn't build with this flag set.
172+
if env::var("CARGO_CFG_TARGET_OS").unwrap() != "android" {
173+
cfg.flag_if_supported("-stdlib=libstdc++");
174+
}
175+
176+
#[cfg(feature = "bundled-android-static-libstdcpp")]
177+
if env::var("CARGO_CFG_TARGET_OS").unwrap() == "android" {
178+
cfg.flag_if_supported("-static-libstdc++");
179+
}
180+
168181
if win_target() {
169182
cfg.define("DUCKDB_BUILD_LIBRARY", None);
170183
}

0 commit comments

Comments
 (0)