Skip to content

Commit

Permalink
Support building on Android
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
ndarilek committed Nov 18, 2024
1 parent 2bd811e commit 8646f01
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/duckdb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ name = "duckdb"
[features]
default = []
bundled = ["libduckdb-sys/bundled"]
bundled-android-static-libstdcpp = ["libduckdb-sys/bundled-android-static-libstdcpp"]
json = ["libduckdb-sys/json", "bundled"]
parquet = ["libduckdb-sys/parquet", "bundled"]
vtab = []
Expand Down
1 change: 1 addition & 0 deletions crates/libduckdb-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ exclude = ["duckdb-sources"]
[features]
default = ["vcpkg", "pkg-config"]
bundled = ["cc"]
bundled-android-static-libstdcpp = ["bundled"]
buildtime_bindgen = ["bindgen", "pkg-config", "vcpkg"]
json = ["bundled"]
parquet = ["bundled"]
Expand Down
12 changes: 11 additions & 1 deletion crates/libduckdb-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fn main() {
mod build_bundled {
use std::{
collections::{HashMap, HashSet},
env,
path::Path,
};

Expand Down Expand Up @@ -151,11 +152,20 @@ mod build_bundled {
cfg.cpp(true)
.flag_if_supported("-std=c++11")
.flag_if_supported("-stdlib=libc++")
.flag_if_supported("-stdlib=libstdc++")
.flag_if_supported("/bigobj")
.warnings(false)
.flag_if_supported("-w");

// The Android NDK doesn't build with this flag set.
if env::var("CARGO_CFG_TARGET_OS").unwrap() != "android" {
cfg.flag_if_supported("-stdlib=libstdc++");
}

#[cfg(feature = "bundled-android-static-libstdcpp")]
if env::var("CARGO_CFG_TARGET_OS").unwrap() == "android" {
cfg.flag_if_supported("-static-libstdc++");
}

if win_target() {
cfg.define("DUCKDB_BUILD_LIBRARY", None);
}
Expand Down

0 comments on commit 8646f01

Please sign in to comment.