Skip to content

Commit c7b8246

Browse files
committed
static build of netcdf
1 parent d6b4239 commit c7b8246

7 files changed

Lines changed: 62 additions & 2 deletions

File tree

.gitmodules

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

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ readme = "README.md"
1616
[features]
1717
default = ["ndarray"]
1818
memory = ["netcdf-sys/memio"]
19+
static = ["netcdf-sys/static"]
1920

2021
[dependencies]
2122
lazy_static = "1.4.0"
@@ -27,3 +28,4 @@ structopt = "0.3.3"
2728

2829
[dependencies.netcdf-sys]
2930
version = "0.2.1"
31+
path = "netcdf-sys"

netcdf-sys/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,18 @@ edition = "2018"
1414
links = "netcdf"
1515
build = "build.rs"
1616

17+
[dependencies]
18+
hdf5-sys = { git = "https://github.com/magnusuMET/hdf5-rust.git", branch = "feature/static_build", features = ["hl", "threadsafe", "deprecated"] }
19+
libz-sys = { version = "1.0.25", optional = true }
20+
1721
[dev-dependencies]
1822
lazy_static = "1.4.0"
1923

24+
[build-dependencies]
25+
cmake = "0.1.42"
26+
2027
[features]
28+
default = ["libz"]
2129
memio = []
30+
static = ["libz-sys/static", "hdf5-sys/static"]
31+
libz = ["libz-sys"]

netcdf-sys/build.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,48 @@
1+
macro_rules! feature {
2+
($feature:expr) => {
3+
std::env::var(concat!("CARGO_FEATURE_", $feature))
4+
};
5+
}
6+
17
fn main() {
8+
println!("cargo:rerun-if-changed=build.rs");
9+
if feature!("STATIC").is_ok() {
10+
build();
11+
return;
12+
}
13+
// Link to the system netcdf
214
println!("cargo:rustc-link-lib=netcdf");
315
println!("cargo:rerun-if-changed=build.rs");
416
}
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();
22+
23+
24+
let netcdf = cmake::Config::new("source")
25+
.define("BUILD_SHARED_LIBS", "OFF")
26+
.define("NC_FIND_SHARED_LIBS", "OFF")
27+
.define("BUILD_UTILITIES", "OFF")
28+
.define("ENABLE_EXAMPLES", "OFF")
29+
.define("ENABLE_DAP_REMOTE_TESTS", "OFF")
30+
.define("ENABLE_TESTS", "OFF")
31+
.define("ENABLE_EXTREME_NUMBERS", "OFF")
32+
.define("ENABLE_PARALLEL_TESTS", "OFF")
33+
.define("ENABLE_FILTER_TESTING", "OFF")
34+
.define("ENABLE_BASH_SCRIPT_TESTING", "OFF")
35+
//
36+
.define("HDF5_C_LIBRARY", &hdf5_lib)
37+
.define("HDF5_HL_LIBRARY", &hdf5_hl_lib)
38+
.define("HDF5_INCLUDE_DIR", hdf5_incdir)
39+
//
40+
.define("ENABLE_DAP", "OFF") // TODO: feature flag, requires curl
41+
//
42+
.profile("RelWithDebInfo") // TODO: detect opt-level
43+
.very_verbose(true)
44+
.build();
45+
46+
println!("cargo:rustc-link-lib=static=netcdf");
47+
println!("cargo:rustc-link-search=native={}/lib", netcdf.display());
48+
}

netcdf-sys/source

Submodule source added at 5d34ea5

netcdf-sys/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#![allow(non_upper_case_globals)]
22
#![allow(non_camel_case_types)]
33

4+
extern crate hdf5_sys;
5+
46
mod netcdf_bindings;
57
mod netcdf_const;
68
pub use netcdf_bindings::*;

netcdf-sys/src/netcdf_bindings.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ pub struct nc_vlen_t {
1313
}
1414

1515
pub type nclong = c_int;
16-
#[link(name = "netcdf")]
1716
extern "C" {
1817
pub static mut ncerr: c_int;
1918
pub static mut ncopts: c_int;
2019
}
21-
#[link(name = "netcdf")]
2220
extern "C" {
2321
pub fn nc_inq_libvers() -> *const c_char;
2422
pub fn nc_strerror(ncerr: c_int) -> *const c_char;

0 commit comments

Comments
 (0)