Offer optional support for protox in tonic-build
Feature Request
If I understand correctly, using https://github.com/andrewhickman/protox should make it possible to avoid the use of protoc binaries. It would be great if tonic-build offered built-in API (using a Cargo feature) to leverage protox for schema compilation.
Crates
tonic-build
Motivation
Avoid the need for installing protoc on developer systems and in build containers.
I'd be willing to implement this if there is a reasonable expectation that it would be accepted.
Alternatives
It is possible today to use protox directly, as documented in its README:
let file_descriptors = protox::compile(["root.proto"], ["."]).unwrap();
let file_descriptor_path = PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR not set"))
.join("file_descriptor_set.bin");
fs::write(&file_descriptor_path, file_descriptors.encode_to_vec()).unwrap();
tonic_build::Config::new()
.file_descriptor_set_path(&file_descriptor_path)
.skip_protoc_run()
.compile_protos(["root.proto"], ["."])
.unwrap();
Having this built-in seems like it would be a good deal more easy to use, and maybe eventually could become the default?
@andrewhickman any potential blockers from your side?
Sounds good to me 😃
It would also be nice to have a compile_fds function like in prost-build. That also allows the user to customize the protox compilation if necessary, and doesn't require a direct dependency on protox
@andrewhickman would you be interested in starting that work? I think id like to get a release out today but we can add these in both prost/tonic in a non-breaking way.
This sounds great.
https://github.com/andrewhickman/protox/issues/17 - added more complete instructions in this issue.