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

Enable T in VarLenArray<T> to also contain a VarLenArray #232

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
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
22 changes: 11 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
include:
- {version: hdf5@1.8}
- {version: hdf5@1.10}
- {version: hdf5@1.12}
# - {version: hdf5@1.12}
- {version: hdf5-mpi, mpi: true}
steps:
- name: Checkout repository
Expand Down Expand Up @@ -132,10 +132,10 @@ jobs:
fail-fast: false
matrix:
include:
- {os: ubuntu, rust: stable}
- {os: windows, rust: stable-msvc}
- {os: windows, rust: stable-gnu}
- {os: macos, rust: stable}
- {os: ubuntu, rust: stable, h5version: 1_14}
- {os: windows, rust: stable-msvc, h5version: 1_12}
- {os: windows, rust: stable-gnu, h5version: 1_10}
- {os: macos, rust: stable, h5version: 1_10}
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -144,9 +144,9 @@ jobs:
uses: actions-rs/toolchain@v1
with: {toolchain: '${{matrix.rust}}', profile: minimal, override: true}
- name: Build and test all crates
run: cargo test --workspace -v --features hdf5-sys/static,hdf5-sys/zlib --exclude hdf5-derive
run: cargo test --workspace -v --features hdf5-sys/static,hdf5-sys/zlib,hdf5-src/${{matrix.h5version}} --exclude hdf5-derive
- name: Build and test with filters
run: cargo test --workspace -v --features hdf5-sys/static,hdf5-sys/zlib,lzf,blosc --exclude hdf5-derive
run: cargo test --workspace -v --features hdf5-sys/static,hdf5-sys/zlib,lzf,blosc,hdf5-src/${{matrix.h5version}} --exclude hdf5-derive
if: matrix.rust != 'stable-gnu'
- name: Run examples
run: |
Expand Down Expand Up @@ -194,7 +194,7 @@ jobs:
fail-fast: false
matrix:
rust: [stable]
version: ["1.8", "1.10", "1.12", "1.13"]
version: ["1.8", "1.10", "1.12", "1.14"]
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -218,9 +218,9 @@ jobs:
DL_PATH=hdf5-1.12.0-Std-win10_64-vs16.zip
echo "MSI_PATH=hdf\\HDF5-1.12.0-win64.msi" >> $GITHUB_ENV
else
VERSION=1.13.2
DL_PATH=windows/hdf5-1.13.2-Std-win10_64-vs16.zip
echo "MSI_PATH=hdf\\HDF5-1.13.2-win64.msi" >> $GITHUB_ENV
VERSION=1.14.0
DL_PATH=windows/hdf5-1.14.0-Std-win10_64-vs16.zip
echo "MSI_PATH=hdf\\HDF5-1.14.0-win64.msi" >> $GITHUB_ENV
fi
BASE_URL=https://support.hdfgroup.org/ftp/HDF5/releases
echo "DL_URL=$BASE_URL/hdf5-${{matrix.version}}/hdf5-$VERSION/bin/$DL_PATH" >> $GITHUB_ENV
Expand Down
10 changes: 8 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[submodule "hdf5"]
path = hdf5-src/ext/hdf5
[submodule "hdf5-src/ext/1_10"]
path = hdf5-src/ext/1_10
url = https://github.com/HDFGroup/hdf5.git
[submodule "hdf5-src/ext/1_12_0"]
path = hdf5-src/ext/1_12
url = https://github.com/HDFGroup/hdf5.git
[submodule "hdf5-src/ext/1_14"]
path = hdf5-src/ext/1_14
url = https://github.com/HDFGroup/hdf5.git
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

- The `H5Type` derive macro now uses `proc-macro-error` to emit error messages.
- MSRV is now `1.54` following a bump in a dependency.
- `hdf5-src` can now be built from several versions of `hdf5` using compile-time
flags. Enable this using the features `1_14`, `1_12`, or `1_10` of `hdf5-src`.
More recent versions take priority if multiple versions has been selected.

### Fixed

