diff --git a/proj-sys/Cargo.toml b/proj-sys/Cargo.toml index 8c90b986..b6ef3a02 100644 --- a/proj-sys/Cargo.toml +++ b/proj-sys/Cargo.toml @@ -12,6 +12,8 @@ links = "proj" rust-version = "1.70" [dependencies] +libsqlite3-sys = "0.28" +link-cplusplus = "1.0" [build-dependencies] bindgen = "0.68.1" diff --git a/proj-sys/build.rs b/proj-sys/build.rs index 7f2838d4..9473527b 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.4.0.tar.gz"; let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); let tar_gz = File::open(path)?; @@ -99,6 +99,20 @@ fn build_from_source() -> Result> config.define("BUILD_PROJSYNC", "OFF"); config.define("ENABLE_CURL", "OFF"); + // we check here whether or not these variables are set by cargo + // if they are set, `libsqlite3-sys` was built with the bundled feature + // enabled, which in turn allows us to rely on the built libsqlite3 version + // and link it statically + // + // If these are not set, it's necessary that libsqlite3 exists on the build system + // in a location accessible by cmake + if let Ok(sqlite_include) = std::env::var("DEP_SQLITE3_INCLUDE") { + config.define("SQLITE3_INCLUDE_DIR", sqlite_include); + } + if let Ok(sqlite_lib_dir) = std::env::var("DEP_SQLITE3_LIB_DIR") { + config.define("SQLITE3_LIBRARY", format!("{sqlite_lib_dir}/libsqlite3.a",)); + } + if cfg!(feature = "tiff") { eprintln!("enabling tiff support"); config.define("ENABLE_TIFF", "ON"); @@ -132,9 +146,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 +170,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 b020e342..052b7feb 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"));