Skip to content

Commit

Permalink
make env! optional in src/lib.rs
Browse files Browse the repository at this point in the history
Users of plugins may not want to use a build.rs file to generate the
plugin, as the plugin will not need to know the location of protoc.
Removing the need for a build.rs file simplifies the integration with
build systems other than cargo, such as bazel, through the use of cargo
raze and rules_rust.
  • Loading branch information
dfreese committed May 5, 2020
1 parent b7ff3b8 commit 8e347b6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions prost-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,12 +808,16 @@ where

/// Returns the path to the `protoc` binary.
pub fn protoc() -> &'static Path {
Path::new(env!("PROTOC"))
// Leave these as optional, for users who do not want to use build.rs, which is not needed by
// the protoc plugin users.
Path::new(option_env!("PROTOC").unwrap())
}

/// Returns the path to the Protobuf include directory.
pub fn protoc_include() -> &'static Path {
Path::new(env!("PROTOC_INCLUDE"))
// Leave these as optional, for users who do not want to use build.rs, which is not needed by
// the protoc plugin users.
Path::new(option_env!("PROTOC_INCLUDE").unwrap())
}

#[cfg(test)]
Expand Down

0 comments on commit 8e347b6

Please sign in to comment.