https://www.boundaryml.com logo
Rust + BAML
# general
v
starting a thread for rust work! @h256 @ceciliaz030
we can use thread for comms!
We’re gonna close this and start a new one branching off the baml repo
☐ - [ ] array_types - [ ] asserts - [ ] classes - [ ] edge_cases - [ ] enums - [ ] literal_types - [ ] map_types - [ ] media_types - [ ] mixed_complex_types - [ ] nested_structures - [ ] optional_nullable - [ ] primitive_types - [ ] recursive_types - [ ] sample - [ ] semantic_streaming - [ ] union_types_extended - [ ] unions @h256 for each type you passed in code gen check this off pls 😁
h
v
Nice!!
c
goated bro
a
we do own this crate: https://crates.io/crates/baml once we have the package working locally we can publish it there πŸ™‚
super exciting
oh interesting, you generate an actual baml-client-rust crate as well, neat
s
Awesome and about time πŸ™‚
h
Yes exactly we did implement the rust client to call the cffi, like other languagues e.g. go
Just one question regarding the CFFI, seems the decoder is still not supporting StreamingStateValue, and CheckedValue, which led some tests failed. Are there any specific reasons why they're not supported? https://github.com/BoundaryML/baml/blob/canary/engine/language_client_cffi/src/ctypes/baml_value_decode.rs#L96-L100
v
we just didn't need the decorder so far
cause no one was sending streamstate values to rust code before πŸ™‚
(ie. host language -> baml runtime)
now that hte host language is rust, we need to support it haha
h
yeah that makes sense. we will implement both in the pr
I've created a branch and pr with all our changes https://github.com/BoundaryML/baml/pull/2558 The code is running with all tests except those for media types such as PDF and video. it would be super helpful if you guys could take a look first to see if anything is missing. (There are still some ai-generated docs that help us to understand the code, which should be removed before merging)
v
Amazing. I’ll read it by EOD!
s
Love it
c
hi guys just run in to the runtime design problem where @Vaibhav (BAML πŸ‘) and us talked about
we curretnly use CFFI which we can potentiall just import
baml_runtime::BamlRuntime
in the client, which introduce the
Arc<tokio::runtime::Runtime>
from here https://github.com/BoundaryML/baml/blob/758e4ba09ba696061e4336c88a8053bb4638a725/engine/baml-runtime/src/lib.rs#L190
either way, CFFI isolation doesn't solve problem, we need to somehow access in the middle of our code
Copy code
match TOKIO_SINGLETON.get_or_init(|| tokio::runtime::Runtime::new().map(Arc::new)) {
            Ok(t) => Ok(t.clone()),
            Err(e) => Err(e.into()),
        }
