ffi: generate sandlock.h with cbindgen#87
Merged
Conversation
Signed-off-by: Cong Wang <cwang@multikernel.io>
Signed-off-by: Cong Wang <cwang@multikernel.io>
dzerik
added a commit
to dzerik/sandlock
that referenced
this pull request
Jun 2, 2026
Header is now cbindgen-generated (upstream switched in multikernel#87). The manual header edits from the original Protection commits are dropped; the C ABI for the Protection setters is regenerated from the #[no_mangle] Rust definitions instead. CI verifies the committed header matches a fresh generation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Replaces the hand-maintained
crates/sandlock-ffi/include/sandlock.hwith one generated from the crate's#[no_mangle]exports by cbindgen, and adds a CI gate so the header can never drift from the source again.Why
While reviewing the Go SDK (#83), the C header was found to be both stale and divergent: it declared only 50 of the 69 symbols the bindings call, and a class of latent type mismatches had crept in (for example boolean setters that the header, Rust, and Python all spell
boolbut which other consumers had transcribed asunsigned char). The header was curated by hand for the handler docs and was not kept in lockstep with the builder, lifecycle, and dry-run surfaces. Generating it makes it authoritative and complete, so downstream consumers (the C test, and a future Go binding) can#includeit instead of re-transcribing prototypes.How
crates/sandlock-ffi/cbindgen.toml: cbindgen config. Opaque#[repr(C)]wrappers and foreign sandlock-core types are forward-declared; the two action/exception enums are force-emitted (they are referenced from Rust only viaas u32casts, so cbindgen would otherwise drop them); type and enum-variant renames preserve the established C names (sandlock_builder_t,SANDLOCK_EXCEPTION_KILL,SANDLOCK_ACTION_INJECT_FD_SEND, ...).src/handler/abi.rs:sandlock_handler_newnow spells its two callback parameters as inlineOption<extern "C-unwind" fn(...)>rather than via thesandlock_handler_fn_t/sandlock_handler_ud_drop_taliases. A type alias is the same type to Rust, so this is ABI-identical and the body is unchanged, but cbindgen only flattensOption<fn>into a nullable C function pointer when thefnis written inline;Option<NamedAlias>is emitted as an uncallable opaque by-value struct. The aliases remain in use by the struct fields and the Rust tests..github/workflows/ci.yml: acbindgen-headerjob regenerates the header and fails on any diff from the committed copy.build.rs: comment updated to reflect generation (the build still does not run cbindgen, so a plaincargo buildneeds no extra tooling)..gitignore: keep tracking the generated header while still ignoring other artifacts underinclude/.Verification
crates/sandlock-ffi/tests/c/handler_smoke.ccompiles against it unchanged, confirming the C names and the now-callablesandlock_handler_newsignature.libsandlock_ffi.so, and every exportedsandlock_symbol is declared in the header.cargo test -p sandlock-ffi: 49 passed (the handler-interception tests exercise the touched ABI). The only failure is the preexisting libLLVM doctest stub issue on this host, unrelated to the change.🤖 Generated with Claude Code