Skip to content

feat(cffi): publish generated V1 C ABI - #4055

Merged
hellovai merged 11 commits into
canaryfrom
codex/public-cffi-abi
Jul 16, 2026
Merged

hellovai merged 11 commits into
canaryfrom
codex/public-cffi-abi

Conversation

@hellovai

@hellovai hellovai commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Changes

  • publish crates/bridge_cffi/include/baml_cffi.h as the canonical C/C++ contract for baml_get_api_v1
  • make Rust ABI declarations authoritative via pinned, deterministic cbindgen generation and checked-in drift tests
  • document practical ownership, lifetime, threading, panic, and V1 evolution rules next to the public declarations
  • verify enum widths/discriminants, structure size/alignment/offsets, table order, function signatures, and calling conventions from Rust, C11, and C++17
  • add C and C++ dynamic-loader smoke consumers that resolve only baml_get_api_v1, validate the table, call version, and release its buffer
  • run the public-header smoke in the existing bridge CFFI release workflow on Linux, macOS, and Windows/MSVC

Testing

  • cargo fmt --all --check
  • cargo test -p bridge_cffi
  • cargo clippy -p bridge_cffi --all-targets -- -D warnings
  • cargo check -p bridge_cffi --target wasm32-unknown-unknown
  • strict C11 and C++17 compile/layout tests
  • macOS C and C++ runtime smoke against libbridge_cffi.dylib
  • repository pre-commit hooks

Summary by CodeRabbit

  • New Features
    • Introduced a stricter, versioned public C/C++ ABI contract with explicit ABI versioning, compatibility validation, and a typed function-table surface (including updated exported naming and stable enum discriminants).
  • Tests
    • Added compile-time ABI assertions, cross-language ABI layout verification, deterministic public header generation checks, and a new ABI smoke test that dynamically loads a bridge and validates required entrypoints.
  • Documentation
    • Clarified FFI buffer ownership/release expectations and expanded ABI/status documentation.
  • CI / Chores
    • Updated ABI smoke workflow to use the new runner and removed the legacy smoke script; standardized test runs on Windows to suppress profiling output.

@cursor

cursor Bot commented Jul 16, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@vercel

vercel Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
beps Ready Ready Preview, Comment Jul 16, 2026 9:36am
promptfiddle Ready Ready Preview, Comment Jul 16, 2026 9:36am
promptfiddle2 Ready Ready Preview, Comment Jul 16, 2026 9:36am

Request Review

@github-actions

Copy link
Copy Markdown

⏭️ Performance benchmarks were skipped

Perf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to canary/main.

To run them on this PR, do any of the following, then push a commit (or re-run CI):

  • Add RUN_CODSPEED=1 to the PR description, or
  • Include run-perf or /perf in the PR title or any commit message.

@vercel
vercel Bot temporarily deployed to Preview – beps July 16, 2026 06:41 Inactive
@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The bridge CFFI surface now has a generated versioned C/C++ ABI header, explicit Rust callback and function-pointer types, cross-language layout assertions, deterministic header checks, and dynamic smoke tests that resolve baml_get_api_v1 and verify the product version. The Windows standard test workflow also disables incidental profiling output.

Changes

CFFI ABI contract and validation