ohh can we do
BamlRuntime::init_with_runtime(external_rt: Runtime)
? we might need to PR into the runtime module then
v
Sorry for the delay! Couldn’t finish reading yesterday. Should be done today.
c
@Vaibhav (BAML πŸ‘) when do u have time for another call
v
tmrw?
c
SG!
v
can do pretty early in the morning!
around 6 am PT?
c
@h256 does that work for u?
works for me
h
Yep works great for me !
@Vaibhav (BAML πŸ‘) hope you had a good trip! Regarding the baml_cffi lib, I did the adaptations to manage to call the dylib in our rust client, just like the go implementation. However, I realize we still need the rlib dependency because of the encoding/decoding parts from the
ctypes
, which I believe should be reused in the rust client to avoid any inconsistency. I therefore want to split the baml_cffi into 2 libs -
baml_cffi_types
implements all the encoding and decoding, and protobuf stuff as a rlib
baml_cffi
with dependency of
baml_cffi_types
, act the same as the FFI layer and built as a dylib. What do you think?
v
That’s a great idea. But I think we can also sym link the files/foldee?
The reason for a symlink is that it’s a flatter dependency over another crate
Making release pipelines simpler
h
Sounds good. but with simlink there will be still some unnecessary dependencies introduced to the client, e.g.
baml_runtime
, which is against our purpose of using dylib. I'll then probably copy the relevant code into the client, which makes things a bit easier.
In [this commit](https://github.com/BoundaryML/baml/pull/2558/commits/344943724bd127e77c2927d5544474feeea04a4b#diff-431acf7f2935eff88a99ed005fd9f8dc1070ddd085668193ddb440aa8b0e12e4) I copied the relevant implementation about serialization to our rust client, so that we don;t need all unnecessary dependencies like baml-runtime. Pls let me know if this makes sense.
v
looks pretty good here!
i think we can leave baml-types for now
and not worry about that yet
h
yep that should be fairly lightweight.
v
hi @h256 been trying to compile the code you have, but i'm not able to atm. what am I missing? It seems like there are some bespoke steps i should be running
for context:
Copy code
vbv@Vaibhavs-MacBook-Pro-2 rust % ../../engine/target/debug/baml-cli generate --from ../
2025-10-11T16:19:31.165 [BAML INFO] Generating clients with CLI version: 0.210.0
2025-10-11T16:19:31.697 [BAML INFO] Wrote 13 files to ../python/baml_client
2025-10-11T16:19:31.721 [BAML INFO] Wrote 13 files to ../python-v1/baml_client
2025-10-11T16:19:31.735 [BAML INFO] Wrote 13 files to ../typescript/baml_client
2025-10-11T16:19:32.035 [BAML INFO] Wrote 13 files to ../typescript-esm/baml_client
2025-10-11T16:19:32.055 [BAML INFO] Wrote 18 files to ../react/baml_client
2025-10-11T16:19:32.074 [BAML INFO] Wrote 6 files to ../ruby/baml_client
2025-10-11T16:19:32.122 [BAML INFO] Wrote 3 files to ../openapi/baml_client
2025-10-11T16:19:32.122 [BAML INFO] Running "rm .gitignore" in ../openapi/baml_client
2025-10-11T16:19:32.149 [BAML INFO] Wrote 19 files to ../go/baml_client
2025-10-11T16:19:32.149 [BAML INFO] Running "mise x -- gofmt -w . && mise x -- goimports -w . && mise x -- go mod tidy" in ../go/baml_client
2025-10-11T16:19:33.666 [BAML INFO] Wrote 6 files to ../rust/baml_client
2025-10-11T16:19:33.666 [BAML INFO] Running "cd .. && cargo fmt && cargo check" in ../rust/baml_client
2025-10-11T16:19:34.007 [BAML ERROR] Error generating clients: Client generation failed

Caused by:
    on_generate command finished with exit code 101: cd .. && cargo fmt && cargo check
    Stdout:
    
    Stderr:
        Checking baml-integ-tests-rust v0.1.0 (/Users/vbv/repos/baml-3/integ-tests/rust)
    error[E0425]: cannot find function `get_library_version` in module `baml_client_rust::ffi`
      --> src/main.rs:27:34
       |
    27 |     match baml_client_rust::ffi::get_library_version() {
       |                                  ^^^^^^^^^^^^^^^^^^^ not found in `baml_client_rust::ffi`
    
    For more information about this error, try `rustc --explain E0425`.
    error: could not compile `baml-integ-tests-rust` (bin "simple-test") due to 1 previous error
Error: Client generation failed
h
Ah yeah you are right. I didn't complete the dylib adaptation for the integ-tests yet. I'll fix this issue.
the
get_library_version()
error has been fixed. However it's still not passing some integration tests. Working on a fix
v
nice, thanks!
h
I've pushed a fix to the integration test issues. The errors were about the union naming issue in streaming types and the recursive alias generation. I use an opaque json
serde_json::Value
for the recursive alias now.
However this change breaks the unit tests recursive_types and edge_cases. Because in these tests, there are aliases used in union types. I'll find a nicer solution for these tests as well.
@Vaibhav (BAML πŸ‘) I've updated the code with a new implementation that detects cyclic alias and thereafter handle it with serde_json::Value, just like go does. Now all tests (integration & unit tests) are passing
pls let me know if it doesn't work on your side
v
will take a look today! thanks!
ok! this is looking great!
theres some small nuances about how we wanna handle literal types
i need to think about that more
cause technically its possible to construct invalid types currently
likely need either some validation or better checking
also i pushed some changes to make better support for dynamic enums
h
sry for the late reply.
Your changes look great!
yep, agree. pls feel free to start a conversation about this if we can work on it together.
c
@Vaibhav (BAML πŸ‘) when are we gonnna merge the Rust support 😁
we're gonna put it to use
a
Ill ping him, he s just been busy in a conference but lets move this forward!
Thank you so much for your patience and your contributions
a
Looking forward to rust support πŸ™‚
v
hey folks, sorry for the constant delay here. I've been traveling and just returned from paris.
I'm coding on this today to get back up to speed here and see whats missing and build out a checklist of everything thats left remaining. If possible, perhaps @h256 we can sync up this week based on your schedule? Happy to do very early morning to make it more convinient. I'll have a notion document ready for us to review by tmrw evening with a full checklist. I'll also have eng bandwidth myself to actually push this over the finish line.
c
sry for the late reply @Vaibhav (BAML πŸ‘) let's sync up! we're starting using baml heavily at this point, since the Rust code is not merge we're still using the OpenAPI, so it'd be great to get it done fully done
h
sounds great! let's talk together!
v
Let me find a time!
Booked for Wednesday my time!
c
@Vaibhav (BAML πŸ‘) how's the release pipeline?
we're waiting to integrate haha also we're gonna post hopefully tmr an X announcement shilling baml and our Rust work, it'd great if we like follow/like/repost each other
u
Hi all. Just wanted to introduce myself - I’m Shylia. I joined Cecilia's team on the marketing and growth side. Pleasure to meet you guys!
v
@.slyah πŸ‘‹πŸΎ nice to meet you!
@ceciliaz030 still working on some of the rust side. there are still a few edge cases I'm not yet happy with in the code-gen (i.e. streaming types) that i'm ironing out.
did you post?
I didn't see anything and didn't get the chance to repost it!!
if you ping me on here, i'll be around more on discord
u
@Vaibhav (BAML πŸ‘) we just pushed the post live! 😍 : https://x.com/aomi_labs/status/1996675475830104545
c
Thanks bro πŸ™ let us know if you need us to to fix more stuffs
would be great if anyone can like or repost 😁
Also watched ur event driven agent loop episode, im taking the inspiration to build the callbacks path of our async onchain execution
a
Thank you so much for writing this out! Im on vacation atm but will retweet and repost soon!
And also for your contributions ❀️
v
hi folks! Wanted to provide an update. I've been findign a few type-system bugs that was making rust porting hard (esp for streaming type). I've got 1 PR merged already that fixed it for Go + Py + TS: https://github.com/BoundaryML/baml/pull/2778 Doing this also fundamentally changed how Rust would work so I've been working here: https://github.com/BoundaryML/baml/pull/2832 What's working so far: 1. dynamic types 2. streaming 3. Most BamlOptions seem to working e2e. 4. Codegen for all types What's left: * codegen for functions * additional verification I'll start posting updates here every day until this is closed! I'm hoping its close!
hi folks! updates over the holidays: 1. Type systems seem to be working now! (unions, recursive type aliases, vectors, media types, etc) 2. collector works! Whats left: 3. exposing streaming interfaces
Ok! Updates. https://github.com/BoundaryML/baml/pull/2832 1. ClientRegistry works 2. async, sync, async streaming, sync streaming work 3. cancelations works What's next: 1. TypeBuilder 2. a few last incomplete methods on collector need to be plumbed
s
I am waiting on the edge of my seat for the rust implementation here, thank you for all the hard work and can't wait to integrate it into my rust app πŸ™‚
v
i can send instructions
btw if you really want to try it earlier, you can git clone the branch and run it locally!
a
Looking forward to it πŸ™‚
c
πŸ”₯ πŸ”₯ πŸ”₯
wow this is so exciting
Sry didn’t see this earlier cuz my discord channel is on mute haha But I’m trying it out today
Also is our earlier commits included or did u just refactor from scratch? I’m just curious πŸ‘€ @Vaibhav (BAML πŸ‘)
v
Had to do from scratch πŸ™
The types were quite funky for some of the edge cases (in particular the checked and streamstate types)
Out at a NYE party atm but I’ll post an update of how to run it locally!
ok update. Its pretty much done! all the features work as expected!! πŸ™‚
i'm gonna be doing basic clean up work tmrw (clippy-iness, formatting, minor cleanups)
but to play with it, heres what you can do yourself:
Copy code
bash
# Assuming you already have rust installed
git clone -b hellovai/rust-ffi git@github.com:boundaryml/baml.git
cd baml/languages/rust
./setup-ffi.sh
cd baml/engine
cargo build -p baml-cli
Then the project of your choice:
Copy code
bash
cd $my_project
# Add this to your projects cargo.toml 
baml = { path = "path/to/baml-repo-clone/languages/rust/baml", features = ["dev"] }
Copy code
ts
// Add a "rust" generator
generator my_client {
 output_type "rust"
 output_dir "../"
 version "0.216.0"
}
Copy code
bash
# run baml-cli generate
path/to/baml-repo-clone/engine/target/debug/baml-cli --from path/to/baml_src
Then it should just work!
I think we should be merging this in beta mode into the next release (By that we mean we may make a syntax change or two on the generated code as we get feedback from you all)
did it in oneshot with claude
also maybe you can let user optionally specify the need for stream type, otherwise there are so many types with the same name
a
maybe we can namespace the stream types elsewhere?
another user commented maybe we can add a setting to just make stream types the default via a setting, so you dont have to juggle 2 types nor converting between them
c
yea i think have a setting in the generation command makes sense
baml-cli generate --stream whatever
and the runtime doens't need to care cuz it's not affected
v
Sorry about the lack of updates here. * I had to swap to a .dylib instead of statically compiled .a file. * some weird recursive types had some issues (resolved) I’m writing a few more tests will update before bed tonight of final status.
ok as of now, I've added the cancellation apis and with_collectors as well. CI/CD is passing all tests! (I'm adding our final suite of integ-tests, but sadly not able to finish before bed).
hi folks, changes are merged in! release scripts should merge in today as well and todays release should have the first beta version of BAML!!
please note, its all beta
and we may break some interfaces over the next 3-4 releases as we learn more from you!
(you will still need to wait for EOD until the release actually goes out)
s
Incredible, thank you!
c
yeahhhhh!!!
v
just baml!
working on instructions / docs update once release goes out πŸ™‚
s
Officially releasing by tomorrow? πŸ™‚
a
it's released now!
thanks for all the patience, we'll update the docs soon
s
Btw just tested this in a real-world project and it's working great, thanks again for all the hard work here
a
Let us know if yall run into issues
a
Are there instructions for the rust sdk use? Came across the support PR
v
@baml-sam has been putting them together!