@@ -72,6 +72,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
7272// returns the path of "include" for the built proj
7373fn 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.4.0.tar.gz" ;
8585 let out_path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
8686 let tar_gz = File :: open ( path) ?;
@@ -99,6 +99,20 @@ fn build_from_source() -> Result<std::path::PathBuf, Box<dyn std::error::Error>>
9999 config. define ( "BUILD_PROJSYNC" , "OFF" ) ;
100100 config. define ( "ENABLE_CURL" , "OFF" ) ;
101101
102+ // we check here whether or not these variables are set by cargo
103+ // if they are set, `libsqlite3-sys` was built with the bundled feature
104+ // enabled, which in turn allows us to rely on the built libsqlite3 version
105+ // and link it statically
106+ //
107+ // If these are not set, it's necessary that libsqlite3 exists on the build system
108+ // in a location accessible by cmake
109+ if let Ok ( sqlite_include) = std:: env:: var ( "DEP_SQLITE3_INCLUDE" ) {
110+ config. define ( "SQLITE3_INCLUDE_DIR" , sqlite_include) ;
111+ }
112+ if let Ok ( sqlite_lib_dir) = std:: env:: var ( "DEP_SQLITE3_LIB_DIR" ) {
113+ config. define ( "SQLITE3_LIBRARY" , format ! ( "{sqlite_lib_dir}/libsqlite3.a" , ) ) ;
114+ }
115+
102116 if cfg ! ( feature = "tiff" ) {
103117 eprintln ! ( "enabling tiff support" ) ;
104118 config. define ( "ENABLE_TIFF" , "ON" ) ;
@@ -132,9 +146,6 @@ fn build_from_source() -> Result<std::path::PathBuf, Box<dyn std::error::Error>>
132146 & out_path. join( "build/lib" ) . display( )
133147 ) ;
134148
135- // The PROJ library needs SQLite and the C++ standard library.
136- println ! ( "cargo:rustc-link-lib=dylib=sqlite3" ) ;
137-
138149 if cfg ! ( feature = "tiff" ) {
139150 // On platforms like apples aarch64, users are likely to have installed libtiff with homebrew,
140151 // 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<std::path::PathBuf, Box<dyn std::error::Error>>
159170 println ! ( "cargo:rustc-link-lib=dylib=tiff" ) ;
160171 }
161172
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-
170173 Ok ( proj. join ( "include" ) )
171174}
0 commit comments