@@ -1125,12 +1125,17 @@ impl Config {
11251125
11261126 debug ! ( "Running: {:?}" , cmd) ;
11271127
1128- let output = cmd. output ( ) . map_err ( |error| {
1129- Error :: new (
1130- error. kind ( ) ,
1131- format ! ( "failed to invoke protoc (hint: https://docs.rs/prost-build/#sourcing-protoc): (path: {:?}): {}" , & protoc, error) ,
1132- )
1133- } ) ?;
1128+ let output = match cmd. output ( ) {
1129+ Err ( err) if ErrorKind :: NotFound == err. kind ( ) => return Err ( Error :: new (
1130+ err. kind ( ) ,
1131+ error_message_protoc_not_found ( )
1132+ ) ) ,
1133+ Err ( err) => return Err ( Error :: new (
1134+ err. kind ( ) ,
1135+ format ! ( "failed to invoke protoc (hint: https://docs.rs/prost-build/#sourcing-protoc): (path: {:?}): {}" , & protoc, err) ,
1136+ ) ) ,
1137+ Ok ( output) => output,
1138+ } ;
11341139
11351140 if !output. status . success ( ) {
11361141 return Err ( Error :: new (
@@ -1505,6 +1510,12 @@ pub fn compile_fds(fds: FileDescriptorSet) -> Result<()> {
15051510
15061511/// Returns the path to the `protoc` binary.
15071512pub fn protoc_from_env ( ) -> PathBuf {
1513+ env:: var_os ( "PROTOC" )
1514+ . map ( PathBuf :: from)
1515+ . unwrap_or ( PathBuf :: from ( "protoc" ) )
1516+ }
1517+
1518+ pub fn error_message_protoc_not_found ( ) -> String {
15081519 let os_specific_hint = if cfg ! ( target_os = "macos" ) {
15091520 "You could try running `brew install protobuf` or downloading it from https://github.com/protocolbuffers/protobuf/releases"
15101521 } else if cfg ! ( target_os = "linux" ) {
@@ -1517,18 +1528,13 @@ pub fn protoc_from_env() -> PathBuf {
15171528 this knowledge. If `protoc` is installed and this crate had trouble finding
15181529 it, you can set the `PROTOC` environment variable with the specific path to your
15191530 installed `protoc` binary." ;
1520- let msg = format ! (
1531+ format ! (
15211532 "{}{}
15221533
15231534For more information: https://docs.rs/prost-build/#sourcing-protoc
15241535" ,
15251536 error_msg, os_specific_hint
1526- ) ;
1527-
1528- env:: var_os ( "PROTOC" )
1529- . map ( PathBuf :: from)
1530- . or_else ( || which:: which ( "protoc" ) . ok ( ) )
1531- . expect ( & msg)
1537+ )
15321538}
15331539
15341540/// Returns the path to the Protobuf include directory.
0 commit comments