Skip to content

Explore a Rust interface for CCF applications - #8200

Draft
Amaury Chamayou (achamayou) wants to merge 17 commits into
mainfrom
achamayou-rust-interface-exploration
Draft

Explore a Rust interface for CCF applications#8200
Amaury Chamayou (achamayou) wants to merge 17 commits into
mainfrom
achamayou-rust-interface-exploration

Conversation

@achamayou

@achamayou Amaury Chamayou (achamayou) commented Aug 24, 2026

Copy link
Copy Markdown
Member

Summary

This draft explores what it would take to support native CCF applications written in Rust while keeping the integration boundary small and explicit.

It introduces:

  • a C ABI bridge between the CCF host and Rust application code;
  • an initial ccf-app Rust crate for endpoint registration, request and response handling, authentication selection, and raw-byte KV access;
  • CMake support for building and packaging Rust applications alongside native CCF applications;
  • a basic Rust records application, end-to-end test coverage, and user documentation.

Goal

The goal is to evaluate the viability and ergonomics of Rust as another native CCF application language without exposing C++ implementation details across the boundary. The proposed API deliberately starts small so that ownership, lifetime, panic containment, transaction, concurrency, and packaging concerns can be reviewed before expanding the surface area.

Exploration status

This is exploratory work, not a commitment to a stable or production-supported Rust SDK. The current interface intentionally omits advanced endpoint configuration, custom authentication policies, historical queries, indexing, and commit callbacks. Feedback is especially welcome on the ABI design, safety guarantees, SDK ergonomics, and long-term maintenance implications.

This replays the work from achamayou/CCF#107 onto the current microsoft/CCF main branch so it can be discussed and evaluated in the upstream repository.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Introduces exploratory Rust support for native CCF applications through a C ABI bridge and Rust SDK.

Changes:

  • Adds endpoint, authentication, response, and raw KV APIs.
  • Adds Cargo/CMake integration and packaging.
  • Adds a sample application, E2E coverage, documentation, and changelog entry.

Custom instructions used

  • .github/copilot-instructions.md
  • .github/instructions/changelog.instructions.md
  • .github/instructions/reviewing.instructions.md

Reviewed changes

Copilot reviewed 17 out of 19 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
CHANGELOG.md Announces Rust application support.
CMakeLists.txt Installs Rust sources and registers the E2E test.
cmake/ccf_app.cmake Adds the Rust application build helper.
cmake/gersemi_definitions.cmake Registers the helper for CMake formatting.
include/ccf/rust_ffi.h Defines the public C ABI.
src/rust/app_bridge.cpp Implements the C++ bridge and endpoint registry.
src/rust/ccf-app/Cargo.toml Defines the Rust SDK crate.
src/rust/ccf-app/Cargo.lock Locks the SDK crate.
src/rust/ccf-app/src/lib.rs Implements the Rust-facing API and handlers.
samples/CMakeLists.txt Includes the Rust sample.
samples/apps/basic_rust/CMakeLists.txt Builds the sample application.
samples/apps/basic_rust/Cargo.toml Defines the sample crate.
samples/apps/basic_rust/Cargo.lock Locks sample dependencies.
samples/apps/basic_rust/rust-toolchain.toml Pins Rust 1.90.
samples/apps/basic_rust/src/lib.rs Implements records and health endpoints.
tests/basic_rust.py Exercises authentication and KV behavior.
doc/build_apps/index.rst Adds Rust to the application overview.
doc/build_apps/get_started.rst Links Rust build guidance.
doc/build_apps/example_rust.rst Documents the initial Rust interface.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/rust/app_bridge.cpp Outdated
Comment thread cmake/ccf_app.cmake Outdated
Comment thread src/rust/ccf-app/src/lib.rs
Comment thread doc/build_apps/example_rust.rst Outdated
Comment thread doc/build_apps/example_rust.rst Outdated
Comment thread include/ccf/rust_ffi.h Outdated
@achamayou
Amaury Chamayou (achamayou) force-pushed the achamayou-rust-interface-exploration branch from b50fb7c to 66b1b47 Compare August 26, 2026 14:42
Copilot AI and others added 11 commits August 28, 2026 15:05
Co-authored-by: achamayou <4016369+achamayou@users.noreply.github.com>
Co-authored-by: achamayou <4016369+achamayou@users.noreply.github.com>
Co-authored-by: achamayou <4016369+achamayou@users.noreply.github.com>
Co-authored-by: achamayou <4016369+achamayou@users.noreply.github.com>
Co-authored-by: achamayou <4016369+achamayou@users.noreply.github.com>
Co-authored-by: achamayou <4016369+achamayou@users.noreply.github.com>
Co-authored-by: achamayou <4016369+achamayou@users.noreply.github.com>
Co-authored-by: achamayou <4016369+achamayou@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Preserve compaction retry semantics, reject unsupported HTTP status codes, and keep the CI test bucket inventory in sync.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Stabilize the C ABI, preserve Cargo dependency tracking, register Rust unit tests, enforce unwind panics, and clarify native application trust semantics.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 20 out of 22 changed files in this pull request and generated 5 comments.

