Skip to content

abi: verify public declarations against the Rust FFI - #115

Merged
Xuanwo merged 6 commits into
mainfrom
xuanwo/verify-c-abi-declarations
Nov 22, 2026
Merged

Xuanwo merged 6 commits into
mainfrom
xuanwo/verify-c-abi-declarations

Conversation

@Xuanwo

@Xuanwo Xuanwo commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Adds a check-abi target, run on the shared Ubuntu CI build, that generates declarations from the production Rust FFI with pinned cbindgen 0.29.4 and compares them with include/lancedb.h through clang ASTs and record layouts.

The comparison covers every #[no_mangle] extern "C" export, function return types, ordered arguments, pointer indirection, callback signatures, public by-value struct field types/order/offsets/size/alignment, and public enumerator names and values. Opaque handles are compared by identity; header-only static inline helpers are excluded. Enumerator order is ignored, while the C LANCEDB_* names are checked against the canonical names of the Rust variants.

The check runs for the host data model and for the Windows MSVC LLP64 Clang target using Clang resource headers. The target check does not build a Windows Rust library. Deliberate differences remain narrow and named:

Temporary fixtures cover signature, enum-name, wrong-enum, and pure _Alignas layout drift. A focused unsigned long long → unsigned long fixture passes the host LP64 check and fails the LLP64 check, so a Windows-only return-value break is not hidden.

Validation:

Limits: this is a declaration check for the host and Windows data models, not a native MSVC link/run test. Native C17 consumer jobs are platform runtime smoke tests rather than full declaration coverage; MSVC C17 CI remains owned by #107. This slice does not add export restrictions, version introspection, release packaging or runtime changes.

Refs #99. #99 stays open for the remaining slices.

Add a check-abi target that generates declarations from the production Rust FFI with pinned cbindgen and compares them with the hand-written header using clang ASTs and record layouts. It checks extern function names, return types, ordered arguments, pointer indirection, callback signatures, public struct layout and enum values, with narrow exceptions for checked c_int inputs and read-only result views.

Run the check on the shared Ubuntu CI build and include temporary signature and layout drift fixtures so a parser or comparison regression is visible.

Refs #99
LanceDBIndexStatistics exposes borrowed const C strings while Rust keeps the owned pointers private for Drop, the same deliberate const view already recorded for LanceDBIndexInfo. The object layout and calling ABI are unchanged.
Run the declaration check against the host and the Windows MSVC LLP64 Clang target so LP64-equivalent spellings cannot hide an LLP64 ABI break. The target check uses Clang resource headers and a temporary empty stdlib.h shim, without building a Windows Rust library.

Compare enumerator names as well as values, canonicalizing Rust variant names to the public LANCEDB_* spelling while ignoring declaration order. Make every checked c_int allowance name its expected C enum, including the #103 create-index API, and reject a wrong enum. Prove the layout comparison independently with an _Alignas-only fixture and require the exact offset diagnostic. Add a long-return fixture that passes on LP64 and fails on LLP64.
@Xuanwo
Xuanwo merged commit bdec217 into main Nov 22, 2026
10 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.

1 participant