Skip to content

Rust bindings#87

Merged
caraghbiner merged 45 commits into
developfrom
rust-bindings
May 4, 2026
Merged

Rust bindings#87
caraghbiner merged 45 commits into
developfrom
rust-bindings

Conversation

@Choochmeque

Copy link
Copy Markdown
Contributor

Description

Contributor Declaration

By opening this pull request, I affirm the following:

  • All authors agree to the Contributor License Agreement.
  • The code follows the project's coding standards.
  • I have performed self-review and added comments where needed.
  • I have added or updated tests to verify that my changes are effective and functional.
  • I have run all existing tests and confirmed they pass.

@codecov-commenter

codecov-commenter commented Mar 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.89%. Comparing base (34b0ab5) to head (da0883d).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop      #87   +/-   ##
========================================
  Coverage    74.89%   74.89%           
========================================
  Files           98       98           
  Lines         5047     5047           
  Branches       445      445           
========================================
  Hits          3780     3780           
  Misses        1267     1267           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces Rust bindings for the ECMWF gribjump C++ library, including a low-level gribjump-sys FFI layer and a safe gribjump wrapper crate, plus supporting tests/fixtures, examples, and benchmarks.

Changes:

  • Add gribjump-sys (cxx bridge + build script) to build/link gribjump (vendored or system).
  • Add gribjump safe wrapper API (handle, requests, iterator, results, error mapping).
  • Add integration/thread-safety/async tests, fixtures, examples, and Rust/C++ benchmarks.

Reviewed changes

Copilot reviewed 27 out of 32 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
rust/crates/gribjump/tests/gribjump_thread_safety.rs Thread-safety + concurrency tests (ignored runtime cases)
rust/crates/gribjump/tests/gribjump_integration.rs Integration tests that set up an FDB and validate wrapper behavior
rust/crates/gribjump/tests/gribjump_async.rs Tokio-based concurrent access tests (ignored by default)
rust/crates/gribjump/tests/fixtures/template.grib Added GRIB fixture
rust/crates/gribjump/tests/fixtures/synth11.grib Added GRIB fixture used for tests/benches
rust/crates/gribjump/tests/fixtures/schema Added FDB schema fixture
rust/crates/gribjump/tests/fixtures/extract_ranges.grib Added GRIB fixture for range extraction tests
rust/crates/gribjump/tests/fixtures/axes.grib Added GRIB fixture for axes tests
rust/crates/gribjump/src/result.rs Zero-copy result types + views + owned conversions
rust/crates/gribjump/src/request.rs Request/range types and conversion to FFI types
rust/crates/gribjump/src/lib.rs Crate module wiring + public re-exports
rust/crates/gribjump/src/iterator.rs Iterator wrapper over FFI extraction iterator
rust/crates/gribjump/src/handle.rs Thread-safe handle wrapper around the FFI handle
rust/crates/gribjump/src/error.rs Rust error type + mapping from cxx::Exception
rust/crates/gribjump/examples/gribjump_file.rs Example: scan + extract from file offsets
rust/crates/gribjump/examples/gribjump_extract.rs Example: build request + extract ranges
rust/crates/gribjump/examples/gribjump_basic.rs Example: version/git-sha + handle creation
rust/crates/gribjump/examples/gribjump_axes.rs Example: axes query
rust/crates/gribjump/benches/gribjump_bench.rs Criterion benchmarks for Rust wrapper
rust/crates/gribjump/benches/cpp/gribjump_bench.cpp Google Benchmark comparison using native C++ API
rust/crates/gribjump/benches/cpp/CMakeLists.txt CMake build for C++ benchmarks
rust/crates/gribjump/README.md Wrapper crate documentation
rust/crates/gribjump/Cargo.toml Wrapper crate manifest
rust/crates/gribjump-sys/src/lib.rs cxx::bridge definitions for FFI API surface
rust/crates/gribjump-sys/cpp/gribjump_bridge.h C++ bridge declarations + global try/catch mapping
rust/crates/gribjump-sys/cpp/gribjump_bridge.cpp C++ bridge implementation + conversions + validations
rust/crates/gribjump-sys/build.rs Vendored/system build + link configuration for the bridge
rust/crates/gribjump-sys/README.md Sys crate documentation
rust/crates/gribjump-sys/Cargo.toml Sys crate manifest + features
rust/Cargo.toml Rust workspace definition + shared deps
.gitignore Ignore Rust build artifacts/lockfile under rust/
.github/workflows/rust.yml.example Example CI workflow for Rust checks/tests/fmt/clippy

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread rust/crates/gribjump/tests/gribjump_thread_safety.rs Outdated
Comment thread rust/crates/gribjump/tests/gribjump_thread_safety.rs Outdated
Comment thread rust/crates/gribjump/tests/gribjump_thread_safety.rs Outdated
Comment thread rust/crates/gribjump/tests/gribjump_thread_safety.rs Outdated
Comment thread rust/crates/gribjump/tests/gribjump_async.rs Outdated
Comment thread rust/crates/gribjump/tests/gribjump_thread_safety.rs Outdated
Comment thread rust/crates/gribjump/tests/gribjump_thread_safety.rs Outdated
Comment thread rust/crates/gribjump/tests/gribjump_thread_safety.rs Outdated
Comment thread rust/crates/gribjump/src/request.rs
Comment thread rust/crates/gribjump/src/request.rs Outdated

