tonic icon indicating copy to clipboard operation
tonic copied to clipboard

Offer optional support for protox in tonic-build

Open djc opened this issue 2 years ago • 4 comments

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?

djc avatar Aug 31 '23 13:08 djc

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 avatar Aug 31 '23 21:08 andrewhickman

@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.

LucioFranco avatar Sep 01 '23 14:09 LucioFranco

This sounds great.

0xAlcibiades avatar Sep 16 '23 22:09 0xAlcibiades

https://github.com/andrewhickman/protox/issues/17 - added more complete instructions in this issue.

0xAlcibiades avatar Sep 28 '23 04:09 0xAlcibiades