Skip to content

feat(go): add generated SDK and standalone runtime release - #4067

Merged
hellovai merged 30 commits into
canaryfrom
codex/go-baml-bridge-primitives
Jul 17, 2026
Merged

feat(go): add generated SDK and standalone runtime release#4067
hellovai merged 30 commits into
canaryfrom
codex/go-baml-bridge-primitives

Conversation

@hellovai

@hellovai hellovai commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add the Go SDK generator with canonical naming, package routing, classes, enums, aliases, containers, nullability, optional arguments, and collision-safe generated identifiers
  • add the dynamically loaded bridge_cffi Go runtime with verified release-manifest artifact resolution
  • wire Go generation into baml-cli generate and port the initial compile/runtime SDK fixtures
  • publish github.com/boundaryml/baml-go as a read-only module mirror with matching Canary/nightly v<language-version> tags
  • gate public manifests on Go publication and smoke a clean external consumer on Linux, macOS, and Windows

Release behavior

The shared BAML release plan stamps the Go module's required runtime version. For every future Canary or nightly release, the release workflow:

  1. assembles and tests the standalone Go module
  2. pushes the exact contents to BoundaryML/baml-go
  3. creates the immutable v<canonical-version> tag atomically with main
  4. publishes baml_bridge_go in the public version manifest only after the tag succeeds
  5. generates and runs a basic BAML function from a fresh module with no replace directive or Rust toolchain

BAML_GO_DEPLOY_KEY and the write deploy key on BoundaryML/baml-go are configured. The already-published BAML 0.15.0 release is intentionally not backfilled with a new Go tag; the first Go release will be the next nightly, followed by the next bumped Canary.

Local validation

  • cargo test -p sdkgen_go (35 passed)
  • cargo nextest run -p sdk_test_go (6 passed)
  • standalone mirror go test ./...
  • standalone mirror go vet ./...
  • Canary and nightly isolated stamp/assemble/test checks
  • scripts/baml-language-version check
  • actionlint .github/workflows/release-baml-language.yml

Summary by CodeRabbit

  • New Features
    • Added Go SDK generation, including support for Go output targets, classes/enums/aliases, optional values, containers, and native runtime execution.
    • Added Go runtime artifact resolution with caching, checksum verification, offline reuse, and Linux/macOS/Windows support.
    • Enhanced release publishing with a Go SDK mirror, tagging, and cross-platform smoke testing.
  • Bug Fixes
    • Improved generated identifier handling to avoid reserved-word/name collisions (including TypeScript parameter binding correctness).
  • Documentation
    • Added comprehensive Go runtime documentation.
  • Tests
    • Expanded Go SDK, runtime, and cross-platform release validation coverage.

@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 17, 2026 4:33am
promptfiddle Ready Ready Preview, Comment Jul 17, 2026 4:33am
promptfiddle2 Ready Ready Preview, Comment Jul 17, 2026 4:33am

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.

@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

This PR adds Go SDK generation, a native Go runtime and value codecs, extensive Go SDK fixtures and harness coverage, cross-platform CI support, and release automation that mirrors, publishes, and smoke-tests the Go module.

Changes

Go SDK generation

Layer / File(s) Summary
Generator configuration and source emission
baml_language/crates/baml_cli/..., baml_language/sdks/go/sdkgen_go/..., baml_language/sdks/typescript/sdkgen_typescript_shared/...
Adds the Go generator target, validates Go import paths, emits Go packages, types, functions, codecs, and updates TypeScript parameter-name projection handling.

Go runtime and codecs

Layer / File(s) Summary
Native runtime and artifact loading
baml_language/sdks/go/baml_go/...
Adds the CFFI ABI header, Unix and Windows loaders, runtime calls, callback handling, artifact caching, downloads, validation, and version resolution.
Typed value codecs
baml_language/sdks/go/baml_go/{class,container,enum,optional,value}*
Adds scalar, enum, class, optional, list, and map encoding/decoding helpers with focused tests.

SDK test harness

Layer / File(s) Summary
Fixture generation and execution
baml_language/sdk_tests/...
Adds Go fixture generation, staged modules, platform setup scripts, harness execution, and broad function/type-shape round-trip coverage.

CI and releases

Layer / File(s) Summary
Cross-platform CI and release publication
.github/workflows/..., scripts/...
Adds Go test matrix entries, ABI smoke handling, module mirroring and publication, release manifest/version integration, and external Go release smoke tests.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI as baml-cli
  participant Generator as sdkgen_go
  participant SDK as Generated Go SDK
  participant Runtime as baml_go runtime
  participant Native as bridge_cffi
  CLI->>Generator: generate Go source with bytecode
  Generator-->>SDK: write functions, types, codecs, bootstrap
  SDK->>Runtime: call generated function
  Runtime->>Native: load runtime and invoke function
  Native-->>Runtime: callback result envelope
  Runtime-->>SDK: decoded Go value
