From 3f7913d2353ff9b9760e272c082be3a470015fcd Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Sun, 5 May 2024 12:26:26 +0200 Subject: [PATCH 1/4] Add expected feature flags --- netcdf-sys/Cargo.toml | 2 +- netcdf-sys/build.rs | 6 ++++++ netcdf-sys/src/mmap.rs | 8 ++++---- netcdf/build.rs | 1 + 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/netcdf-sys/Cargo.toml b/netcdf-sys/Cargo.toml index 0750fc3..351df59 100644 --- a/netcdf-sys/Cargo.toml +++ b/netcdf-sys/Cargo.toml @@ -17,7 +17,7 @@ categories = ["external-ffi-bindings", "filesystem", "science"] exclude = [ "testdata/**", ] -rust-version = "1.70" +rust-version = "1.77" [dependencies] libz-sys = { version = "1.0.25" } diff --git a/netcdf-sys/build.rs b/netcdf-sys/build.rs index 5dc8343..0680b7b 100644 --- a/netcdf-sys/build.rs +++ b/netcdf-sys/build.rs @@ -295,6 +295,12 @@ fn main() { Version::new(4, 9, 2), ]; + for version in &versions { + // println!("cargo::rustc-check-cfg={version}"); + println!("cargo::rustc-check-cfg=cfg(feature, values(\"{version}\"))"); + } + println!("cargo::rustc-check-cfg=cfg(feature, values(\"has-mmap\"))"); + if !versions.contains(&metaheader.version) { if versions .iter() diff --git a/netcdf-sys/src/mmap.rs b/netcdf-sys/src/mmap.rs index b87bd5d..69f6740 100644 --- a/netcdf-sys/src/mmap.rs +++ b/netcdf-sys/src/mmap.rs @@ -2,7 +2,7 @@ use std::os::raw::{c_char, c_int, c_void}; #[repr(C)] #[derive(Copy, Clone)] -#[cfg(feature = "1.6.2")] +#[cfg(feature = "4.6.2")] pub struct NC_memio { size: usize, memory: *mut c_void, @@ -18,14 +18,14 @@ extern "C" { ncidp: *mut c_int, ) -> c_int; - #[cfg(feature = "1.6.2")] + #[cfg(feature = "4.6.2")] pub fn nc_create_mem( path: *const c_char, mode: c_int, initialsize: usize, ncidp: *mut c_int, ) -> c_int; - #[cfg(feature = "1.6.2")] + #[cfg(feature = "4.6.2")] pub fn nc_open_memio( path: *const c_char, mode: c_int, @@ -33,6 +33,6 @@ extern "C" { ncidp: *mut c_int, ) -> c_int; - #[cfg(feature = "1.6.2")] + #[cfg(feature = "4.6.2")] pub fn nc_close_memio(ncid: c_int, info: *mut NC_memio) -> c_int; } diff --git a/netcdf/build.rs b/netcdf/build.rs index 6b0d9be..b61a1bd 100644 --- a/netcdf/build.rs +++ b/netcdf/build.rs @@ -1,4 +1,5 @@ fn main() { + println!("cargo::rustc-check-cfg=cfg(feature, values(\"has-mmap\"))"); if std::env::var("DEP_NETCDF_HAS_MMAP").is_ok() { println!("cargo:rustc-cfg=feature=\"has-mmap\""); } From 84976a41ce559ed3c71d23716226456ded71b73a Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Sun, 5 May 2024 12:44:09 +0200 Subject: [PATCH 2/4] Use cargo:: syntax --- netcdf-src/Cargo.toml | 1 + netcdf-src/build.rs | 10 ++++++---- netcdf-sys/build.rs | 27 +++++++++++++-------------- netcdf/build.rs | 2 +- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/netcdf-src/Cargo.toml b/netcdf-src/Cargo.toml index 8641f66..c3cb72a 100644 --- a/netcdf-src/Cargo.toml +++ b/netcdf-src/Cargo.toml @@ -26,6 +26,7 @@ exclude = [ "source/nctest/**", "source/ncdap_test/**", ] +rust-version = "1.77" [features] dap = ["dep:link-cplusplus"] diff --git a/netcdf-src/build.rs b/netcdf-src/build.rs index c53c331..2d7950c 100644 --- a/netcdf-src/build.rs +++ b/netcdf-src/build.rs @@ -24,7 +24,7 @@ fn get_hdf5_version() -> String { } fn main() { - println!("cargo:rerun-if-changed=build.rs"); + println!("cargo::rerun-if-changed=build.rs"); let hdf5_incdir = std::env::var("DEP_HDF5_INCLUDE").unwrap(); let mut hdf5_lib = std::env::var("DEP_HDF5_LIBRARY").unwrap(); @@ -89,12 +89,14 @@ fn main() { let netcdf = netcdf_config.build(); - println!("cargo:lib=netcdf"); + println!("cargo::metadata=lib=netcdf"); let search_path = format!("{}/lib", netcdf.display()); if std::path::Path::new(&search_path).exists() { - println!("cargo:search={}", search_path); + println!("cargo::metadata=search={search_path}"); + println!("cargo::rustc-link-search={}", search_path); } else { let search_path = format!("{}/lib64", netcdf.display()); - println!("cargo:search={}", search_path); + println!("cargo::metadata=search={search_path}"); + println!("cargo::rustc-link-search={}", search_path); } } diff --git a/netcdf-sys/build.rs b/netcdf-sys/build.rs index 0680b7b..3452e40 100644 --- a/netcdf-sys/build.rs +++ b/netcdf-sys/build.rs @@ -128,9 +128,10 @@ impl NcMetaHeader { } fn emit_feature_flags(&self) { + println!("cargo::rustc-check-cfg=cfg(feature, values(\"has-mmap\",\"has-dap\"))"); if self.has_dap2 || self.has_dap4 { - println!("cargo:rustc-cfg=feature=\"has-dap\""); - println!("cargo:has-dap=1"); + println!("cargo::rustc-cfg=feature=\"has-dap\""); + println!("cargo::metadata=has-dap=1"); } else { assert!( feature!("DAP").is_err(), @@ -138,8 +139,8 @@ impl NcMetaHeader { ); } if self.has_mmap { - println!("cargo:rustc-cfg=feature=\"has-mmap\""); - println!("cargo:has-mmap=1"); + println!("cargo::rustc-cfg=feature=\"has-mmap\""); + println!("cargo::metadata=has-mmap=1"); } else { assert!( feature!("MEMIO").is_err(), @@ -232,7 +233,7 @@ fn _check_consistent_version_linked() { } fn main() { - println!("cargo:rerun-if-changed=build.rs"); + println!("cargo::rerun-if-changed=build.rs"); let info; if feature!("STATIC").is_ok() { @@ -242,10 +243,10 @@ fn main() { info = NcInfo::gather_from_ncconfig(Some(&netcdf_path.join(".."))) .unwrap_or_else(|| NcInfo::from_path(&netcdf_path.join(".."))); - println!("cargo:rustc-link-search=native={}", netcdf_path.display()); - println!("cargo:rustc-link-lib=static={netcdf_lib}"); + println!("cargo::rustc-link-search=native={}", netcdf_path.display()); + println!("cargo::rustc-link-lib=static={netcdf_lib}"); } else { - println!("cargo:rerun-if-env-changed=NETCDF_DIR"); + println!("cargo::rerun-if-env-changed=NETCDF_DIR"); let nc_dir = std::env::var_os("NETCDF_DIR") .or_else(|| std::env::var_os("NetCDF_DIR")) @@ -260,8 +261,8 @@ fn main() { NcInfo::gather_from_ncconfig(None).unwrap_or_else(NcInfo::guess) }; - println!("cargo:rustc-link-search={}", info.libdir.display()); - println!("cargo:rustc-link-lib={}", &info.libname); + println!("cargo::rustc-link-search={}", info.libdir.display()); + println!("cargo::rustc-link-lib={}", &info.libname); } let metaheader = NcMetaHeader::gather_from_includeheader( @@ -273,8 +274,8 @@ fn main() { // panic!("{:?}", info); // Emit nc flags - println!("cargo:includedir={}", info.includedir.display()); - println!("cargo:nc_version={}", metaheader.version); + println!("cargo::metadata=includedir={}", info.includedir.display()); + println!("cargo::metadata=nc_version={}", metaheader.version); let versions = [ Version::new(4, 4, 0), Version::new(4, 4, 1), @@ -296,10 +297,8 @@ fn main() { ]; for version in &versions { - // println!("cargo::rustc-check-cfg={version}"); println!("cargo::rustc-check-cfg=cfg(feature, values(\"{version}\"))"); } - println!("cargo::rustc-check-cfg=cfg(feature, values(\"has-mmap\"))"); if !versions.contains(&metaheader.version) { if versions diff --git a/netcdf/build.rs b/netcdf/build.rs index b61a1bd..f60dc97 100644 --- a/netcdf/build.rs +++ b/netcdf/build.rs @@ -1,7 +1,7 @@ fn main() { println!("cargo::rustc-check-cfg=cfg(feature, values(\"has-mmap\"))"); if std::env::var("DEP_NETCDF_HAS_MMAP").is_ok() { - println!("cargo:rustc-cfg=feature=\"has-mmap\""); + println!("cargo::rustc-cfg=feature=\"has-mmap\""); } for (env, _value) in std::env::vars() { if let Some(version) = env.strip_prefix("DEP_NETCDF_VERSION_") { From ea4f4da471a03f094e36333a6ed6b0ba7d64ea9b Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Sun, 5 May 2024 12:46:38 +0200 Subject: [PATCH 3/4] Small comments --- netcdf-src/build.rs | 4 ++-- netcdf/Cargo.toml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/netcdf-src/build.rs b/netcdf-src/build.rs index 2d7950c..27d49a4 100644 --- a/netcdf-src/build.rs +++ b/netcdf-src/build.rs @@ -89,14 +89,14 @@ fn main() { let netcdf = netcdf_config.build(); + // Only forward link options to netcdf-sys, so netcdf-sys can + // optionally choose not to use this build println!("cargo::metadata=lib=netcdf"); let search_path = format!("{}/lib", netcdf.display()); if std::path::Path::new(&search_path).exists() { println!("cargo::metadata=search={search_path}"); - println!("cargo::rustc-link-search={}", search_path); } else { let search_path = format!("{}/lib64", netcdf.display()); println!("cargo::metadata=search={search_path}"); - println!("cargo::rustc-link-search={}", search_path); } } diff --git a/netcdf/Cargo.toml b/netcdf/Cargo.toml index 62b0021..74bf6d2 100644 --- a/netcdf/Cargo.toml +++ b/netcdf/Cargo.toml @@ -14,6 +14,7 @@ readme = "../README.md" categories = ["science", "filesystem"] exclude = ["examples/**", "tests/**"] build = "build.rs" +rust-version = "1.77" [features] default = ["ndarray"] From 5e328b8f1f5b0ac5d423a3e696f85c2bdcfd83d6 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Sun, 12 May 2024 08:46:43 +0200 Subject: [PATCH 4/4] Specify patch version in rust-version --- netcdf-src/Cargo.toml | 2 +- netcdf-sys/Cargo.toml | 2 +- netcdf/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/netcdf-src/Cargo.toml b/netcdf-src/Cargo.toml index c3cb72a..adae55a 100644 --- a/netcdf-src/Cargo.toml +++ b/netcdf-src/Cargo.toml @@ -26,7 +26,7 @@ exclude = [ "source/nctest/**", "source/ncdap_test/**", ] -rust-version = "1.77" +rust-version = "1.77.0" [features] dap = ["dep:link-cplusplus"] diff --git a/netcdf-sys/Cargo.toml b/netcdf-sys/Cargo.toml index 351df59..4674e7a 100644 --- a/netcdf-sys/Cargo.toml +++ b/netcdf-sys/Cargo.toml @@ -17,7 +17,7 @@ categories = ["external-ffi-bindings", "filesystem", "science"] exclude = [ "testdata/**", ] -rust-version = "1.77" +rust-version = "1.77.0" [dependencies] libz-sys = { version = "1.0.25" } diff --git a/netcdf/Cargo.toml b/netcdf/Cargo.toml index 74bf6d2..96f09ab 100644 --- a/netcdf/Cargo.toml +++ b/netcdf/Cargo.toml @@ -14,7 +14,7 @@ readme = "../README.md" categories = ["science", "filesystem"] exclude = ["examples/**", "tests/**"] build = "build.rs" -rust-version = "1.77" +rust-version = "1.77.0" [features] default = ["ndarray"]