From 9a6b47d70a74ffef0f606731b1ee414668c67f17 Mon Sep 17 00:00:00 2001 From: Georg Semmler Date: Thu, 25 Jan 2024 14:03:10 +0100 Subject: [PATCH] Depend on `libsqlite3-sys` for bundled builds This commit adds an optional dependency to libsqlite3-sys to provide a bundled version of libsqlite3 as well instead of relying on a system provided version. Also use the `link_cplusplus` crate to handling linking libc++ for us. --- proj-sys/Cargo.toml | 2 ++ proj-sys/build.rs | 21 +++++++++------------ proj-sys/src/lib.rs | 5 +++++ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/proj-sys/Cargo.toml b/proj-sys/Cargo.toml index bde1172a..24a59d32 100644 --- a/proj-sys/Cargo.toml +++ b/proj-sys/Cargo.toml @@ -12,6 +12,8 @@ links = "proj" rust-version = "1.70" [dependencies] +libsqlite3-sys = { version = "0.28", features = ["bundled"] } +link-cplusplus = "1.0" [build-dependencies] bindgen = "0.68.1" diff --git a/proj-sys/build.rs b/proj-sys/build.rs index 5bdb739b..d9645f3b 100644 --- a/proj-sys/build.rs +++ b/proj-sys/build.rs @@ -72,6 +72,7 @@ fn main() -> Result<(), Box> { // returns the path of "include" for the built proj fn build_from_source() -> Result> { eprintln!("building libproj from source"); + println!("cargo:rustc-cfg=bundled_build"); if let Ok(val) = &env::var("_PROJ_SYS_TEST_EXPECT_BUILD_FROM_SRC") { if val == "0" { panic!( @@ -80,7 +81,6 @@ fn build_from_source() -> Result> } } - // NOTE: The PROJ build expects Sqlite3 to be present on the system. let path = "PROJSRC/proj-9.3.1.tar.gz"; let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); let tar_gz = File::open(path)?; @@ -98,6 +98,14 @@ fn build_from_source() -> Result> config.define("BUILD_PROJINFO", "OFF"); config.define("BUILD_PROJSYNC", "OFF"); config.define("ENABLE_CURL", "OFF"); + config.define( + "SQLITE3_INCLUDE_DIR", + std::env::var("DEP_SQLITE3_INCLUDE").expect("This is set by libsqlite3-sys"), + ); + config.define( + "SQLITE3_LIBRARY", + format!("{}/libsqlite3.a", std::env::var("DEP_SQLITE3_LIB_DIR").unwrap()), + ); if cfg!(feature = "tiff") { eprintln!("enabling tiff support"); @@ -132,9 +140,6 @@ fn build_from_source() -> Result> &out_path.join("build/lib").display() ); - // The PROJ library needs SQLite and the C++ standard library. - println!("cargo:rustc-link-lib=dylib=sqlite3"); - if cfg!(feature = "tiff") { // On platforms like apples aarch64, users are likely to have installed libtiff with homebrew, // which isn't in the default search path, so try to determine path from pkg-config @@ -159,13 +164,5 @@ fn build_from_source() -> Result> println!("cargo:rustc-link-lib=dylib=tiff"); } - if cfg!(target_os = "linux") { - println!("cargo:rustc-link-lib=dylib=stdc++"); - } else if cfg!(target_os = "macos") { - println!("cargo:rustc-link-lib=dylib=c++"); - } else { - println!("cargo:warning=proj-sys: Not configuring an explicit C++ standard library on this target."); - } - Ok(proj.join("include")) } diff --git a/proj-sys/src/lib.rs b/proj-sys/src/lib.rs index 6f8be7a4..04a6e6eb 100644 --- a/proj-sys/src/lib.rs +++ b/proj-sys/src/lib.rs @@ -28,6 +28,11 @@ //! implement your own set of callbacks if you wish to make use of them (see the //! [`proj`](https://crates.io/crates/proj) crate for an example). +#[cfg(bundled_build)] +extern crate libsqlite3_sys; +#[cfg(bundled_build)] +extern crate link_cplusplus; + #[cfg(not(feature = "nobuild"))] include!(concat!(env!("OUT_DIR"), "/bindings.rs"));