Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove which dependency #962

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
32 changes: 19 additions & 13 deletions prost-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,12 +1125,17 @@ 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() => return Err(Error::new(
err.kind(),
error_message_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 @@ -1505,6 +1510,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 error_message_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 @@ -1517,18 +1528,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
Loading