protoc-fetcher
Rust library for fetching official Protocol Buffer compiler (protoc
) releases, pegged to a
specific version.
protoc-fetcher
downloads an official release of the protobuf compiler (protoc) and returns the
path to it.
use env;
use Path;
// From within build.rs...
let protoc_version = "21.5";
let out_dir = var.unwrap;
let protoc_path = protoc;
The release archive matching the given version
will be downloaded, and the protoc binary will
be extracted into a subdirectory of out_dir
. You can choose a version
from the
release page, for example "21.5". Don't prefix it with a "v".
out_dir
can be anywhere you want, but if calling this function from a build script, you should
probably use the OUT_DIR
env var (which is set by Cargo automatically for build scripts).
A previously downloaded protoc binary of the correct version will be reused if already present
in out_dir
.
Usage with Tonic or Prost
If you are using tonic-build (or prost-build), you can instruct it to use the fetched
protoc
binary by setting the PROTOC
env var.
use env;
use Path;
let out_dir = var.unwrap;
let path_to_my_protos = new;
let protoc_path = protoc.unwrap;
set_var;
compile_protos;