Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use feature check options in rust 1.77 #143

Merged
merged 4 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions netcdf-src/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ exclude = [
"source/nctest/**",
"source/ncdap_test/**",
]
rust-version = "1.77.0"

[features]
dap = ["dep:link-cplusplus"]
Expand Down
10 changes: 6 additions & 4 deletions netcdf-src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -89,12 +89,14 @@ fn main() {

let netcdf = netcdf_config.build();

println!("cargo:lib=netcdf");
// 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:search={}", search_path);
println!("cargo::metadata=search={search_path}");
} else {
let search_path = format!("{}/lib64", netcdf.display());
println!("cargo:search={}", search_path);
println!("cargo::metadata=search={search_path}");
}
}
2 changes: 1 addition & 1 deletion netcdf-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ categories = ["external-ffi-bindings", "filesystem", "science"]
exclude = [
"testdata/**",
]
rust-version = "1.70"
rust-version = "1.77.0"

[dependencies]
libz-sys = { version = "1.0.25" }
Expand Down
29 changes: 17 additions & 12 deletions netcdf-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,19 @@ 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(),
"DAP requested but not found in this installation of netCDF"
);
}
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(),
Expand Down Expand Up @@ -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() {
Expand All @@ -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"))
Expand All @@ -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(
Expand All @@ -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),
Expand All @@ -295,6 +296,10 @@ fn main() {
Version::new(4, 9, 2),
];

for version in &versions {
println!("cargo::rustc-check-cfg=cfg(feature, values(\"{version}\"))");
}

if !versions.contains(&metaheader.version) {
if versions
.iter()
Expand Down
8 changes: 4 additions & 4 deletions netcdf-sys/src/mmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -18,21 +18,21 @@ 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,
info: *mut NC_memio,
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;
}
1 change: 1 addition & 0 deletions netcdf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ readme = "../README.md"
categories = ["science", "filesystem"]
exclude = ["examples/**", "tests/**"]
build = "build.rs"
rust-version = "1.77.0"

[features]
default = ["ndarray"]
Expand Down
3 changes: 2 additions & 1 deletion netcdf/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +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_") {
Expand Down
Loading