From 1b9bc1648ac1c72ab9827c1b5512a3bd99052b55 Mon Sep 17 00:00:00 2001 From: Zack Fu Zi Xiang Date: Thu, 25 Jan 2024 03:41:08 +0800 Subject: [PATCH] fix: use proto from env if present --- libs/realtime-entity/build.rs | 11 +++++++---- shell.nix | 11 +++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 shell.nix diff --git a/libs/realtime-entity/build.rs b/libs/realtime-entity/build.rs index 4b11e89e..d78928fb 100644 --- a/libs/realtime-entity/build.rs +++ b/libs/realtime-entity/build.rs @@ -1,11 +1,14 @@ use std::process::Command; fn main() -> Result<(), Box> { - 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/") diff --git a/shell.nix b/shell.nix new file mode 100644 index 00000000..511d2a6d --- /dev/null +++ b/shell.nix @@ -0,0 +1,11 @@ +{ pkgs ? import {} }: + +pkgs.mkShell { + packages = with pkgs; [ + pkg-config rustup + grpc-tools openssl + ]; + shellHook = '' + export PROTOC=$(which protoc) + ''; +}