Expand Down
40 changes: 26 additions & 14 deletions hdf5-src/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "hdf5-src"
version = "0.8.1" # !V
authors = ["Ivan Smirnov <i.s.smirnov@gmail.com>"]
keywords = ["hdf5"]
license-file = "ext/hdf5/COPYING"
license-file = "ext/1_13/COPYING"
build = "build.rs"
repository = "https://github.com/aldanor/hdf5-rust"
homepage = "https://github.com/aldanor/hdf5-rust"
Expand All @@ -13,28 +13,40 @@ links = "hdf5src"
readme = "README.md"
categories = ["ffi"]
exclude = [
"ext/hdf5/bin/**",
"ext/hdf5/c++/**",
"ext/hdf5/examples/**",
"ext/hdf5/fortran/**",
"ext/hdf5/java/**",
"ext/hdf5/release_docs/**",
"ext/hdf5/test/**",
"ext/hdf5/testpar/**",
"ext/hdf5/tools/**",
"ext/hdf5/hl/test/**",
"ext/hdf5/hl/tools/**",
"ext/hdf5/hl/examples/**",
"ext/*/bin/**",
"ext/*/c++/**",
"ext/*/examples/**",
"ext/*/fortran/**",
"ext/*/java/**",
"ext/*/release_docs/**",
"ext/*/test/**",
"ext/*/testpar/**",
"ext/*/tools/**",
"ext/*/m4/**",
"ext/*/configure",
"ext/*/MANIFEST",
"ext/*/hl/test/**",
"ext/*/hl/tools/**",
"ext/*/hl/examples/**",
"ext/*/hl/fortran/**",
"ext/*/hl/c++/**",
"ext/*/oxygen/**",
"ext/*/doxygen/**",
"ext/*/config/cmake_ext_mod/hdf.icns",
]

[features]
default = ["1_12"]
hl = []
zlib = ["libz-sys"]
deprecated = []
threadsafe = []
1_10 = []
1_12 = []
1_14 = []

[dependencies]
libz-sys = { version = "1.0.25", features = ["static", "libc"], optional = true, default-features=false }
libz-sys = { version = "1.1.9", features = ["static", "libc"], optional = true, default-features=false }

