Skip to content

Commit

Permalink
Depend on libsqlite3-sys for bundled builds
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
weiznich committed Feb 12, 2024
1 parent ae91aba commit 9a6b47d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 2 additions & 0 deletions proj-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 9 additions & 12 deletions proj-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// returns the path of "include" for the built proj
fn build_from_source() -> Result<std::path::PathBuf, Box<dyn std::error::Error>> {
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!(
Expand All @@ -80,7 +81,6 @@ fn build_from_source() -> Result<std::path::PathBuf, Box<dyn std::error::Error>>
}
}

// 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)?;
Expand All @@ -98,6 +98,14 @@ fn build_from_source() -> Result<std::path::PathBuf, Box<dyn std::error::Error>>
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");
Expand Down Expand Up @@ -132,9 +140,6 @@ fn build_from_source() -> Result<std::path::PathBuf, Box<dyn std::error::Error>>
&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
Expand All @@ -159,13 +164,5 @@ fn build_from_source() -> Result<std::path::PathBuf, Box<dyn std::error::Error>>
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"))
}
5 changes: 5 additions & 0 deletions proj-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down

0 comments on commit 9a6b47d

Please sign in to comment.