@mathleur mathleur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, I just had one question/comment about the PathExtractionRequest constructor, which we might start using in Polytope in the future

Comment thread rust/crates/gribjump/src/request.rs Outdated
@caraghbiner

Copy link
Copy Markdown
Member

Hi @Choochmeque, just so you are aware there is a PR likely to be merged soon which cleans up of the gribjump source code. This involved moving and renaming some API headers, so will likely affect your work. It should be fairly easy to update the relevant paths in your implementation, but just letting you know in advance.

@Choochmeque

Copy link
Copy Markdown
Contributor Author

Hi @Choochmeque, just so you are aware there is a PR likely to be merged soon which cleans up of the gribjump source code. This involved moving and renaming some API headers, so will likely affect your work. It should be fairly easy to update the relevant paths in your implementation, but just letting you know in advance.

Hi @ChrisspyB,
Thank you for information. I will keep an eye on it.

Comment thread rust/Cargo.toml
gribjump = { path = "crates/gribjump" }

# FDB dependency
fdb = { git = "ssh://git@github.com/ecmwf/fdb.git", branch = "rust-bindings", default-features = false }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder note to switch this away from rust-bindings.

Comment thread rust/Cargo.toml
#[derive(Debug, Clone, Default)]
pub struct ExtractionRequestData {
/// MARS request string (e.g., "class=od,expver=0001,...")
pub request_str: String,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Placeholder note - this really ought to be a MarsRequest. Although it looks like gribjump is lagging there...

Comment thread rust/crates/gribjump/benches/cpp/gribjump_bench.cpp Outdated
Comment thread rust/crates/gribjump/benches/cpp/gribjump_bench.cpp Outdated
Comment thread rust/crates/gribjump-sys/cpp/gribjump_bridge.h
Comment thread rust/crates/gribjump-sys/cpp/gribjump_bridge.h
Comment thread rust/crates/gribjump-sys/cpp/gribjump_bridge.h
Comment thread rust/crates/gribjump-sys/build.rs Outdated
#[cfg(feature = "system")]
#[allow(clippy::too_many_lines)]
fn cmake_find_package(
package: &str,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this code that is going to need to be duplicated in all packages?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed via bindman-build crate.

Comment thread rust/crates/gribjump-sys/build.rs
sametd
sametd previously requested changes Apr 7, 2026

@sametd sametd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some minor comments

Comment thread rust/crates/gribjump-sys/cpp/gribjump_bridge.cpp Outdated
Comment thread rust/crates/gribjump-sys/cpp/gribjump_bridge.cpp Outdated
Comment thread rust/crates/gribjump-sys/build.rs Outdated
Comment thread rust/crates/gribjump/src/handle.rs Outdated
Comment thread rust/Cargo.toml
Comment thread rust/crates/gribjump/src/result.rs Outdated
Comment thread rust/crates/gribjump/src/request.rs
@Choochmeque Choochmeque marked this pull request as ready for review April 14, 2026 15:46
Comment thread rust/crates/gribjump/examples/fdb_gribjump.rs
@caraghbiner

Copy link
Copy Markdown
Member

Please rebase on the latest develop, all (py)gribjump tests should now pass the CI

@Choochmeque

Copy link
Copy Markdown
Contributor Author

Please rebase on the latest develop, all (py)gribjump tests should now pass the CI

All green now. Thanks!

@simondsmart simondsmart left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments that should be addressed. But fundamentally happy.

I would like some clarification about the Range question, but otherwise ready to merge when you are (re the comments)


// Set FDB5_CONFIG for GribJump
unsafe {
env::set_var("FDB5_CONFIG", &config);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still feels like it is in the wrong place relative to a function called setup_test_dir. Feels like hidden, magic, implicit behaviour. That were are (re)setting the env var needs to be made clear in the naming, or moved out to the calling function, or something.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9ca00fe.

assert!(results.iter().all(|(_, c)| *c == first_count));
println!("Concurrent axes: all tasks found {first_count} axis entries");

drop(gj);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unclear why the explicit drop calls are needed? This seems to be the natural drop order implied by the construction order?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 02533d2.


/// A range of indices to extract (start and end inclusive).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct Range {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we can't use std::Range here? Seems to carry the same functionality.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Validation - Range::new() rejects empty ranges at construction; std::ops::Range allows 5..3 silently
  • Copy - our Range is Copy; std::ops::Range is not (because it implements Iterator)
  • No clippy conflicts - vec![Range::new(0, 100)?] is unambiguous; vec![0..100] triggers single_range_in_vec_init
  • Interop - From<std::ops::Range> lets users write (0..100).into() when they want standard syntax (added in da0883d)

Comment thread rust/crates/gribjump/src/handle.rs Outdated

/// Get the gribjump library version.
#[must_use]
pub fn version() -> String {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that the version/git_sha1 functions belong to the GribJump struct.

They certainly belong somewhere in the crate (they are library-level info). But Not sure that they should be part of the object.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 62f9224.

@caraghbiner caraghbiner merged commit 62390b6 into develop May 4, 2026
141 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants