Skip to content

Commit f05588f

Browse files
committed
move netcdf-c to netcdf-src
1 parent c973361 commit f05588f

10 files changed

Lines changed: 78 additions & 51 deletions

File tree

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "netcdf-sys/source"]
2-
path = netcdf-sys/source
2+
path = netcdf-src/source
33
url = https://github.com/Unidata/netcdf-c.git

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ structopt = "0.3.3"
3030
[workspace]
3131
members = [
3232
"netcdf-sys",
33+
"netcdf-src",
3334
]
3435

3536
[patch]

netcdf-src/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "netcdf-src"
3+
version = "0.1.0"
4+
authors = ["Magnus Ulimoen <magnusu@met.no>"]
5+
edition = "2018"
6+
description = "Build scripts for building `netCDF` from source"
7+
build = "build.rs"
8+
license-file = "source/COPYRIGHT"
9+
links = "netcdfsrc"
10+
11+
[features]
12+
dap = []
13+
14+
[dependencies]
15+
hdf5-sys = { version = "*", features=["hl", "deprecated", "zlib"] }
16+
17+
[build-dependencies]
18+
cmake = "0.1.42"

netcdf-src/build.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
macro_rules! feature {
2+
($feature:expr) => {
3+
std::env::var(concat!("CARGO_FEATURE_", $feature))
4+
};
5+
}
6+
7+
fn main() {
8+
println!("cargo:rerun-if-changed=build.rs");
9+
10+
let hdf5_incdir = std::env::var("DEP_HDF5_INCLUDE").unwrap();
11+
let hdf5_lib = std::env::var("DEP_HDF5_LIBRARY").unwrap();
12+
let hdf5_hl_lib = std::env::var("DEP_HDF5_HL_LIBRARY").unwrap();
13+
14+
let mut netcdf_config = cmake::Config::new("source");
15+
netcdf_config
16+
.define("BUILD_SHARED_LIBS", "OFF")
17+
.define("NC_FIND_SHARED_LIBS", "OFF")
18+
.define("BUILD_UTILITIES", "OFF")
19+
.define("ENABLE_EXAMPLES", "OFF")
20+
.define("ENABLE_DAP_REMOTE_TESTS", "OFF")
21+
.define("ENABLE_TESTS", "OFF")
22+
.define("ENABLE_EXTREME_NUMBERS", "OFF")
23+
.define("ENABLE_PARALLEL_TESTS", "OFF")
24+
.define("ENABLE_FILTER_TESTING", "OFF")
25+
.define("ENABLE_BASH_SCRIPT_TESTING", "OFF")
26+
//
27+
.define("HDF5_C_LIBRARY", &hdf5_lib)
28+
.define("HDF5_HL_LIBRARY", &hdf5_hl_lib)
29+
.define("HDF5_INCLUDE_DIR", hdf5_incdir)
30+
//
31+
.define("ENABLE_DAP", "OFF") // TODO: feature flag, requires curl
32+
//
33+
.profile("RelWithDebInfo"); // TODO: detect opt-level
34+
35+
if feature!("DAP").is_ok() {
36+
netcdf_config.define("ENABLE_DAP", "ON");
37+
}
38+
39+
let netcdf = netcdf_config.build();
40+
41+
println!("cargo:lib={}", "netcdf");
42+
println!("cargo:search={}/lib", netcdf.display());
43+
}

netcdf-src/source

Submodule source added at 0014db9

netcdf-src/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//! Dummy crate for building `netCDF` from source