Loading

Possibly related PRs

  • BoundaryML/baml#3489: Updates the SDK test matrix and Go SDK test-target discovery in the same reusable workflow.
  • BoundaryML/baml#4041: Introduces the versioned CFFI API surface consumed by the Go native loader.
  • BoundaryML/baml#4060: Extends the same generator dispatch surface with another SDK target.

Poem

A rabbit found Go in the code garden bright,
With codecs and bridges all hopping just right.
It stamped every module, then bounded away,
Through Windows and Unix to release day.
“Hop!” cried the tests, as the pipelines grew—
A SDK moon rose in a very Go hue.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 31.72% 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 accurately summarizes the two main changes: generated Go SDK support and a standalone Go runtime release flow.
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/go-baml-bridge-primitives

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 🔒 25.1 MB 10.7 MB file 24.5 MB +617.9 KB (+2.5%) OK
packed-program Linux 🔒 17.0 MB 7.0 MB file 17.0 MB +0 B (+0.0%) OK
baml-cli macOS 🔒 19.4 MB 9.3 MB file 18.9 MB +529.0 KB (+2.8%) OK
packed-program macOS 🔒 13.2 MB 6.2 MB file 13.2 MB +0 B (+0.0%) OK
baml-cli Windows 🔒 20.9 MB 9.5 MB file 20.4 MB +521.7 KB (+2.6%) OK
packed-program Windows 🔒 14.1 MB 6.2 MB file 14.1 MB +0 B (+0.0%) OK
bridge_wasm WASM 16.0 MB 🔒 4.4 MB gzip 4.3 MB +93.0 KB (+2.2%) 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

@coderabbitai coderabbitai Bot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.github/workflows/build2-bridge-cffi.reusable.yaml (1)

81-106: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Restrict the matrix job’s token to read-only access.

This checkout-only job currently inherits the caller’s default permissions. Declare the minimum permission explicitly.

Proposed fix
   matrix:
     name: Compute target matrix
     runs-on: ubuntu-latest
+    permissions:
+      contents: read
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/build2-bridge-cffi.reusable.yaml around lines 81 - 106,
Restrict the matrix job’s GitHub token to read-only access by adding an explicit
permissions declaration to the matrix job containing only contents: read. Update
the job identified by the matrix name “Compute target matrix”; leave its
checkout and matrix-generation steps unchanged.

Source: Linters/SAST tools

🧹 Nitpick comments (1)
.github/workflows/cargo-tests.reusable.yaml (1)

748-753: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Prevent confusing workspace builds when WASM package discovery fails.

If cargo metadata or jq fails, readarray silently swallows the error and produces an empty array. This causes cargo build to execute without any -p flags, inadvertently building the entire workspace for WASM and failing with extremely misleading compilation errors.

Adding a check for an empty array improves CI debuggability by pinpointing the failure source immediately.

💡 Proposed check for empty array
           readarray -t wasm_packages < <(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.source==null) | select(if .metadata.ci.wasm_support == null then true else .metadata.ci.wasm_support end) | .name')
           package_args=()
           for package in "${wasm_packages[@]}"; do
             package_args+=(-p "$package")
           done
+          if [[ ${`#package_args`[@]} -eq 0 ]]; then
+            echo "Error: No WASM packages found. Did 'cargo metadata' or 'jq' fail?" >&2
+            exit 1
+          fi
           cargo build "${package_args[@]}" --target wasm32-unknown-unknown --no-default-features --release --timings
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/cargo-tests.reusable.yaml around lines 748 - 753, Validate
the wasm_packages result immediately after the cargo metadata/jq readarray in
the WASM build step, and fail with a clear error before constructing or invoking
cargo build when the array is empty. Keep the existing package_args construction
and targeted build behavior unchanged for successfully discovered packages.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In @.github/workflows/build2-bridge-cffi.reusable.yaml:
- Around line 81-106: Restrict the matrix job’s GitHub token to read-only access
by adding an explicit permissions declaration to the matrix job containing only
contents: read. Update the job identified by the matrix name “Compute target
matrix”; leave its checkout and matrix-generation steps unchanged.

---

