Skip to content

Commit

Permalink
Remove the check for existing protoc at build time (tokio-rs#283) (to…
Browse files Browse the repository at this point in the history
…kio-rs#324)

* Allow PROTOC env to be overriden at runtime

* fix tests

Co-authored-by: Gabriel de Russo e Carmo <gabrielrc@fb.com>
  • Loading branch information
2 people authored and Alexis Bauvin committed Jun 23, 2020
1 parent f9afea2 commit f14a097
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions prost-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,13 +676,19 @@ where
}

/// Returns the path to the `protoc` binary.
pub fn protoc() -> &'static Path {
Path::new(env!("PROTOC"))
pub fn protoc() -> PathBuf {
match env::var_os("PROTOC") {
Some(protoc) => PathBuf::from(protoc),
None => PathBuf::from(env!("PROTOC")),
}
}

/// Returns the path to the Protobuf include directory.
pub fn protoc_include() -> &'static Path {
Path::new(env!("PROTOC_INCLUDE"))
pub fn protoc_include() -> PathBuf {
match env::var_os("PROTOC_INCLUDE") {
Some(include) => PathBuf::from(include),
None => PathBuf::from(env!("PROTOC_INCLUDE")),
}
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion tests/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use tempfile;
/// repo. Ensures that the checked-in compiled versions are up-to-date.
#[test]
fn bootstrap() {
let protobuf = Path::new(prost_build::protoc_include())
let protobuf = prost_build::protoc_include()
.join("google")
.join("protobuf");

Expand Down

0 comments on commit f14a097

Please sign in to comment.