Layer / File(s) Summary
Versioned ABI contract and generated header
baml_language/{Cargo.toml,crates/bridge_cffi/Cargo.toml}, baml_language/crates/bridge_cffi/{cbindgen.toml,include/baml_cffi.h,src/api.rs}
Defines the versioned append-only API table, public enums, callback types, export rules, calling conventions, and generated header contract.
Rust ABI wiring and ownership contracts
baml_language/crates/bridge_cffi/src/{buffer.rs,lib_native.rs}, baml_language/crates/bridge_cffi/src/ffi/*
Aligns callback re-exports and host-release signatures, expands public exports, and documents buffer, status, and bridge metadata boundary rules.
C and C++ ABI layout validation
baml_language/crates/bridge_cffi/tests/{abi_assertions.h,abi_layout.*,header_generation.rs}
Adds compile-time and runtime checks for ABI widths, discriminants, field layouts, function-pointer types, generated-header determinism, and Rust representation attributes.
Header-based dynamic smoke flow
baml_language/crates/bridge_cffi/tests/{abi_smoke.c,run_abi_smoke.py}, .github/workflows/build2-bridge-cffi.reusable.yaml
Builds C11/C++17 consumers, loads the shared library, validates the API table, calls version(), and compares both observed versions with release-plan.json.

Windows test profile

Layer / File(s) Summary
Disable default profiling output
.github/workflows/cargo-tests.reusable.yaml
Sets BAML_PROFILE to 0 for the standard Windows cargo test step and documents the profiling behavior.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

Sequence Diagram(s)

sequenceDiagram
  participant SmokeRunner
  participant CConsumer
  participant CppConsumer
  participant BridgeLibrary
  SmokeRunner->>CConsumer: compile and execute public-header consumer
  SmokeRunner->>CppConsumer: compile and execute public-header consumer
  CConsumer->>BridgeLibrary: resolve baml_get_api_v1
  CppConsumer->>BridgeLibrary: resolve baml_get_api_v1
  BridgeLibrary-->>CConsumer: return compatible BamlApiV1
  BridgeLibrary-->>CppConsumer: return compatible BamlApiV1
  CConsumer->>BridgeLibrary: call version and free buffer
  CppConsumer->>BridgeLibrary: call version and free buffer
  SmokeRunner-->>SmokeRunner: compare observed versions with expected version
Loading

Poem

I’m a rabbit with headers, hopping ABI-wide,
C and C++ consumers now run side by side.
Tables stay ordered, versions ring true,
Buffers are freed as they’re meant to do.
baml_get_api_v1 leads the way—
Hop, compile, smoke, and yay! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.75% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: publishing the generated V1 C ABI for bridge_cffi.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/public-cffi-abi

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

Binary size checks passed

✅ 7 passed

Artifact Platform File Gzip Gated on Baseline Delta Status
✅ baml-cli Linux 🔒 22.8 MB 9.7 MB file 22.8 MB +66.0 KB (+0.3%) OK
✅ packed-program Linux 🔒 16.3 MB 6.8 MB file 16.3 MB +24.6 KB (+0.2%) OK
✅ baml-cli macOS 🔒 17.6 MB 8.5 MB file 17.5 MB +49.7 KB (+0.3%) OK
✅ packed-program macOS 🔒 12.6 MB 6.0 MB file 12.6 MB +32 B (+0.0%) OK
✅ baml-cli Windows 🔒 19.2 MB 8.7 MB file 18.7 MB +425.5 KB (+2.3%) OK
✅ packed-program Windows 🔒 13.5 MB 6.1 MB file 13.5 MB +5.6 KB (+0.0%) OK
✅ bridge_wasm WASM 15.2 MB 🔒 4.3 MB gzip 4.3 MB +4.6 KB (+0.1%) OK

🔒 = the size this artifact is GATED on (ceiling + delta). Binaries gate on file size (installed binary); WASM gates on gzip (download size). The other size is shown for information only.


Generated by cargo size-gate · workflow run

@vercel
vercel Bot temporarily deployed to Preview – beps July 16, 2026 06:48 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 July 16, 2026 06:56 Inactive
@hellovai
hellovai enabled auto-merge July 16, 2026 06:59
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle July 16, 2026 07:09 Inactive
@vercel
vercel Bot temporarily deployed to Preview – beps July 16, 2026 07:12 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 July 16, 2026 07:18 Inactive
@vercel
vercel Bot temporarily deployed to Preview – beps July 16, 2026 07:31 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 July 16, 2026 07:38 Inactive
@vercel
vercel Bot temporarily deployed to Preview – beps July 16, 2026 07:49 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 July 16, 2026 07:56 Inactive
@vercel
vercel Bot temporarily deployed to Preview – beps July 16, 2026 08:10 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 July 16, 2026 08:17 Inactive
@vercel
vercel Bot temporarily deployed to Preview – beps July 16, 2026 08:26 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 July 16, 2026 08:32 Inactive
@vercel
vercel Bot temporarily deployed to Preview – beps July 16, 2026 08:42 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 July 16, 2026 08:49 Inactive
@vercel
vercel Bot temporarily deployed to Preview – beps July 16, 2026 08:55 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 July 16, 2026 09:02 Inactive

This branch was previously deployed

3 inactive deployments
Preview – promptfiddle — a2ed2cf0 Deployed Jul 16, 2026 by vercel[bot]
Preview – promptfiddle2 — a2ed2cf0 Deployed Jul 16, 2026 by vercel[bot]
Preview – beps — a2ed2cf0 Deployed Jul 16, 2026 by vercel[bot]
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