Skip to content

Commit 010b07d

Browse files
authoredJul 29, 2024··
Merge pull request #143 from mulimoen/check-cfg
Use feature check options in rust 1.77
2 parents 52d4361 + 5e328b8 commit 010b07d

File tree

7 files changed

+32
-22
lines changed

7 files changed

+32
-22
lines changed
 

‎netcdf-src/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ exclude = [
2626
"source/nctest/**",
2727
"source/ncdap_test/**",
2828
]
29+
rust-version = "1.77.0"
2930

3031
[features]
3132
dap = ["dep:link-cplusplus"]

‎netcdf-src/build.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn get_hdf5_version() -> String {
2424
}
2525

2626
fn main() {
27-
println!("cargo:rerun-if-changed=build.rs");
27+
println!("cargo::rerun-if-changed=build.rs");
2828

2929
let hdf5_incdir = std::env::var("DEP_HDF5_INCLUDE").unwrap();
3030
let mut hdf5_lib = std::env::var("DEP_HDF5_LIBRARY").unwrap();
@@ -89,12 +89,14 @@ fn main() {
8989

9090
let netcdf = netcdf_config.build();
9191

92-
println!("cargo:lib=netcdf");
92+
// Only forward link options to netcdf-sys, so netcdf-sys can
93+
// optionally choose not to use this build
94+
println!("cargo::metadata=lib=netcdf");
9395
let search_path = format!("{}/lib", netcdf.display());
9496
if std::path::Path::new(&search_path).exists() {
95-
println!("cargo:search={}", search_path);
97+
println!("cargo::metadata=search={search_path}");
9698
} else {
9799
let search_path = format!("{}/lib64", netcdf.display());
98-
println!("cargo:search={}", search_path);
100+
println!("cargo::metadata=search={search_path}");
99101
}
100102
}

‎netcdf-sys/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ categories = ["external-ffi-bindings", "filesystem", "science"]
1717
exclude = [
1818
"testdata/**",
1919
]
20-
rust-version = "1.70"
20+
rust-version = "1.77.0"
2121

2222
[dependencies]
2323
libz-sys = { version = "1.0.25" }

‎netcdf-sys/build.rs

+17-12
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,19 @@ impl NcMetaHeader {
128128
}
129129

130130
fn emit_feature_flags(&self) {
131+
println!("cargo::rustc-check-cfg=cfg(feature, values(\"has-mmap\",\"has-dap\"))");
131132
if self.has_dap2 || self.has_dap4 {
132-
println!("cargo:rustc-cfg=feature=\"has-dap\"");
133-
println!("cargo:has-dap=1");
133+
println!("cargo::rustc-cfg=feature=\"has-dap\"");
134+
println!("cargo::metadata=has-dap=1");
134135
} else {
135136
assert!(
136137
feature!("DAP").is_err(),
137138
"DAP requested but not found in this installation of netCDF"
138139
);
139140
}
140141
if self.has_mmap {
141-
println!("cargo:rustc-cfg=feature=\"has-mmap\"");
142-
println!("cargo:has-mmap=1");
142+
println!("cargo::rustc-cfg=feature=\"has-mmap\"");
143+
println!("cargo::metadata=has-mmap=1");
143144
} else {
144145
assert!(
145146
feature!("MEMIO").is_err(),
@@ -232,7 +233,7 @@ fn _check_consistent_version_linked() {
232233
}
233234

234235
fn main() {
235-
println!("cargo:rerun-if-changed=build.rs");
236+
println!("cargo::rerun-if-changed=build.rs");
236237

237238
let info;
238239
if feature!("STATIC").is_ok() {
@@ -242,10 +243,10 @@ fn main() {
242243
info = NcInfo::gather_from_ncconfig(Some(&netcdf_path.join("..")))
243244
.unwrap_or_else(|| NcInfo::from_path(&netcdf_path.join("..")));
244245

245-
println!("cargo:rustc-link-search=native={}", netcdf_path.display());
246-
println!("cargo:rustc-link-lib=static={netcdf_lib}");
246+
println!("cargo::rustc-link-search=native={}", netcdf_path.display());
247+
println!("cargo::rustc-link-lib=static={netcdf_lib}");
247248
} else {
248-
println!("cargo:rerun-if-env-changed=NETCDF_DIR");
249+
println!("cargo::rerun-if-env-changed=NETCDF_DIR");
249250

250251
let nc_dir = std::env::var_os("NETCDF_DIR")
251252
.or_else(|| std::env::var_os("NetCDF_DIR"))
@@ -260,8 +261,8 @@ fn main() {
260261
NcInfo::gather_from_ncconfig(None).unwrap_or_else(NcInfo::guess)
261262
};
262263

263-
println!("cargo:rustc-link-search={}", info.libdir.display());
264-
println!("cargo:rustc-link-lib={}", &info.libname);
264+
println!("cargo::rustc-link-search={}", info.libdir.display());
265+
println!("cargo::rustc-link-lib={}", &info.libname);
265266
}
266267

267268
let metaheader = NcMetaHeader::gather_from_includeheader(
@@ -273,8 +274,8 @@ fn main() {
273274

274275
// panic!("{:?}", info);
275276
// Emit nc flags
276-
println!("cargo:includedir={}", info.includedir.display());
277-
println!("cargo:nc_version={}", metaheader.version);
277+
println!("cargo::metadata=includedir={}", info.includedir.display());
278+
println!("cargo::metadata=nc_version={}", metaheader.version);
278279
let versions = [
279280
Version::new(4, 4, 0),
280281
Version::new(4, 4, 1),
@@ -295,6 +296,10 @@ fn main() {
295296
Version::new(4, 9, 2),
296297
];
297298

299+
for version in &versions {
300+
println!("cargo::rustc-check-cfg=cfg(feature, values(\"{version}\"))");
301+
}
302+
298303
if !versions.contains(&metaheader.version) {
299304
if versions
300305
.iter()

‎netcdf-sys/src/mmap.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::os::raw::{c_char, c_int, c_void};
22

33
#[repr(C)]
44
#[derive(Copy, Clone)]
5-
#[cfg(feature = "1.6.2")]
5+
#[cfg(feature = "4.6.2")]
66
pub struct NC_memio {
77
size: usize,
88
memory: *mut c_void,
@@ -18,21 +18,21 @@ extern "C" {
1818
ncidp: *mut c_int,
1919
) -> c_int;
2020

21-
#[cfg(feature = "1.6.2")]
21+
#[cfg(feature = "4.6.2")]
2222
pub fn nc_create_mem(
2323
path: *const c_char,
2424
mode: c_int,
2525
initialsize: usize,
2626
ncidp: *mut c_int,
2727
) -> c_int;
28-
#[cfg(feature = "1.6.2")]
28+
#[cfg(feature = "4.6.2")]
2929
pub fn nc_open_memio(
3030
path: *const c_char,
3131
mode: c_int,
3232
info: *mut NC_memio,
3333
ncidp: *mut c_int,
3434
) -> c_int;
3535

36-
#[cfg(feature = "1.6.2")]
36+
#[cfg(feature = "4.6.2")]
3737
pub fn nc_close_memio(ncid: c_int, info: *mut NC_memio) -> c_int;
3838
}

‎netcdf/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ readme = "../README.md"
1414
categories = ["science", "filesystem"]
1515
exclude = ["examples/**", "tests/**"]
1616
build = "build.rs"
17+
rust-version = "1.77.0"
1718

1819
[features]
1920
default = ["ndarray"]

‎netcdf/build.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
fn main() {
2+
println!("cargo::rustc-check-cfg=cfg(feature, values(\"has-mmap\"))");
23
if std::env::var("DEP_NETCDF_HAS_MMAP").is_ok() {
3-
println!("cargo:rustc-cfg=feature=\"has-mmap\"");
4+
println!("cargo::rustc-cfg=feature=\"has-mmap\"");
45
}
56
for (env, _value) in std::env::vars() {
67
if let Some(version) = env.strip_prefix("DEP_NETCDF_VERSION_") {

0 commit comments

Comments
 (0)
Please sign in to comment.