engine/language_client_cffi/README.md
Internal FFI for the language client.
cargo install cargo-makecargo install cbindgenBuild the CFFI Layer for the Go SDK:
cd engine/language_client_cffi
# default
cargo make go-sdk
# release build
RELEASE_MODE=1 cargo make go-sdk
This command:
baml_cffi_generated.h for go-sdkbaml-clibaml-cli generate in integ testsBuild integration tests:
cd integ-tests/go
go build
./integ-tests
When developing changes to the CFFI layer, Go tests will by default download and use a cached version of the library from GitHub releases. To test your local changes:
Build the CFFI library (debug mode is faster for iteration):
cd engine/language_client_cffi
cargo build # or cargo build --release for optimized build
This creates: engine/target/debug/libbaml_cffi.dylib (macOS) or libbaml_cffi.so (Linux)
Run Go tests with your local library:
cd engine/generators/languages/go/generated_tests/dynamic_types # or any test directory
BAML_LIBRARY_PATH=/path/to/baml/engine/target/debug/libbaml_cffi.dylib go test -v
The BAML_LIBRARY_PATH environment variable tells the Go SDK to use your locally built library instead of the cached version.
Regenerate Go test code (if you've changed code generation):
cd engine/generators/languages/go
cargo test --lib # Regenerates all Go test projects
# 1. Make changes to Rust code
vim engine/language_client_cffi/src/ffi/functions.rs
# 2. Rebuild CFFI
cd engine/language_client_cffi && cargo build
# 3. Test with your changes
cd ../generators/languages/go/generated_tests/dynamic_types
BAML_LIBRARY_PATH=$PWD/../../../target/debug/libbaml_cffi.dylib go test -v
Note: Without setting
BAML_LIBRARY_PATH, Go tests will use the cached library at~/.cache/baml/libs/{VERSION}/or download from GitHub releases, which won't reflect your local changes.
Note: The actual go-sdk lives in ../language_client_go. The CFFI layer is a thin wrapper around the go-sdk.
For further details on configuration and advanced usage, please refer to the corresponding cargo-make tasks defined in your project configuration files or the Go project documentation in the integ-tests/go directory.