Skip to content

feat(native): add baml_rust_workspace BEP-092 codegen and stub baml_native_rt crate - #5869

Open
hellovai wants to merge 1 commit into
feat/rust-crate-syntaxfrom
feat/native-codegen
Open

hellovai wants to merge 1 commit into
feat/rust-crate-syntaxfrom
feat/native-codegen

Conversation

@hellovai

@hellovai hellovai commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Stack (on top of kai/mir-stack-rebased)

  1. bcu: add baml_bcu crate and move PackageInterface/BcuMeta out of TIR #5845 (claude/bcu-meta-rebased): baml_bcu crate + .bmeta
  2. bcu: add BcuModule (.bcu), parallel baml_mir_linker, and Salsa-free emit pipeline #5846 (claude/bcu-module-rebased): BcuModule (.bcu) + parallel baml_mir_linker + Salsa-free emit
  3. feat(lang,compiler,runtime): add //baml:in_class_only and baml.errors.Panic marker interface #5851 (feat/panic-interface): //baml:in_class_only and baml.errors.Panic marker interface
  4. feat(lang,compiler,runtime): migrate magic cleanup() to baml.Cleanup interface (BEP-093 Part 3) #5852 (feat/cleanup-interface): baml.Cleanup interface (BEP-093)
  5. refactor(stdlib,mir,vm): migrate pure stdlib builtins, Array callbacks, and ns_ops to pure BAML; simplify MIR builtins #5859 (feat/stdlib-pure-baml): Migrate pure stdlib builtins & Array callbacks to pure BAML
  6. feat(lang,compiler,runtime): rust items frontend (BEP-092 v4) #5863 (avery/rust-items): Rust items frontend (rust function, rust class, builtin function)
  7. feat(lang,bcu): add rust "<crate>" syntax and disjoint native metadata in BcuModule #5868 (feat/rust-crate-syntax): rust "<crate>" syntax + disjoint RustFnMeta/RustClassMeta in BcuModule
  8. feat(native): add baml_rust_workspace BEP-092 codegen and stub baml_native_rt crate #5869 (feat/native-codegen): baml_rust_workspace BEP-092 codegen + stub baml_native_rt + baml_bcu::mangle (this PR)
  9. feat(cranelift): vendor cranelift-codegen 0.138 with AArch64 LSE2 + x86_64 AVX 128-bit atomics #5849 (claude/cranelift-vendor-rebased): Vendor cranelift-codegen 0.138 + LSE2/AVX 128-bit atomics
  10. feat(cranelift,bex2): add Cranelift AOT backend, bex2 M:N runtime, and baml pack --native #5850 (claude/cranelift-bex2-rebased): Cranelift AOT backend + bex2 M:N runtime + real BEP-092 C ABI + baml pack --native

Summary

Stacked on #5868 (feat/rust-crate-syntax). Implements the BEP-092 v4 Rust native workspace generator (baml_rust_workspace), collision-free shared symbol mangling (baml_bcu::mangle), and zero-dependency stub runtime types (baml_native_rt). Library + tests only (no CLI changes, no VM changes, all scaffolded crate methods panic with todo!()).

Changes

  • baml_bcu::mangle: injective, length-prefixed C/linker symbol mangling (mangle_rust_free_fn → __baml_rust_F_..., mangle_rust_method → __baml_rust_M_..., reserving _I_ for future ImplMethod), with invertible demangler round-trip tests.
  • baml_native_rt: zero-dependency, zero-unsafe stub crate defining BEP-092 public API types (RawVal, BamlCtx, Scope, AsyncScope, Root, Ref, Type, Thrown, BigInt, marker ZSTs) with compile-time Send/Sync proofs and #[doc(hidden)] pub mod __glue todo!() stubs.
  • baml_rust_workspace: Salsa-free generator consuming (&BcuModule, &[&BcuMeta], &CodegenOptions) directly (no extra IR layer, zero .bmeta / VM edits):
    • RustWorkspacePlan: resolves all 4 owners (root free fn, nested namespace free fn, plain class static/self methods, rust class static/self methods), all 4 async × gc modes, all 4 throws shapes (plain throws never returns R directly; <FnName>Error with <FnName>Throws fallback when colliding with a BAML class like baml.json.DecodeError), visible is_panic classes, cross-package dep .bmetas, and external_crates.
    • Emits the full baml_native/ Cargo workspace:
      • Cargo.toml (members = ["crates/*", "generated/*"], written only if absent)
      • generated/common_bindings/ (baml_common_bindings_<pkg>): shared types, enums, C::Instance, C::Owned, Panic<'s>, OwnedPanic, OwnedThrow, GcThrow, and imported dep types
      • generated/bindings_<crate>/ (baml_bindings_<pkg>_<crate>): Option-1 merged re-exports + per-crate Rust traits and error enums
      • generated/glue_<crate>/ (baml_glue_<pkg>_<crate>, rlib): #[unsafe(no_mangle)] pub extern "C" shims invoking the generated traits
      • crates/<crate>/ (baml_native_<pkg>_<crate>): non-destructive scaffolds with todo!() bodies
    • sync_workspace_to_disk: idempotent writer skipping unchanged files and pruning stale generated/ crates without clobbering author edits.
  • Tests & Snapshots:
    • crates/baml_rust_workspace/tests/codegen_e2e.rs + 5 insta snapshots: full multi-crate matrix, split namespace/class across crates, Rust keywords, cross-package .bmetas, idempotent sync/pruning, strict //rust:gc enforcement, external_crates, and real cargo check --offline --workspace.
    • crates/baml_tests/tests/native_codegen_e2e.rs: end-to-end .baml → ProjectDatabase → BcuModule → baml_rust_workspace → cargo check --offline --workspace on both a multi-crate .baml package and the entire real baml stdlib (~458 rust functions).

Verification

  • cargo fmt --check, mise run stow, mise run clippy (0 warnings)
  • baml_bcu (11/11), baml_native_rt (1/1), baml_rust_workspace (4/4), baml_tests --test native_codegen_e2e (2/2) all passing.

@vercel

vercel Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
developer-docs Ready Ready Preview Dec 4, 2026 6:01pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0bbf0314-162b-4727-8749-fab6f709e396

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@blacksmith-sh

blacksmith-sh Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Found 18 test failures on Blacksmith runners:

Failures

Test View Logs
Anthropic Provider/Anthropic Provider should support anthropic shorthand View Logs
Anthropic Provider/
Anthropic Provider Streaming should support anthropic shorthand streaming
View Logs
AWS Provider/
AWS Provider Dynamic Client Registry Credential Resolution should handle session creden
tials correctly
View Logs
AWS Provider/
AWS Provider Dynamic Client Registry should throw error when using temporary credential
s without session token
View Logs
Azure Provider/
Azure Provider should support o1 model with explicit max_completion_tokens
View Logs
Collector Tests/Collector Tests should track cached input tokens for Anthropic caching View Logs
Experimental OnTick/
Experimental OnTick should fire onTick callbacks for async non-streaming function
View Logs
Experimental OnTick/
Experimental OnTick should fire onTick callbacks for streaming function
View Logs
Experimental OnTick/Experimental OnTick should handle onTick callback errors View Logs
Experimental OnTick/Experimental OnTick should not significantly impact performance View Logs

...and 8 more test failures. View all on Blacksmith

Fix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

This branch was successfully deployed

1 active deployment
Preview – developer-docs — 60ea2c0f Deployed Dec 4, 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