Nitpick comments:
In @.github/workflows/cargo-tests.reusable.yaml:
- Around line 748-753: Validate the wasm_packages result immediately after the
cargo metadata/jq readarray in the WASM build step, and fail with a clear error
before constructing or invoking cargo build when the array is empty. Keep the
existing package_args construction and targeted build behavior unchanged for
successfully discovered packages.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c9279f9f-0657-4db1-afd7-51620a77bc1c

📥 Commits

Reviewing files that changed from the base of the PR and between be3f7c2 and 7fd82d3.

⛔ Files ignored due to path filters (1)
  • baml_language/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (13)
  • .github/workflows/build2-bridge-cffi.reusable.yaml
  • .github/workflows/cargo-tests.reusable.yaml
  • .github/workflows/release-baml-language.yml
  • baml_language/.config/nextest.toml
  • baml_language/Cargo.toml
  • baml_language/crates/baml_cli/Cargo.toml
  • baml_language/crates/baml_cli/src/generate.rs
  • baml_language/crates/baml_codegen_types/src/generator_fields.rs
  • baml_language/sdk_tests/harness_runner/src/lib.rs
  • baml_language/sdk_tests/harness_setup/Cargo.toml
  • baml_language/sdk_tests/harness_setup/src/lib.rs
  • scripts/baml-language-version
  • scripts/baml-release-manifests
🚧 Files skipped from review as they are similar to previous changes (9)
  • baml_language/crates/baml_codegen_types/src/generator_fields.rs
  • baml_language/sdk_tests/harness_setup/src/lib.rs
  • baml_language/Cargo.toml
  • baml_language/.config/nextest.toml
  • scripts/baml-release-manifests
  • baml_language/sdk_tests/harness_runner/src/lib.rs
  • baml_language/sdk_tests/harness_setup/Cargo.toml
  • baml_language/crates/baml_cli/src/generate.rs
  • baml_language/crates/baml_cli/Cargo.toml

@hellovai

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

…e-primitives

# Conflicts:
#	.github/workflows/release-baml-language.yml
#	baml_language/.config/nextest.toml
#	baml_language/Cargo.lock
#	baml_language/crates/baml_cli/Cargo.toml
#	baml_language/crates/baml_cli/src/generate.rs
#	baml_language/sdk_tests/harness_setup/src/lib.rs
@hellovai
hellovai dismissed coderabbitai[bot]’s stale review July 17, 2026 04:15

Superseded by fixes in 26d4e22 and the subsequent successful CodeRabbit review. All actionable threads are resolved; two withdrawn findings were verified against the current ABI/package model.

@hellovai
hellovai added this pull request to the merge queue Jul 17, 2026
Merged via the queue into canary with commit 7d9a665 Jul 17, 2026
63 checks passed
@hellovai
hellovai deleted the codex/go-baml-bridge-primitives branch July 17, 2026 04:35
addiplus added a commit to addiplus/baml that referenced this pull request Aug 13, 2026
The pydantic2 SDK generator emitted BAML identifiers verbatim, so an
enum member `None`, a class field `pass`, or a keyword class/enum/alias
name produced Python that fails to import with a SyntaxError (issue
BoundaryML#4059). Only free-function and method names were escaped previously.

Generalize the existing `escape_python_keyword` helper to every
Python-visible identifier site, mirroring the Go generator (PR BoundaryML#4067):
keep the raw BAML name on the wire, escape only the language-facing
spelling.

- enum members: `None` renders `None_ = "None"` (value stays the wire
  identity, so decode by value keeps working with no alias needed).
- class fields: `pass` renders `pass_: T = pydantic.Field(alias="pass")`
  and the class gains `populate_by_name=True` so it validates from both
  the escaped attribute and the raw JSON/wire key. Classes with no
  escaped field render byte-identically to before.
- class / enum / type-alias names, plus TypeVars, escape at the
  definition site AND at every cross-reference (translate_ty
  render_name_ref, Ty::TypeVar) so references stay in lockstep.
- collisions inside one scope resolve deterministically: a class or
  enum declaring both `pass` and `pass_` yields `pass__` and `pass_`.
- a debug-assert render-boundary guard panics on any identifier that
  reaches the emitter still a hard keyword (mirrors Go's assertion).

Out of scope (documented follow-ups): function/method parameter
renaming (wire-coupled, needs bridge alias plumbing) and routing.rs
module-segment generalization.

Adds exhaustive 35-keyword unit tests for enum members and class
fields, name/typevar escape + cross-reference agreement, collision
resolution, soft-keyword controls, and a byte-identical no-keyword
control. Keeps all 117 existing tests green (128 total).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.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.

1 participant