@@ -1124,12 +1124,16 @@ impl Config {
11241124
11251125 debug ! ( "Running: {:?}" , cmd) ;
11261126
1127- let output = cmd. output ( ) . map_err ( |error| {
1128- Error :: new (
1129- error. kind ( ) ,
1130- format ! ( "failed to invoke protoc (hint: https://docs.rs/prost-build/#sourcing-protoc): (path: {:?}): {}" , & protoc, error) ,
1131- )
1132- } ) ?;
1127+ let output = match cmd. output ( ) {
1128+ Err ( err) if ErrorKind :: NotFound == err. kind ( ) => {
1129+ panic ! ( "{}" , protoc_not_found( ) ) ;
1130+ }
1131+ Err ( err) => return Err ( Error :: new (
1132+ err. kind ( ) ,
1133+ format ! ( "failed to invoke protoc (hint: https://docs.rs/prost-build/#sourcing-protoc): (path: {:?}): {}" , & protoc, err) ,
1134+ ) ) ,
1135+ Ok ( output) => output,
1136+ } ;
11331137
11341138 if !output. status . success ( ) {
11351139 return Err ( Error :: new (
@@ -1495,6 +1499,12 @@ pub fn compile_fds(fds: FileDescriptorSet) -> Result<()> {
14951499
14961500/// Returns the path to the `protoc` binary.
14971501pub fn protoc_from_env ( ) -> PathBuf {
1502+ env:: var_os ( "PROTOC" )
1503+ . map ( PathBuf :: from)
1504+ . unwrap_or ( PathBuf :: from ( "protoc" ) )
1505+ }
1506+
1507+ pub fn protoc_not_found ( ) -> String {
14981508 let os_specific_hint = if cfg ! ( target_os = "macos" ) {
14991509 "You could try running `brew install protobuf` or downloading it from https://github.com/protocolbuffers/protobuf/releases"
15001510 } else if cfg ! ( target_os = "linux" ) {
@@ -1507,18 +1517,13 @@ pub fn protoc_from_env() -> PathBuf {
15071517 this knowledge. If `protoc` is installed and this crate had trouble finding
15081518 it, you can set the `PROTOC` environment variable with the specific path to your
15091519 installed `protoc` binary." ;
1510- let msg = format ! (
1520+ format ! (
15111521 "{}{}
15121522
15131523For more information: https://docs.rs/prost-build/#sourcing-protoc
15141524" ,
15151525 error_msg, os_specific_hint
1516- ) ;
1517-
1518- env:: var_os ( "PROTOC" )
1519- . map ( PathBuf :: from)
1520- . or_else ( || which:: which ( "protoc" ) . ok ( ) )
1521- . expect ( & msg)
1526+ )
15221527}
15231528
15241529/// Returns the path to the Protobuf include directory.
0 commit comments