Comment thread CHANGELOG.md Outdated

- C++ endpoints can now use `ccf::endpoints::Endpoint::add_openapi_response<Out>()` to document additional HTTP responses in their generated OpenAPI schema without changing the endpoint's primary success response (#8115).
- New `ledger.max_transaction_size` node configuration option (default `32MB`), which caps the total serialised size of transactions written to the ledger. The limit covers the whole ledger entry: the fixed 8-byte ledger entry header, the ledger encryption header, public domain size field, public domain and encrypted private domain. It is checked before a transaction is applied, so an oversized transaction is now rejected with `413 Payload Too Large` and error code `TransactionTooLarge`, and subsequent transactions are unaffected, where previously an excessively large transaction could terminate the node. Reserved internal signature transactions are exempt because they must fill their reserved ledger version. The limit applies only to newly serialised non-reserved transactions; deserialising existing entries (including during recovery), historical queries and snapshots are unaffected, so entries written under a larger or unset limit remain readable. It must be smaller than `memory.max_msg_size` by at least the ring-buffer range response overhead, which is validated at node startup and by `--check` (#7992).
- Native CCF applications can now be written in Rust through a minimal API for registering endpoints and accessing raw-byte KV maps (#8200).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Updated the release metadata to add the new unreleased 7.0.14 section above 7.0.13 and synced python/pyproject.toml to 7.0.14 (1019c22).

Comment thread src/rust/app_bridge.cpp
Comment thread src/rust/ccf-app/src/lib.rs Outdated
Comment on lines +241 to +245
status: if (400..=599).contains(&status) {
status
} else {
500
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Addressed by validating status against the known HTTP error status set in HTTP_STATUS_MAP in EndpointError::new in 941258d.

Comment on lines +50 to +54
Request, response, transaction, and map values borrow the callback context and
cannot be retained. The SDK requires Rust's ``unwind`` panic strategy so that
panics are caught at the ABI boundary and become HTTP 500 errors. Builds using
``panic = "abort"`` are rejected. C++ exceptions are also contained by the
bridge.
let endpoint_error = match result {
Ok(Ok(())) => return RawResult::Ok as i32,
Ok(Err(error)) => error,
Err(_) => EndpointError::internal("Rust endpoint panicked"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixed in 005256d5c by adding a panic-triggering /app/panic sample endpoint and extending tests/basic_rust.py to assert a 500 from the panic path followed by a healthy /app/health response.

Copilot AI and others added 3 commits August 29, 2026 08:52
Co-authored-by: achamayou <4016369+achamayou@users.noreply.github.com>
Co-authored-by: achamayou <4016369+achamayou@users.noreply.github.com>
Co-authored-by: achamayou <4016369+achamayou@users.noreply.github.com>
Co-authored-by: achamayou <4016369+achamayou@users.noreply.github.com>
Co-authored-by: achamayou <4016369+achamayou@users.noreply.github.com>
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.

3 participants