Rust Protobuf Support

9 views
Skip to first unread message

Jingyun Liu

unread,
Dec 11, 2025, 6:29:22 PM12/11/25
to rust...@chromium.org
Hi rust-dev,

I'm trying to compile and generate a proto message in Rust so that it can be used as a deps in a rust lib that we want to build. I didn't find any existing `rust_proto_library` rules in the codebase, but I did find the rust protobuf compiler already exists.  
I'm wondering if there's any support for generating rust files from proto files, and if there's any examples to follow? If not, what's the recommended approach?

Thank you in advance,
- Jingyun

Łukasz Anforowicz

unread,
Dec 11, 2025, 6:32:47 PM12/11/25
to rust-dev, Jingyun Liu, Marcel Hlopko
There is no existing support in the Chromium build system for generating Rust bindings for protobufs.  If there is demand, then we can probably figure out together the path forward.  I assume that we would just mimic what google3 does, so let me /cc @hlopko, who I hope can help us figure out if/how we can try to reuse google3 protobuf/Rust integration in Chromium.

Jingyun Liu

unread,
Dec 12, 2025, 1:26:38 PM12/12/25
to Łukasz Anforowicz, rust-dev, Marcel Hlopko
Thank you for the quick reply! 

We use the Rust proto as a data container for our Rust parser to return serialized parsed results back to C++ (our directory cannot depend on //base, so we can't use json either)

I made some attempt to update the various build rules for rust in https://crrev.com/c/7254707, but I still cannot get it to build. Would really appreciate it if anyone could help!

- Jingyun

Łukasz Anforowicz

unread,
Dec 12, 2025, 2:50:21 PM12/12/25
to Jingyun Liu, rust-dev, Marcel Hlopko
I am not sure what exactly is the problem when trying `ninja.sh -C out/rel protoc-gen-rust`.  I see that 1) the `upb_reflection` target has `upb/reflection/stage0` in its `include_dirs` and 2) `upb_reflection` is in `public_deps` of `upb`, and 3) `upb` is in `deps` (I also tried changing this to `public_deps`) of the new `protoc_rust` target.  I think that maybe the `include_dirs` needs to be put into a `config` and then exposed as `public_configs` from `upb_reflection`?  Not sure, but let me try that quickly.

Jingyun Liu

unread,
Dec 17, 2025, 6:39:03 PM12/17/25
to Łukasz Anforowicz, Matthew Chan, rust-dev, Marcel Hlopko
I ended up making the "proto_rust" target compile on  https://crrev.com/c/7263449, but when building chrome, I still got a bunch of unsafe errors from the "//third_party/protobuf/rust:protobuf" target... So we started looking at other ways to pass data from rust to c++ that doesn't use proto  (e.g, opaque cxx rust type)

Also cc @Matthew Chan  who was having some issue building the OSS rust protobuf on windows, in case this thread could help in the future.


- Jingyun

Reply all
Reply to author
Forward
0 new messages