Giter Site home page Giter Site logo

protoc-fetcher's Introduction

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);

protoc-fetcher's People

Contributors

aleasims avatar jdahlq avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.