-
Notifications
You must be signed in to change notification settings - Fork 585
Description
It's hard to explain what I'm asking in abstract terms, but I'll try:
I want to make a crate that has my own proto message that uses messages from an external crate, and then be able to use the protos from both my crate and the external crate from Rust. Assume that both my crate and the external crate are using prost.
In case that didn't make any sense, here's a simple example to illustrate what I want. Suppose someone who is not me (let's call them Alice) owns a crate called freshfoods, which contains the following files:
freshfoods/src/seasoning.proto:
package freshfoods.seasoning;
// A tablespoon of salt
message Salt {}freshfoods/src/perishable.proto:
package freshfoods.perishable;
// A clove of garlic
message Garlic {}Alice is using prost in order to expose these protobufs as simply as possible in Rust.
I am trying to create a crate called grocer, which contains the following file:
grocer/src/products.proto:
package grocer.products;
import "freshfoods/seasoning.proto";
import "freshfoods/perishable.proto";
// A can of garlic salt
message GarlicSalt {
// Cloves to add
repeated freshfoods.perishable.Garlic cloves = 1;
// Tablespoons of salt to add
repeated freshfoods.seasoning.Salt salt_tbsp = 2;
}Since I'm not Alice, I'm importing freshfoods by putting a freshfoods = "1.0.0" line in my Cargo.toml.
Unfortunately, I can't figure out how to make this compile. I found prost_build::Config::extern_path and read the docs but I can't figure out what to put in it to make it compile. Nothing I try works.
The only thing I can think of would be to manually copy and paste Alice's proto files into my own crate, but that defeats the purpose of Cargo.toml and it just feels really hacky.
Is it even possible to do what I'm trying to do?