diff --git a/prost-build/build.rs b/prost-build/build.rs index 4bc1cc6ed..3ce4848b9 100644 --- a/prost-build/build.rs +++ b/prost-build/build.rs @@ -36,6 +36,7 @@ fn env_protoc() -> Option { } /// Returns the path to the bundled `protoc`, if it is available for the host platform. +#[cfg(not(target_env = "musl"))] fn bundled_protoc() -> Option { let protoc_bin_name = match (env::consts::OS, env::consts::ARCH) { ("linux", "x86") => "protoc-linux-x86_32", @@ -50,6 +51,14 @@ fn bundled_protoc() -> Option { Some(bundle_path().join(protoc_bin_name)) } +/// `musl` build hosts do not have a bundled `protoc`. +/// +/// Note: this checks the target of the `prost-build` build.rs, which is ultimately the host architecture. +#[cfg(target_env = "musl")] +fn bundled_protoc() -> Option { + None +} + /// Returns the path to the `protoc` included on the `PATH`, if it exists. fn path_protoc() -> Option { which::which("protoc").ok() diff --git a/prost-build/src/lib.rs b/prost-build/src/lib.rs index 7aa20ed47..4500a6068 100644 --- a/prost-build/src/lib.rs +++ b/prost-build/src/lib.rs @@ -97,14 +97,17 @@ //! PROTOC_INCLUDE=/usr/include //! ``` //! -//! If `PROTOC` is not found in the environment, then a pre-compiled `protoc` binary bundled in -//! the prost-build crate is used. Pre-compiled `protoc` binaries exist for Linux, macOS, and -//! Windows systems. If no pre-compiled `protoc` is available for the host platform, then the +//! If `PROTOC` is not found in the environment, then a pre-compiled `protoc` binary bundled in the +//! prost-build crate is used. Pre-compiled `protoc` binaries exist for Linux (non-musl), macOS, +//! and Windows systems. If no pre-compiled `protoc` is available for the host platform, then the //! `protoc` or `protoc.exe` binary on the `PATH` is used. If `protoc` is not available in any of //! these fallback locations, then the build fails. //! -//! If `PROTOC_INCLUDE` is not found in the environment, then the Protobuf include directory bundled -//! in the prost-build crate is be used. +//! If `PROTOC_INCLUDE` is not found in the environment, then the Protobuf include directory +//! bundled in the prost-build crate is be used. +//! +//! To force `prost-build` to use the `protoc` on the `PATH`, add `PROTOC=protoc` to the +//! environment. mod ast; mod code_generator; @@ -697,7 +700,13 @@ impl Config { cmd.arg(proto.as_ref()); } - let output = cmd.output()?; + let output = cmd.output().map_err(|error| { + Error::new( + error.kind(), + format!("failed to invoke protoc (hint: https://docs.rs/prost-build/#sourcing-protoc): {}", error), + ) + })?; + if !output.status.success() { return Err(Error::new( ErrorKind::Other,