netcdf-sys/Cargo.toml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,14 @@ exclude = [
3636
libz-sys = { version = "1.0.25" }
3737
curl-sys = { version = "0.4.25", optional = true }
3838
hdf5-sys = { version = "0.6.0", features = ["hl", "deprecated", "zlib"] }
39+
netcdf-src = { path = "../netcdf-src", version = "0.1.0", optional = true }
3940

4041
[dev-dependencies]
4142
lazy_static = "1.4.0"
4243

43-
[build-dependencies]
44-
cmake = "0.1.42"
45-
4644
[features]
4745
default = []
4846
memio = []
49-
static = ["libz-sys/static", "hdf5-sys/static"]
47+
static = ["libz-sys/static", "hdf5-sys/static", "netcdf-src"]
5048
# TODO: Link static curl (but only when using "dap") "curl-sys/static-curl", "curl-sys/static-ssl"
5149
dap = ["curl-sys"]
52-
53-
[patch]
54-
[patch.crates-io]
55-
hdf5-sys = { git = "https://github.com/magnusuMET/hdf5-rust", branch = "feature/static_build" }

netcdf-sys/build.rs

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,15 @@ macro_rules! feature {
66

77
fn main() {
88
println!("cargo:rerun-if-changed=build.rs");
9-
if feature!("STATIC").is_ok() {
10-
build();
11-
return;
12-
}
13-
// Link to the system netcdf
14-
println!("cargo:rustc-link-lib=netcdf");
15-
println!("cargo:rerun-if-changed=build.rs");
16-
}
17-
18-
fn build() {
19-
let hdf5_incdir = std::env::var("DEP_HDF5_INCLUDE").unwrap();
20-
let hdf5_lib = std::env::var("DEP_HDF5_LIBRARY").unwrap();
21-
let hdf5_hl_lib = std::env::var("DEP_HDF5_HL_LIBRARY").unwrap();
229

10+
if feature!("STATIC").is_ok() {
11+
let netcdf_lib = std::env::var("DEP_NETCDFSRC_LIB").unwrap();
12+
let netcdf_path = std::env::var("DEP_NETCDFSRC_SEARCH").unwrap();
2313

24-
let mut netcdf_config = cmake::Config::new("source");
25-
netcdf_config
26-
.define("BUILD_SHARED_LIBS", "OFF")
27-
.define("NC_FIND_SHARED_LIBS", "OFF")
28-
.define("BUILD_UTILITIES", "OFF")
29-
.define("ENABLE_EXAMPLES", "OFF")
30-
.define("ENABLE_DAP_REMOTE_TESTS", "OFF")
31-
.define("ENABLE_TESTS", "OFF")
32-
.define("ENABLE_EXTREME_NUMBERS", "OFF")
33-
.define("ENABLE_PARALLEL_TESTS", "OFF")
34-
.define("ENABLE_FILTER_TESTING", "OFF")
35-
.define("ENABLE_BASH_SCRIPT_TESTING", "OFF")
36-
//
37-
.define("HDF5_C_LIBRARY", &hdf5_lib)
38-
.define("HDF5_HL_LIBRARY", &hdf5_hl_lib)
39-
.define("HDF5_INCLUDE_DIR", hdf5_incdir)
40-
//
41-
.define("ENABLE_DAP", "OFF") // TODO: feature flag, requires curl
42-
//
43-
.profile("RelWithDebInfo"); // TODO: detect opt-level
44-
45-
if feature!("DAP").is_ok() {
46-
netcdf_config.define("ENABLE_DAP", "ON");
14+
println!("cargo:rustc-link-lib=static={}", netcdf_lib);
15+
println!("cargo:rustc-link-search=native={}", netcdf_path);
16+
} else {
17+
// Link to the system netcdf
18+
println!("cargo:rustc-link-lib=netcdf");
4719
}
48-
49-
let netcdf = netcdf_config.build();
50-
51-
println!("cargo:rustc-link-lib=static=netcdf");
52-
println!("cargo:rustc-link-search=native={}/lib", netcdf.display());
5320
}

netcdf-sys/source

Lines changed: 0 additions & 1 deletion
This file was deleted.

netcdf-sys/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ extern crate hdf5_sys;
66
#[cfg(feature = "dap")]
77
extern crate curl_sys;
88

9+
#[cfg(feature = "static")]
10+
extern crate netcdf_src;
11+
912
mod netcdf_bindings;
1013
mod netcdf_const;
1114
pub use netcdf_bindings::*;

0 commit comments

Comments
 (0)