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

Win build #4

Closed
wants to merge 22 commits into from
Closed
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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ Cargo.lock
**/target/release
/tmp.*
**/*.h5

# vim
*~
*.swp

# vagrant
.vagrant/

15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ Thread-safe Rust bindings and high-level wrappers for the HDF5 library API.
Note that this project is in its early development stage and hence things are likely to change
and break on a regular basis.

## Building

### Windows

Building hdf5-rs on Windows currently needs some manual preparation steps:

* A HDF5 binary, namely the shared library `hdf5.dll` is needed for linking. For (currently) unknown reasons, the prebuilt binaries from [HDF-Group](http://www.hdfgroup.org/) do not work (they are build with MSVC). It has to be build with gcc. Instructions for building HDF5 on Windows can be found [here](http://www.hdfgroup.org/HDF5/release/cmakebuild.html). For building the [TDM distribution](http://tdm-gcc.tdragon.net/) of MinGW-GCC is recommended, as it contains bintools for both 32bit & 64bit.

* Set the environment variable `HDF5_LIBDIR` to point to the folder with the newly build `hdf5.dll`. Explanation: `pkg-config` will silently fail if not present and the path from the before-mentioned environment variable is added to the rustc commands by cargo. (Hint: Avoid path names with spaces, as they are difficult to escape correctly).

* Run `cargo build` and/or `cargo test` to build and rust library and run the tests, repsectively. Hint: After changing the build environment, e.g. `HDF5_LIBDIR`, a `cargo clean` might be necessary.

* Make sure `hdf5.dll` is on your search path, otherwise the tests will fail.


## License

`hdf5-rs` is primarily distributed under the terms of both the MIT license and the
Expand Down
36 changes: 36 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# appveyor.yml
#
# vim: sw=2 ts=2 et
#

version: 0.1.{build}

environment:
RUST_TARGET: x86_64-pc-windows-gnu
#RUST_VERSION: 1.1.0
HDF5_LIBDIR: C:\hdf5_bin

matrix:
- RUST_VERSION: 1.1.0
- RUST_VERSION: nightly

install:
# get rust & cargo
- ps: Start-FileDownload "https://static.rust-lang.org/dist/rust-${env:RUST_VERSION}-${env:RUST_TARGET}.exe"
- rust-%RUST_VERSION%-%RUST_TARGET%.exe /VERYSILENT /NORESTART /DIR="C:\Program Files\Rust-%RUST_VERSION%"
- set PATH=%PATH%;C:\Program Files\Rust-%RUST_VERSION%\bin

# get hdf5 binary (just get a prebuild binary for now)
- mkdir C:\hdf5_bin
- ps: Invoke-WebRequest "https://github.com/kkirstein/hdf5-rs/releases/download/alpha/hdf5.dll" -OutFile "C:\hdf5_bin\hdf5.dll"
- set PATH=C:\hdf5_bin;%PATH%

# output version info
- rustc --version
- cargo --version

build: false

test_script:
- cargo test --verbose

2 changes: 1 addition & 1 deletion libhdf5-sys/src/h5p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ extern {
pub static H5P_LST_LINK_ACCESS_g: hid_t;
}

#[cfg(target_os = "macos")]
#[cfg(any(target_os = "macos", target_os = "windows"))]
extern {
// Property list classes (OSX version of the library)
pub static H5P_CLS_ROOT_ID_g: hid_t;
Expand Down
11 changes: 9 additions & 2 deletions remutex/src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ unsafe impl Send for ReentrantMutex {}
unsafe impl Sync for ReentrantMutex {}

impl ReentrantMutex {
#[inline]
pub unsafe fn uninitialized() -> ReentrantMutex {
mem::uninitialized()
}

pub unsafe fn init(&mut self) -> ReentrantMutex {
#[inline]
pub unsafe fn init(&mut self) {
ffi::InitializeCriticalSection(self.inner.get());
}

#[inline]
pub unsafe fn lock(&self) {
ffi::EnterCriticalSection(self.inner.get());
}
Expand All @@ -32,19 +35,23 @@ impl ReentrantMutex {
ffi::TryEnterCriticalSection(self.inner.get()) != 0
}

#[inline]
pub unsafe fn unlock(&self) {
ffi::LeaveCriticalSection(self.inner.get());
}

#[inline]
pub unsafe fn destroy(&self) {
ffi::DeleteCriticalSection(self.inner.get());
}
}

mod ffi {
use libc::{LPVOID, LONG, HANDLE, c_ulong};
use libc::{LPVOID, LONG, HANDLE, c_ulong, BOOLEAN};
#[allow(non_camel_case_types)]
pub type ULONG_PTR = c_ulong;

#[allow(non_snake_case)]
#[repr(C)]
pub struct CRITICAL_SECTION {
CriticalSectionDebug: LPVOID,
Expand Down
35 changes: 35 additions & 0 deletions src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,41 @@ link_hid!(H5T_NATIVE_UINT_FAST64, H5T_NATIVE_UINT_FAST64_g);
#[cfg(target_os = "macos")] link_hid!(H5P_LST_LINK_CREATE_ID, H5P_LST_LINK_CREATE_ID_g);
#[cfg(target_os = "macos")] link_hid!(H5P_LST_LINK_ACCESS_ID, H5P_LST_LINK_ACCESS_ID_g);

// Property list classes (Windows version of the library)
#[cfg(target_os = "windows")] link_hid!(H5P_ROOT, H5P_CLS_ROOT_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_OBJECT_CREATE, H5P_CLS_OBJECT_CREATE_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_FILE_CREATE, H5P_CLS_FILE_CREATE_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_FILE_ACCESS, H5P_CLS_FILE_ACCESS_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_DATASET_CREATE, H5P_CLS_DATASET_CREATE_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_DATASET_ACCESS, H5P_CLS_DATASET_ACCESS_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_DATASET_XFER, H5P_CLS_DATASET_XFER_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_FILE_MOUNT, H5P_CLS_FILE_MOUNT_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_GROUP_CREATE, H5P_CLS_GROUP_CREATE_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_GROUP_ACCESS, H5P_CLS_GROUP_ACCESS_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_DATATYPE_CREATE, H5P_CLS_DATATYPE_CREATE_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_DATATYPE_ACCESS, H5P_CLS_DATATYPE_ACCESS_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_STRING_CREATE, H5P_CLS_STRING_CREATE_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_ATTRIBUTE_CREATE, H5P_CLS_ATTRIBUTE_CREATE_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_OBJECT_COPY, H5P_CLS_OBJECT_COPY_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_LINK_CREATE, H5P_CLS_LINK_CREATE_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_LINK_ACCESS, H5P_CLS_LINK_ACCESS_ID_g);

// Default property lists (Windows version of the library)
#[cfg(target_os = "windows")] link_hid!(H5P_LST_FILE_CREATE_ID, H5P_LST_FILE_CREATE_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_LST_FILE_ACCESS_ID, H5P_LST_FILE_ACCESS_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_LST_DATASET_CREATE_ID, H5P_LST_DATASET_CREATE_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_LST_DATASET_ACCESS_ID, H5P_LST_DATASET_ACCESS_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_LST_DATASET_XFER_ID, H5P_LST_DATASET_XFER_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_LST_FILE_MOUNT_ID, H5P_LST_FILE_MOUNT_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_LST_GROUP_CREATE_ID, H5P_LST_GROUP_CREATE_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_LST_GROUP_ACCESS_ID, H5P_LST_GROUP_ACCESS_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_LST_DATATYPE_CREATE_ID, H5P_LST_DATATYPE_CREATE_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_LST_DATATYPE_ACCESS_ID, H5P_LST_DATATYPE_ACCESS_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_LST_ATTRIBUTE_CREATE_ID, H5P_LST_ATTRIBUTE_CREATE_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_LST_OBJECT_COPY_ID, H5P_LST_OBJECT_COPY_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_LST_LINK_CREATE_ID, H5P_LST_LINK_CREATE_ID_g);
#[cfg(target_os = "windows")] link_hid!(H5P_LST_LINK_ACCESS_ID, H5P_LST_LINK_ACCESS_ID_g);

// Error class
link_hid!(H5E_ERR_CLS, H5E_ERR_CLS_g);

Expand Down