Skip to content

Commit 7db4695

Browse files
authored
Merge pull request #1 from magnusuMET/bundled_hdf5-netcdf
Simplify hdf5/netcdf bundling
2 parents 6015440 + c43cd2a commit 7db4695

File tree

3 files changed

+18
-37
lines changed

3 files changed

+18
-37
lines changed

gdal-src/Cargo.toml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ links = "gdal_src"
1010
link-cplusplus = "1.0"
1111
proj-sys = { version = "0.24.0", features = ["bundled_proj"] }
1212
libsqlite3-sys = { version = "0.28.0", features = ["bundled"], optional = true }
13-
hdf5-src = { version = "0.8.1", optional = true, features = ["hl"] }
14-
hdf5-sys = { version = "0.8.1", optional = true, features = ["static"] }
15-
netcdf-src = { version = "0.3.3", optional = true }
13+
hdf5-sys = { package = "hdf5-metno-sys", version = "0.9.1", optional = true, features = ["static", "hl", "deprecated"] }
14+
netcdf-sys = { version = "0.8.1", optional = true, features = ["static"] }
1615
pq-src = { version = "0.1.3", optional = true }
1716
curl-sys = { version = "0.4.70", features = ["static-curl"], optional = true }
1817
libz-sys = { version = "1.1.15", features = ["static"], optional = true }
@@ -56,11 +55,11 @@ all_drivers = [
5655
# that you statically link libgeos and
5756
# therefore makes your binary fall under
5857
# LGPL as well
59-
geos_static = ["geos", "geos-sys/static", "geos-src"]
58+
geos_static = ["geos", "dep:geos-sys", "geos-sys?/static", "dep:geos-src"]
6059
# as long as the `geos_static` feature
6160
# is not enabled that will only
6261
# dynamically link geos
63-
geos = ["geos-sys"]
62+
geos = ["dep:geos-sys"]
6463

6564
internal_drivers = [
6665
# ogr internal,
@@ -310,10 +309,10 @@ driver_pg = ["dep:pq-src"]
310309
driver_postgis_raster = ["driver_pg"]
311310

312311
# libhdf5
313-
driver_hdf5 = ["dep:hdf5-src", "dep:libz-sys"]
312+
driver_hdf5 = ["dep:hdf5-sys", "hdf5-sys?/zlib", "dep:libz-sys"]
314313

315314
# libnetcdf
316-
driver_netcdf = ["dep:netcdf-src", "driver_hdf5", "dep:hdf5-sys"]
315+
driver_netcdf = ["dep:netcdf-sys", "driver_hdf5"]
317316

318317
# poppler
319318
#driver_pdf = []

gdal-src/build.rs

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,14 @@ fn main() {
214214
handle_ogr_driver!(config, "driver_vfk");
215215

216216
if cfg!(feature = "driver_hdf5") {
217-
let hdf5_dir = std::env::var("DEP_HDF5SRC_ROOT").expect("This is set by hdf5-src");
218-
let hdf5_lib = std::env::var("DEP_HDF5SRC_LIBRARY").expect("This is set by hdf5-src");
217+
let hdf5_dir = std::env::var("DEP_HDF5_ROOT").expect("This is set by hdf5-sys");
218+
let hdf5_lib = std::env::var("DEP_HDF5_LIBRARY").expect("This is set by hdf5-sys");
219219
let hdf5_lib_dir = find_library(&hdf5_lib, &hdf5_dir);
220-
let p = PathBuf::from(&hdf5_lib_dir);
221220
let mut hdf5_cc = PathBuf::from(&hdf5_dir);
222221
hdf5_cc.push("bin");
223222
hdf5_cc.push("h5cc");
224-
let mut hdf5_include = PathBuf::from(&hdf5_dir);
225-
hdf5_include.push("include");
226-
let p = p.parent().unwrap();
227-
println!("cargo:rustc-link-search=native={}", p.display());
228-
println!("cargo:rustc-link-lib=static={hdf5_lib}");
223+
let hdf5_include = std::env::var("DEP_HDF5_INCLUDE").expect("This is set by hdf5-sys");
224+
let hdf5_include = PathBuf::from(&hdf5_include);
229225
config
230226
.define("GDAL_USE_HDF5", "ON")
231227
.define("HDF5_C_COMPILER_EXECUTABLE", print_path(&hdf5_cc))
@@ -239,28 +235,14 @@ fn main() {
239235
}
240236

241237
if cfg!(feature = "driver_netcdf") {
242-
let netcdf_root_dir =
243-
std::env::var("DEP_NETCDFSRC_ROOT").expect("This is set by netcdf-src");
244-
let hdf5_dir = std::env::var("DEP_HDF5SRC_ROOT").expect("This is set by hdf5-src");
245-
let hl_library = std::env::var("DEP_HDF5SRC_HL_LIBRARY").expect("This is set by hdf5-src");
246-
let netcdf_lib = find_library("netcdf", &netcdf_root_dir);
247-
let hl_library_path = find_library(&hl_library, hdf5_dir);
248-
let hl_library_path = hl_library_path.parent().unwrap();
238+
let netcdf_include =
239+
std::env::var("DEP_NETCDF_INCLUDEDIR").expect("This is set by netcdf-sys");
240+
let netcdf_root = format!("{netcdf_include}/..");
249241

250-
let netcdf_library_path = netcdf_lib.parent().unwrap();
251-
println!(
252-
"cargo:rustc-link-search=native={}",
253-
netcdf_library_path.display()
254-
);
255-
println!("cargo:rustc-link-lib=static=netcdf");
256-
println!(
257-
"cargo:rustc-link-search=native={}",
258-
hl_library_path.display()
259-
);
260-
println!("cargo:rustc-link-lib=static={hl_library}");
242+
let netcdf_include = PathBuf::from(netcdf_include);
243+
let netcdf_root = PathBuf::from(netcdf_root);
244+
let netcdf_lib = find_library("netcdf", &netcdf_root);
261245

262-
let mut netcdf_include = PathBuf::from(netcdf_root_dir);
263-
netcdf_include.push("include");
264246
config
265247
.define("GDAL_USE_NETCDF", "ON")
266248
.define("NETCDF_INCLUDE_DIR", print_path(&netcdf_include))

gdal-src/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ extern crate curl_sys;
33
#[cfg(feature = "geos")]
44
extern crate geos_sys;
55
#[cfg(feature = "driver_hdf5")]
6-
extern crate hdf5_src;
6+
extern crate hdf5_sys;
77
#[cfg(feature = "driver_sqlite")]
88
extern crate libsqlite3_sys;
99
#[cfg(feature = "driver_netcdf")]
10-
extern crate netcdf_src;
10+
extern crate netcdf_sys;
1111
#[cfg(feature = "driver_pg")]
1212
extern crate pq_src;
1313

0 commit comments

Comments
 (0)