Skip to content

Commit 9a6b47d

Browse files
committed
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.
1 parent ae91aba commit 9a6b47d

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

proj-sys/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ links = "proj"
1212
rust-version = "1.70"
1313

1414
[dependencies]
15+
libsqlite3-sys = { version = "0.28", features = ["bundled"] }
16+
link-cplusplus = "1.0"
1517

1618
[build-dependencies]
1719
bindgen = "0.68.1"

proj-sys/build.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
7272
// returns the path of "include" for the built proj
7373
fn build_from_source() -> Result<std::path::PathBuf, Box<dyn std::error::Error>> {
7474
eprintln!("building libproj from source");
75+
println!("cargo:rustc-cfg=bundled_build");
7576
if let Ok(val) = &env::var("_PROJ_SYS_TEST_EXPECT_BUILD_FROM_SRC") {
7677
if val == "0" {
7778
panic!(
@@ -80,7 +81,6 @@ fn build_from_source() -> Result<std::path::PathBuf, Box<dyn std::error::Error>>
8081
}
8182
}
8283

83-
// NOTE: The PROJ build expects Sqlite3 to be present on the system.
8484
let path = "PROJSRC/proj-9.3.1.tar.gz";
8585
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
8686
let tar_gz = File::open(path)?;
@@ -98,6 +98,14 @@ fn build_from_source() -> Result<std::path::PathBuf, Box<dyn std::error::Error>>
9898
config.define("BUILD_PROJINFO", "OFF");
9999
config.define("BUILD_PROJSYNC", "OFF");
100100
config.define("ENABLE_CURL", "OFF");
101+
config.define(
102+
"SQLITE3_INCLUDE_DIR",
103+
std::env::var("DEP_SQLITE3_INCLUDE").expect("This is set by libsqlite3-sys"),
104+
);
105+
config.define(
106+
"SQLITE3_LIBRARY",
107+
format!("{}/libsqlite3.a", std::env::var("DEP_SQLITE3_LIB_DIR").unwrap()),
108+
);
101109

102110
if cfg!(feature = "tiff") {
103111
eprintln!("enabling tiff support");
@@ -132,9 +140,6 @@ fn build_from_source() -> Result<std::path::PathBuf, Box<dyn std::error::Error>>
132140
&out_path.join("build/lib").display()
133141
);
134142

135-
// The PROJ library needs SQLite and the C++ standard library.
136-
println!("cargo:rustc-link-lib=dylib=sqlite3");
137-
138143
if cfg!(feature = "tiff") {
139144
// On platforms like apples aarch64, users are likely to have installed libtiff with homebrew,
140145
// 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<std::path::PathBuf, Box<dyn std::error::Error>>
159164
println!("cargo:rustc-link-lib=dylib=tiff");
160165
}
161166

162-
if cfg!(target_os = "linux") {
163-
println!("cargo:rustc-link-lib=dylib=stdc++");
164-
} else if cfg!(target_os = "macos") {
165-
println!("cargo:rustc-link-lib=dylib=c++");
166-
} else {
167-
println!("cargo:warning=proj-sys: Not configuring an explicit C++ standard library on this target.");
168-
}
169-
170167
Ok(proj.join("include"))
171168
}

proj-sys/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
//! implement your own set of callbacks if you wish to make use of them (see the
2929
//! [`proj`](https://crates.io/crates/proj) crate for an example).
3030
31+
#[cfg(bundled_build)]
32+
extern crate libsqlite3_sys;
33+
#[cfg(bundled_build)]
34+
extern crate link_cplusplus;
35+
3136
#[cfg(not(feature = "nobuild"))]
3237
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
3338

0 commit comments

Comments
 (0)