#build-script #grpc #protoc #protobuf-compiler #protobuf #compiler-version #prost

build protoc-fetcher

Fetches official Protocol Buffer compiler (protoc) releases for use in build scripts

2 releases

0.1.1 Mar 19, 2024
0.1.0 Aug 28, 2022

#399 in Build Utils

Download history 94/week @ 2024-10-29 151/week @ 2024-11-05 145/week @ 2024-11-12 259/week @ 2024-11-19 228/week @ 2024-11-26 208/week @ 2024-12-03 117/week @ 2024-12-10 178/week @ 2024-12-17 20/week @ 2024-12-31 124/week @ 2025-01-07 200/week @ 2025-01-14 201/week @ 2025-01-21 227/week @ 2025-01-28 259/week @ 2025-02-04 134/week @ 2025-02-11

831 downloads per month
Used in axum-connect-build

MIT license

9KB
70 lines

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 std::env;
use std::path::Path;

// From within build.rs...
let protoc_version = "21.5";
let out_dir = env::var("OUT_DIR").unwrap();
let protoc_path = protoc_fetcher::protoc(protoc_version, Path::new(&out_dir));

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 std::env;
use std::path::Path;

let out_dir = env::var("OUT_DIR").unwrap();
let path_to_my_protos = Path::new("a/b/c");
let protoc_path = protoc_fetcher::protoc("21.2", Path::new(&out_dir)).unwrap();
env::set_var("PROTOC", &protoc_path);
tonic_build::compile_protos(path_to_my_protos);

Dependencies

~5–17MB
~226K SLoC

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy