Skip to content

Commit

Permalink
improve compatibility with alpine
Browse files Browse the repository at this point in the history
  • Loading branch information
danburkert committed Dec 27, 2020
1 parent 6a4f12a commit d79ad6f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
9 changes: 9 additions & 0 deletions prost-build/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ fn env_protoc() -> Option<PathBuf> {
}

/// Returns the path to the bundled `protoc`, if it is available for the host platform.
#[cfg(not(target_env = "musl"))]
fn bundled_protoc() -> Option<PathBuf> {
let protoc_bin_name = match (env::consts::OS, env::consts::ARCH) {
("linux", "x86") => "protoc-linux-x86_32",
Expand All @@ -50,6 +51,14 @@ fn bundled_protoc() -> Option<PathBuf> {
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<PathBuf> {
None
}

/// Returns the path to the `protoc` included on the `PATH`, if it exists.
fn path_protoc() -> Option<PathBuf> {
which::which("protoc").ok()
Expand Down
21 changes: 15 additions & 6 deletions prost-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d79ad6f

Please sign in to comment.