@@ -72,6 +72,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
72
72
// returns the path of "include" for the built proj
73
73
fn build_from_source ( ) -> Result < std:: path:: PathBuf , Box < dyn std:: error:: Error > > {
74
74
eprintln ! ( "building libproj from source" ) ;
75
+ println ! ( "cargo:rustc-cfg=bundled_build" ) ;
75
76
if let Ok ( val) = & env:: var ( "_PROJ_SYS_TEST_EXPECT_BUILD_FROM_SRC" ) {
76
77
if val == "0" {
77
78
panic ! (
@@ -80,7 +81,6 @@ fn build_from_source() -> Result<std::path::PathBuf, Box<dyn std::error::Error>>
80
81
}
81
82
}
82
83
83
- // NOTE: The PROJ build expects Sqlite3 to be present on the system.
84
84
let path = "PROJSRC/proj-9.4.0.tar.gz" ;
85
85
let out_path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
86
86
let tar_gz = File :: open ( path) ?;
@@ -99,6 +99,20 @@ fn build_from_source() -> Result<std::path::PathBuf, Box<dyn std::error::Error>>
99
99
config. define ( "BUILD_PROJSYNC" , "OFF" ) ;
100
100
config. define ( "ENABLE_CURL" , "OFF" ) ;
101
101
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
+
102
116
if cfg ! ( feature = "tiff" ) {
103
117
eprintln ! ( "enabling tiff support" ) ;
104
118
config. define ( "ENABLE_TIFF" , "ON" ) ;
@@ -132,9 +146,6 @@ fn build_from_source() -> Result<std::path::PathBuf, Box<dyn std::error::Error>>
132
146
& out_path. join( "build/lib" ) . display( )
133
147
) ;
134
148
135
- // The PROJ library needs SQLite and the C++ standard library.
136
- println ! ( "cargo:rustc-link-lib=dylib=sqlite3" ) ;
137
-
138
149
if cfg ! ( feature = "tiff" ) {
139
150
// On platforms like apples aarch64, users are likely to have installed libtiff with homebrew,
140
151
// 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>>
159
170
println ! ( "cargo:rustc-link-lib=dylib=tiff" ) ;
160
171
}
161
172
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
-
170
173
Ok ( proj. join ( "include" ) )
171
174
}
0 commit comments