fix: use proto from env if present

This commit is contained in:
Zack Fu Zi Xiang 2024-01-25 03:41:08 +08:00
parent 2a7b0ad75f
commit 1b9bc1648a
2 changed files with 18 additions and 4 deletions

View File

@ -1,11 +1,14 @@
use std::process::Command;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let protoc_path = protoc_bin_vendored::protoc_bin_path().expect("protoc bin path");
let protoc_path_str = protoc_path.to_str().expect("protoc path to str");
// If the `PROTOC` environment variable is set, don't use vendored `protoc`
std::env::var("PROTOC").map(|_| ()).unwrap_or_else(|_| {
let protoc_path = protoc_bin_vendored::protoc_bin_path().expect("protoc bin path");
let protoc_path_str = protoc_path.to_str().expect("protoc path to str");
// Set the `PROTOC` environment variable to the path of the `protoc` binary.
std::env::set_var("PROTOC", protoc_path_str);
// Set the `PROTOC` environment variable to the path of the `protoc` binary.
std::env::set_var("PROTOC", protoc_path_str);
});
prost_build::Config::new()
.out_dir("src/")

11
shell.nix Normal file
View File

@ -0,0 +1,11 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
packages = with pkgs; [
pkg-config rustup
grpc-tools openssl
];
shellHook = ''
export PROTOC=$(which protoc)
'';
}