Skip to content

Commit

Permalink
Remove which dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai committed Dec 19, 2023
1 parent 907e9f6 commit 70d9b8b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
1 change: 0 additions & 1 deletion prost-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ prost-types = { version = "0.12.3", path = "../prost-types", default-features =
tempfile = "3"
once_cell = "1.17.1"
regex = { version = "1.8.1", default-features = false, features = ["std", "unicode-bool"] }
which = "4"

prettyplease = { version = "0.2", optional = true }
syn = { version = "2", features = ["full"], optional = true }
Expand Down
31 changes: 18 additions & 13 deletions prost-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,12 +1124,16 @@ impl Config {

debug!("Running: {:?}", cmd);

let output = cmd.output().map_err(|error| {
Error::new(
error.kind(),
format!("failed to invoke protoc (hint: https://docs.rs/prost-build/#sourcing-protoc): (path: {:?}): {}", &protoc, error),
)
})?;
let output = match cmd.output() {
Err(err) if ErrorKind::NotFound == err.kind() => {
panic!("{}", protoc_not_found());
}
Err(err) => return Err(Error::new(
err.kind(),
format!("failed to invoke protoc (hint: https://docs.rs/prost-build/#sourcing-protoc): (path: {:?}): {}", &protoc, err),
)),
Ok(output) => output,
};

if !output.status.success() {
return Err(Error::new(
Expand Down Expand Up @@ -1495,6 +1499,12 @@ pub fn compile_fds(fds: FileDescriptorSet) -> Result<()> {

/// Returns the path to the `protoc` binary.
pub fn protoc_from_env() -> PathBuf {
env::var_os("PROTOC")
.map(PathBuf::from)
.unwrap_or(PathBuf::from("protoc"))
}

pub fn protoc_not_found() -> String {
let os_specific_hint = if cfg!(target_os = "macos") {
"You could try running `brew install protobuf` or downloading it from https://github.com/protocolbuffers/protobuf/releases"
} else if cfg!(target_os = "linux") {
Expand All @@ -1507,18 +1517,13 @@ pub fn protoc_from_env() -> PathBuf {
this knowledge. If `protoc` is installed and this crate had trouble finding
it, you can set the `PROTOC` environment variable with the specific path to your
installed `protoc` binary.";
let msg = format!(
format!(
"{}{}
For more information: https://docs.rs/prost-build/#sourcing-protoc
",
error_msg, os_specific_hint
);

env::var_os("PROTOC")
.map(PathBuf::from)
.or_else(|| which::which("protoc").ok())
.expect(&msg)
)
}

/// Returns the path to the Protobuf include directory.
Expand Down

0 comments on commit 70d9b8b

Please sign in to comment.