Skip to content

Commit 0d79e65

Browse files
authored
Merge pull request #56 from magnusuMET/vendor
Option for building netCDF from source
2 parents 97cff73 + 0c10ba6 commit 0d79e65

18 files changed

Lines changed: 256 additions & 75 deletions

File tree

.github/workflows/ci.yml

Lines changed: 63 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ jobs:
1818
steps:
1919
- name: Checkout repository
2020
uses: actions/checkout@v2
21+
with: {submodules: true}
22+
- name: Install netCDF
23+
run: sudo apt-get install libnetcdf-dev
2124
- name: Install rust
2225
uses: actions-rs/toolchain@v1
2326
with:
@@ -28,13 +31,13 @@ jobs:
2831
- name: Check formatting
2932
run: cargo fmt -- --check
3033
- name: Documentation
31-
run: cargo doc --workspace
34+
run: cargo doc --workspace --exclude netcdf-src
3235
- name: Clippy
33-
run: cargo clippy --workspace -- -D warnings
36+
run: cargo clippy --workspace --exclude netcdf-src -- -D warnings
3437

35-
test:
36-
name: test
37-
runs-on: ${{ matrix.os }}
38+
test_apt:
39+
name: test apt
40+
runs-on: ubuntu-18.04
3841
strategy:
3942
matrix:
4043
build:
@@ -43,17 +46,15 @@ jobs:
4346
- nightly
4447
include:
4548
- build: stable
46-
os: ubuntu-18.04
4749
rust: stable
4850
- build: beta
49-
os: ubuntu-18.04
5051
rust: beta
5152
- build: nightly
52-
os: ubuntu-18.04
5353
rust: nightly
5454
steps:
5555
- name: Checkout repository
5656
uses: actions/checkout@v2
57+
with: {submodules: false}
5758

5859
- name: Install netcdf
5960
run: sudo apt-get install libnetcdf-dev
@@ -66,37 +67,63 @@ jobs:
6667
override: true
6768

6869
- name: Build
69-
run: cargo build --verbose --workspace
70+
run: cargo build --verbose --workspace --exclude netcdf-src
7071

7172
- name: Test
72-
run: cargo test --verbose --workspace
73+
run: cargo test --verbose --workspace --exclude netcdf-src
7374
if: matrix.os == 'ubuntu-18.04'
7475

75-
tarpaulin:
76-
name: tarpaulin
77-
runs-on: ubuntu-18.04
76+
conda:
77+
name: conda
78+
runs-on: ${{matrix.os}}-latest
79+
strategy:
80+
fail-fast: false
81+
matrix:
82+
include:
83+
- {os: ubuntu, channel: conda-forge, rust: stable}
84+
- {os: windows, channel: conda-forge, rust: stable}
85+
- {os: macos, channel: conda-forge, rust: stable}
86+
defaults:
87+
run:
88+
shell: bash -l {0}
7889
steps:
79-
- name: Checkout repository
80-
uses: actions/checkout@v2
81-
- name: Install netcdf
82-
run: sudo apt-get install libnetcdf-dev
83-
- name: Install rust
84-
uses: actions-rs/toolchain@v1
85-
with:
86-
toolchain: stable
87-
profile: minimal
88-
override: true
89-
- name: Install tarpaulin
90-
uses: actions-rs/install@v0.1
91-
with:
92-
crate: cargo-tarpaulin
93-
version: latest
94-
use-tool-cache: true
95-
96-
- name: Tarpaulin
97-
run: cargo tarpaulin --verbose --out Xml --ignore-tests
90+
- name: Checkout repository
91+
uses: actions/checkout@v2
92+
with: {submodules: true}
93+
- name: Install Rust (${{matrix.rust}})
94+
uses: actions-rs/toolchain@v1
95+
with: {toolchain: '${{matrix.rust}}', profile: minimal, override: true}
96+
- name: Install conda
97+
uses: goanpeca/setup-miniconda@v1
98+
with: {auto-update-conda: false, activate-environment: testenv}
99+
- name: Install netCDF
100+
run: conda install -y -c ${{matrix.channel}} libnetcdf=4.7.4
101+
- name: Build and test
102+
run: |
103+
export HDF5_DIR="$CONDA_PREFIX"
104+
[ "${{runner.os}}" != "Windows" ] && export RUSTFLAGS="-C link-args=-Wl,-rpath,$CONDA_PREFIX/lib"
105+
cargo test -vv --workspace --exclude netcdf-src
98106
99-
- name: Upload to codecov
100-
uses: codecov/codecov-action@v1.0.2
101-
with:
102-
token: ${{ secrets.CODECOV_TOKEN }}
107+
static_builds:
108+
name: static builds
109+
runs-on: ${{matrix.os}}-latest
110+
strategy:
111+
fail-fast: false
112+
matrix:
113+
include:
114+
- {os: ubuntu, rust: stable}
115+
- {os: windows, rust: stable-msvc}
116+
- {os: windows, rust: stable-gnu}
117+
- {os: macos, rust: stable}
118+
defaults:
119+
run:
120+
shell: bash -l {0}
121+
steps:
122+
- name: Checkout repository
123+
uses: actions/checkout@v2
124+
with: {submodules: true}
125+
- name: Install Rust (${{matrix.rust}})
126+
uses: actions-rs/toolchain@v1
127+
with: {toolchain: '${{matrix.rust}}', profile: minimal, override: true}
128+
- name: Build and test
129+
run: cargo test -vv --workspace --features static

.github/workflows/codecov.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: codecov
2+
on: [push]
3+
env:
4+
CARGO_TERM_COLOR: always
5+
6+
jobs:
7+
tarpaulin:
8+
name: tarpaulin
9+
runs-on: ubuntu-18.04
10+
steps:
11+
- name: Checkout repository
12+
uses: actions/checkout@v2
13+
- name: Install netcdf
14+
run: sudo apt-get install libnetcdf-dev
15+
- name: Install rust
16+
uses: actions-rs/toolchain@v1
17+
with:
18+
toolchain: stable
19+
profile: minimal
20+
override: true
21+
- name: Install tarpaulin
22+
uses: actions-rs/install@v0.1
23+
with:
24+
crate: cargo-tarpaulin
25+
version: latest
26+
use-tool-cache: true
27+
28+
- name: Tarpaulin
29+
run: cargo tarpaulin --verbose --out Xml --ignore-tests
30+
31+
- name: Upload to codecov
32+
uses: codecov/codecov-action@v1.0.2
33+
with:
34+
token: ${{ secrets.CODECOV_TOKEN }}

.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-src/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
@@ -17,6 +17,7 @@ exclude = ["examples/**", "tests/**"]
1717
[features]
1818
default = ["ndarray"]
1919
memory = ["netcdf-sys/memio"]
20+
static = ["netcdf-sys/static"]
2021

2122
[dependencies]
2223
lazy_static = "1.4.0"
@@ -30,4 +31,5 @@ structopt = "0.3.3"
3031
[workspace]
3132
members = [
3233
"netcdf-sys",
34+
"netcdf-src",
3335
]

Dockerfile

Lines changed: 0 additions & 18 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<!-- [![dependency status](https://deps.rs/repo/github/georust/netcdf/status.svg)](https://deps.rs/repo/github/georust/netcdf) -->
1010

1111
Medium-level [netCDF](http://www.unidata.ucar.edu/software/netcdf/) bindings for Rust, allowing easy reading and writing of array-like structures to a file.
12+
netCDF can read and write `hdf5` files, which is a commonly used file format in scientific computing.
1213

1314
## Status
1415

@@ -32,14 +33,10 @@ All variable data is read into a contiguous buffer, or inta an [ndarray](https:/
3233

3334
## Building
3435

35-
This crate depends on libnetcdf. The Travis build runs on Ubuntu 16.04 Xenial and installs libnetcdf via apt, which results in netcdf v.4.4.0. netcdf is not widely tested on other versions of netcdf.
36+
This crate depends on `libnetcdf`, but a static build from source is also supported, which can be enabled using the `static` feature.
3637

37-
You can build the library and run the tests via Docker like this:
38+
The crate is built on several platforms using github actions, and is currently known to build form from source on all major platforms (linux, macos, windows (gnu+msvc)), and through the package installers `conda` and `apt`.
3839

39-
```
40-
docker build . -t netcdf
41-
docker run -it --rm netcdf
42-
```
4340

4441
## Documentation
4542

netcdf-src/Cargo.toml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
repository = "https://github.com/georust/netcdf"
9+
license-file = "source/COPYRIGHT"
10+
links = "netcdfsrc"
11+
exclude = [
12+
"source/unit_test/**",
13+
"source/NUG/**",
14+
"source/dap4_test/**",
15+
"source/examples/**",
16+
"source/nc_test/**",
17+
"source/h5_test/**",
18+
"source/nc_perf/**",
19+
"source/ncdump/**",
20+
"source/hdf4_test/**",
21+
"source/ncgen/**",
22+
"source/ncgen3/**",
23+
"source/nctest/**",
24+
]
25+
26+
[features]
27+
dap = []
28+
29+
[dependencies]
30+
hdf5-sys = { version = "0.7.0", features = ["hl", "deprecated", "zlib"] }
31+
32+
[build-dependencies]
33+
cmake = "0.1.44"

netcdf-src/build.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
let search_path = format!("{}/lib", netcdf.display());
43+
if std::path::Path::new(&search_path).exists() {
44+
println!("cargo:search={}", search_path);
45+
} else {
46+
let search_path = format!("{}/lib64", netcdf.display());
47+
println!("cargo:search={}", search_path);
48+
}
49+
}

netcdf-src/source

Submodule source added at 26fba54

netcdf-src/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//! Dummy crate for building `netCDF` from source
2+
//!
3+
//! The current pinned version is 4.7.4

0 commit comments

Comments
 (0)