https://github.com/zarrs/zarrs_ffi
C/C++ bindings for the zarrs Rust crate
https://github.com/zarrs/zarrs_ffi
c cpp library zarr zarr-v3 zarrs
Last synced: 3 months ago
JSON representation
C/C++ bindings for the zarrs Rust crate
- Host: GitHub
- URL: https://github.com/zarrs/zarrs_ffi
- Owner: zarrs
- License: apache-2.0
- Created: 2023-09-25T06:08:26.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-07-26T20:56:09.000Z (4 months ago)
- Last Synced: 2025-07-26T23:44:32.104Z (4 months ago)
- Topics: c, cpp, library, zarr, zarr-v3, zarrs
- Language: Rust
- Homepage: https://zarrs.dev/zarrs_ffi/
- Size: 617 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# zarrs_ffi
[](https://crates.io/crates/zarrs_ffi)
[](https://zarrs.dev/zarrs_ffi/)
[](https://docs.rs/zarrs_ffi)

[](https://github.com/LDeakin/zarrs_ffi/actions/workflows/ci.yml)
C/C++ bindings for the [`zarrs`] crate, a Rust library for the [Zarr](https://zarr.dev) storage format for multidimensional arrays and metadata.
`zarrs_ffi` is a single header library: `zarrs.h` [(docs)](https://zarrs.dev/zarrs_ffi/zarrs_8h.html).
Currently `zarrs_ffi` only supports a small subset of the [`zarrs`] API.
A changelog can be found [here](https://github.com/LDeakin/zarrs_ffi/blob/main/CHANGELOG.md).
## Example
```C++
#include "zarrs.h"
void main() {
// Open a filesystem store pointing to a zarr hierarchy
ZarrsStorage storage = nullptr;
zarrs_assert(zarrsCreateStorageFilesystem("/path/to/hierarchy.zarr", &storage));
// Open an array in the hierarchy
ZarrsArray array = nullptr;
zarrs_assert(zarrsOpenArrayRW(storage, "/array", &array));
// Get the array dimensionality
size_t dimensionality;
zarrs_assert(zarrsArrayGetDimensionality(array, &dimensionality));
assert(dimensionality == 2);
// Retrieve the decoded bytes of the chunk at [0, 0]
size_t indices[] = {0, 0};
size_t chunk_size;
zarrs_assert(zarrsArrayGetChunkSize(array, 2, indices, &chunk_size));
std::unique_ptr chunk_bytes(new uint8_t[chunk_size]);
zarrs_assert(zarrsArrayRetrieveChunk(array, 2, indices, chunk_size, chunk_bytes.get()));
}
```
See a more comprehensive example in the [examples](https://github.com/LDeakin/zarrs_ffi/tree/main/examples) directory.
## CMake Quickstart
1. Install the Rust compiler (and cargo).
2. Put [Findzarrs.cmake](https://github.com/LDeakin/zarrs_ffi/blob/main/examples/Findzarrs.cmake) in your `CMAKE_MODULE_PATH`
3. `find_package(zarrs REQUIRED COMPONENTS zarrs/bz2)`
- Replace `` with the latest release: [](https://crates.io/crates/zarrs_ffi) (e.g., `0.9` or `0.9.2`)
- [`zarrs`] is retrieved from `GitHub` using [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html) and built using [corrosion](https://github.com/corrosion-rs/corrosion)
- Components are optional [`zarrs`] codecs
4. the `zarrs_ffi` library is available as the `zarrs::zarrs` or `zarrs::zarrs-static` target
A complete `CMake` example can be found in [examples/](https://github.com/LDeakin/zarrs_ffi/tree/main/examples/).
## Manual Build
#### Basic Build
Building generates a header, and a platform-dependent static and dynamic library.
```bash
cargo build --release --features cbindgen # -> zarrs.h and target/release/[lib]zarrs_ffi{.a,.so,.dll,.dylib}
```
`zarrs.h` is only re-generated if the `cbindgen` feature is enabled.
#### Enabling SIMD intrinsics
Encoding and decoding performance may be improved with `avx2`/`sse2` enabled (if supported).
Compile with either of:
- `RUSTFLAGS="-C target-cpu=native"`
- `RUSTFLAGS="-C target-feature=+avx2,+sse2"`
#### Enabling non-default zarrs codecs
Non-default `zarrs` codecs (see [`zarrs` crate features](https://docs.rs/zarrs/latest/zarrs/#crate-features)) can be enabled with the `all_codecs` feature.
Alternatively, individual codecs can be enabled by passing them as feature flags.
For example:
```bash
cargo build --release --features cbindgen --features zarrs/zstd,zarrs/bitround,zarrs/zfp,zarrs/bz2,zarrs/pcodec,zarrs/gdeflate
```
## Licence
`zarrs_ffi` is licensed under either of
- the Apache License, Version 2.0 [LICENSE-APACHE](./LICENCE-APACHE) or or
- the MIT license [LICENSE-MIT](./LICENCE-MIT) or , at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
[`zarrs`]: https://github.com/LDeakin/zarrs