[build-dependencies]
cmake = "0.1.44"
17 changes: 16 additions & 1 deletion hdf5-src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ fn feature_enabled(feature: &str) -> bool {

fn main() {
println!("cargo:rerun-if-changed=build.rs");
let mut cfg = cmake::Config::new("ext/hdf5");
let mut cfg = if feature_enabled("1_14") {
cmake::Config::new("ext/1_14")
} else if feature_enabled("1_12") {
cmake::Config::new("ext/1_12")
} else if feature_enabled("1_10") {
cmake::Config::new("ext/1_10")
} else {
cmake::Config::new("ext/1_10")
};

// only build the static c library, disable everything else
cfg.define("HDF5_NO_PACKAGES", "ON");
Expand All @@ -23,6 +31,7 @@ fn main() {
] {
cfg.define(option, "OFF");
}
cfg.define("DEFAULT_API_VERSION", "none");

// disable these by default, can be enabled via features
for option in &[
Expand Down Expand Up @@ -59,6 +68,7 @@ fn main() {
}

let targeting_windows = env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows";
let targeting_macos = env::var("CARGO_CFG_TARGET_OS").unwrap() == "macos";
let debug_postfix = if targeting_windows { "_D" } else { "_debug" };

if feature_enabled("HL") {
Expand All @@ -80,6 +90,11 @@ fn main() {
cfg.define("CMAKE_CROSSCOMPILING_EMULATOR", wine_exec);
}

if env::consts::OS != "macos" && targeting_macos {
println!("Cross compiling to macos, so setting emulator to darling");
cfg.define("CMAKE_CROSSCOMPILING_EMULATOR", "darling");
}

let dst = cfg.build();
println!("cargo:root={}", dst.display());

Expand Down
1 change: 1 addition & 0 deletions hdf5-src/ext/1_10
Submodule 1_10 added at 83f81a
1 change: 1 addition & 0 deletions hdf5-src/ext/1_12
Submodule 1_12 added at 6bd9f7
1 change: 1 addition & 0 deletions hdf5-src/ext/1_14
Submodule 1_14 added at 6eb021
1 change: 0 additions & 1 deletion hdf5-src/ext/hdf5
Submodule hdf5 deleted from db30c2
2 changes: 1 addition & 1 deletion hdf5-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ categories = ["ffi", "filesystem", "science"]
[dependencies]
libc = "0.2"
mpi-sys = { version = "0.1", optional = true }
libz-sys = { version = "1.0.25", optional = true, default-features = false }
libz-sys = { version = "1.1.9", optional = true, default-features = false }
hdf5-src = { path = "../hdf5-src", version = "0.8.1", optional = true } # !V

# Please see README for further explanation of these feature flags
Expand Down
8 changes: 6 additions & 2 deletions hdf5-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl Version {
}

pub fn parse(s: &str) -> Option<Self> {
let re = Regex::new(r"^(1)\.(8|10|12|13)\.(\d\d?)(_\d+)?(-patch\d+)?$").ok()?;
let re = Regex::new(r"^(1)\.(8|10|12|13|14)\.(\d\d?).(\d\d?)?(_\d+)?(-patch\d+)?$").ok()?;
let captures = re.captures(s)?;
Some(Self {
major: captures.get(1).and_then(|c| c.as_str().parse::<u8>().ok())?,
Expand Down Expand Up @@ -604,15 +604,19 @@ impl Config {
if feature_enabled("HL") {
println!("cargo:hl_library=hdf5_hl");
}

let version = self.header.version;
println!("cargo:h5version={}.{}.{}", version.major, version.minor, version.micro);
}

pub fn emit_cfg_flags(&self) {
let version = self.header.version;
assert!(version >= Version::new(1, 8, 4), "required HDF5 version: >=1.8.4");
let mut vs: Vec<_> = (5..=21).map(|v| Version::new(1, 8, v)).collect(); // 1.8.[5-21]
vs.extend((0..=8).map(|v| Version::new(1, 10, v))); // 1.10.[0-8]
vs.extend((0..=1).map(|v| Version::new(1, 12, v))); // 1.12.[0-1]
vs.extend((0..=3).map(|v| Version::new(1, 12, v))); // 1.12.[0-3]
vs.extend((0..=0).map(|v| Version::new(1, 13, v))); // 1.13.[0-0]
vs.extend((0..=0).map(|v| Version::new(1, 14, v))); // 1.14.[0-0]
for v in vs.into_iter().filter(|&v| version >= v) {
println!("cargo:rustc-cfg=feature=\"{}.{}.{}\"", v.major, v.minor, v.micro);
println!("cargo:version_{}_{}_{}=1", v.major, v.minor, v.micro);
Expand Down
30 changes: 15 additions & 15 deletions hdf5-types/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use std::ptr;
use std::slice;

#[repr(C)]
pub struct VarLenArray<T: Copy> {
pub struct VarLenArray<T: Clone> {
len: usize,
ptr: *const T,
tag: PhantomData<T>,
}

impl<T: Copy> VarLenArray<T> {
impl<T: Clone> VarLenArray<T> {
pub unsafe fn from_parts(p: *const T, len: usize) -> Self {
let (len, ptr) = if !p.is_null() && len != 0 {
let dst = crate::malloc(len * mem::size_of::<T>());
Expand Down Expand Up @@ -50,7 +50,7 @@ impl<T: Copy> VarLenArray<T> {
}
}

impl<T: Copy> Drop for VarLenArray<T> {
impl<T: Clone> Drop for VarLenArray<T> {
fn drop(&mut self) {
if !self.ptr.is_null() {
unsafe {
Expand All @@ -64,14 +64,14 @@ impl<T: Copy> Drop for VarLenArray<T> {
}
}

impl<T: Copy> Clone for VarLenArray<T> {
impl<T: Clone> Clone for VarLenArray<T> {
#[inline]
fn clone(&self) -> Self {
Self::from_slice(self)
}
}

impl<T: Copy> Deref for VarLenArray<T> {
impl<T: Clone> Deref for VarLenArray<T> {
type Target = [T];

#[inline]
Expand All @@ -84,58 +84,58 @@ impl<T: Copy> Deref for VarLenArray<T> {
}
}

impl<'a, T: Copy> From<&'a [T]> for VarLenArray<T> {
impl<'a, T: Clone> From<&'a [T]> for VarLenArray<T> {
#[inline]
fn from(arr: &[T]) -> Self {
Self::from_slice(arr)
}
}

impl<T: Copy> From<VarLenArray<T>> for Vec<T> {
impl<T: Clone> From<VarLenArray<T>> for Vec<T> {
#[inline]
fn from(v: VarLenArray<T>) -> Self {
v.iter().copied().collect()
v.iter().cloned().collect()
}
}

impl<T: Copy, const N: usize> From<[T; N]> for VarLenArray<T> {
impl<T: Clone, const N: usize> From<[T; N]> for VarLenArray<T> {
#[inline]
fn from(arr: [T; N]) -> Self {
unsafe { Self::from_parts(arr.as_ptr(), arr.len()) }
}
}

impl<T: Copy> Default for VarLenArray<T> {
impl<T: Clone> Default for VarLenArray<T> {
#[inline]
fn default() -> Self {
unsafe { Self::from_parts(ptr::null(), 0) }
}
}

impl<T: Copy + PartialEq> PartialEq for VarLenArray<T> {
impl<T: Clone + PartialEq> PartialEq for VarLenArray<T> {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.as_slice() == other.as_slice()
}
}

impl<T: Copy + Eq> Eq for VarLenArray<T> {}
impl<T: Clone + Eq> Eq for VarLenArray<T> {}

impl<T: Copy + PartialEq> PartialEq<[T]> for VarLenArray<T> {
impl<T: Clone + PartialEq> PartialEq<[T]> for VarLenArray<T> {
#[inline]
fn eq(&self, other: &[T]) -> bool {
self.as_slice() == other
}
}

impl<T: Copy + PartialEq, const N: usize> PartialEq<[T; N]> for VarLenArray<T> {
impl<T: Clone + PartialEq, const N: usize> PartialEq<[T; N]> for VarLenArray<T> {
#[inline]
fn eq(&self, other: &[T; N]) -> bool {
self.as_slice() == other
}
}

impl<T: Copy + fmt::Debug> fmt::Debug for VarLenArray<T> {
impl<T: Clone + fmt::Debug> fmt::Debug for VarLenArray<T> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.as_slice().fmt(f)
Expand Down
2 changes: 1 addition & 1 deletion hdf5-types/src/h5type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ unsafe impl<T: H5Type, const N: usize> H5Type for [T; N] {
}
}

unsafe impl<T: Copy + H5Type> H5Type for VarLenArray<T> {
unsafe impl<T: Clone + H5Type> H5Type for VarLenArray<T> {
#[inline]
fn type_descriptor() -> TypeDescriptor {
TypeDescriptor::VarLenArray(Box::new(<T as H5Type>::type_descriptor()))
Expand Down
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ mod export {
#[doc(hidden)]
pub use crate::error::h5check;

pub mod macros {
pub use crate::macros::*;
}

pub use hdf5_derive::H5Type;
pub use hdf5_types::H5Type;

Expand Down Expand Up @@ -137,7 +141,7 @@ pub mod globals;
mod handle;
#[doc(hidden)]
pub mod sync;
mod util;
pub mod util;

mod hl;

Expand Down
1 change: 1 addition & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ impl_h5get!(a: A, b: B);
impl_h5get!(a: A, b: B, c: C);
impl_h5get!(a: A, b: B, c: C, d: D);

#[macro_export]
macro_rules! h5err {
($msg:expr, $major:expr, $minor:expr) => {
let line = line!();
Expand Down