feat: migrate native-io implementation from C to Rust#4738
feat: migrate native-io implementation from C to Rust#4738nodece wants to merge 3 commits intoapache:masterfrom
Conversation
|
reopen to rerun CI |
There was a problem hiding this comment.
Pull request overview
This PR migrates the native-io JNI implementation from the existing C-based build (nar + assembly packaging) to a Rust cdylib, and updates Java-side library loading/build automation to embed the produced shared libraries in the module JAR.
Changes:
- Replaced the C JNI implementation with a Rust JNI implementation (
cdylib) and added a Rust build layout (Cargo files + build script). - Updated Java JNI library loading to support explicit-path overrides and candidate-based loading from JAR resources.
- Switched
native-iofromnarpackaging tojarpackaging and introduced acargo-zigbuild-driven Maven build flow; CI workflows were updated to install Rust targets.
Reviewed changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| native-io/src/test/java/org/apache/bookkeeper/common/util/nativeio/NativeIOLibraryPathTest.java | Adds unit tests for library path/candidate resolution and override precedence. |
| native-io/src/main/native-io-jni/rust/src/lib.rs | New Rust JNI implementation of the native I/O operations. |
| native-io/src/main/native-io-jni/rust/Cargo.toml | Declares the Rust cdylib crate and dependencies. |
| native-io/src/main/native-io-jni/rust/Cargo.lock | Locks Rust dependency versions for reproducible builds. |
| native-io/src/main/native-io-jni/rust/build.rs | Adds macOS install_name adjustment for produced dylibs. |
| native-io/src/main/native-io-jni/cpp/native_io_jni.c | Removes the legacy C JNI implementation. |
| native-io/src/main/java/org/apache/bookkeeper/common/util/nativeio/NativeIOLibraryPath.java | Introduces candidate resolution + explicit override path logic for JNI library loading. |
| native-io/src/main/java/org/apache/bookkeeper/common/util/nativeio/NativeIOJni.java | Updates static initialization to load from explicit path or iterate candidate resources. |
| native-io/src/main/assembly/assembly.xml | Removes the prior assembly-based packaging approach for native artifacts. |
| native-io/pom.xml | Switches packaging to JAR and adds cargo zigbuild + resource embedding steps. |
| .github/workflows/windows-daily-build.yml | Adds Rust toolchain/targets setup prior to Maven build. |
| .github/workflows/java21-daily-build.yml | Adds Rust toolchain/targets setup prior to Maven build. |
| .github/workflows/codeql.yml | Adds Rust toolchain/targets setup prior to Maven build/analysis. |
| .github/workflows/bk-streamstorage-python.yml | Adds Rust toolchain/targets setup for Maven build dependency chain. |
| .github/workflows/bk-ci.yml | Adds Rust toolchain/targets setup across CI jobs that run Maven builds. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
native-io/src/main/java/org/apache/bookkeeper/common/util/nativeio/NativeIOLibraryPath.java
Outdated
Show resolved
Hide resolved
native-io/src/main/java/org/apache/bookkeeper/common/util/nativeio/NativeIOLibraryPath.java
Outdated
Show resolved
Hide resolved
native-io/src/test/java/org/apache/bookkeeper/common/util/nativeio/NativeIOLibraryPathTest.java
Outdated
Show resolved
Hide resolved
native-io/src/main/java/org/apache/bookkeeper/common/util/nativeio/NativeIOJni.java
Outdated
Show resolved
Hide resolved
native-io/src/main/java/org/apache/bookkeeper/common/util/nativeio/NativeIOJni.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 15 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 16 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Motivation
The existing
native-iomodule is implemented in C and built using the NAR (Native ARchive) toolchain. This approach has several limitations:To improve maintainability and provide reliable multi-platform support, we migrate the native implementation and build system to a modern Rust-based toolchain.
Changes
1. Native implementation & build system
Replace the C-based implementation with a Rust-based shared library
Remove NAR-based build (
narpackaging and plugin)Introduce Rust build via
cargoandcargo-zigbuildAdd Maven profiles to:
Cross-compile for:
Package both variants into a single JAR
Add an optional pure Rust profile for local development (no cross-compilation)
2. CI/CD pipeline updates
Update GitHub Actions workflows to:
cargo-zigbuildEnsure consistent multi-architecture coverage across all CI jobs
3. Cleanup and dependency updates