Skip to content

Commit 1d656bf

Browse files
committed
Remove which dependency.
1 parent 80f2f7a commit 1d656bf

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

prost-build/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ prost-types = { version = "0.12.3", path = "../prost-types", default-features =
3232
tempfile = "3"
3333
once_cell = "1.17.1"
3434
regex = { version = "1.8.1", default-features = false, features = ["std", "unicode-bool"] }
35-
which = "4"
3635

3736
prettyplease = { version = "0.2", optional = true }
3837
syn = { version = "2", features = ["full"], optional = true }

prost-build/src/lib.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,12 +1125,17 @@ impl Config {
11251125

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

1128-
let output = cmd.output().map_err(|error| {
1129-
Error::new(
1130-
error.kind(),
1131-
format!("failed to invoke protoc (hint: https://docs.rs/prost-build/#sourcing-protoc): (path: {:?}): {}", &protoc, error),
1132-
)
1133-
})?;
1128+
let output = match cmd.output() {
1129+
Err(err) if ErrorKind::NotFound == err.kind() => return Err(Error::new(
1130+
err.kind(),
1131+
error_message_protoc_not_found()
1132+
)),
1133+
Err(err) => return Err(Error::new(
1134+
err.kind(),
1135+
format!("failed to invoke protoc (hint: https://docs.rs/prost-build/#sourcing-protoc): (path: {:?}): {}", &protoc, err),
1136+
)),
1137+
Ok(output) => output,
1138+
};
11341139

11351140
if !output.status.success() {
11361141
return Err(Error::new(
@@ -1505,6 +1510,12 @@ pub fn compile_fds(fds: FileDescriptorSet) -> Result<()> {
15051510

15061511
/// Returns the path to the `protoc` binary.
15071512
pub fn protoc_from_env() -> PathBuf {
1513+
env::var_os("PROTOC")
1514+
.map(PathBuf::from)
1515+
.unwrap_or(PathBuf::from("protoc"))
1516+
}
1517+
1518+
pub fn error_message_protoc_not_found() -> String {
15081519
let os_specific_hint = if cfg!(target_os = "macos") {
15091520
"You could try running `brew install protobuf` or downloading it from https://github.com/protocolbuffers/protobuf/releases"
15101521
} else if cfg!(target_os = "linux") {
@@ -1517,18 +1528,13 @@ pub fn protoc_from_env() -> PathBuf {
15171528
this knowledge. If `protoc` is installed and this crate had trouble finding
15181529
it, you can set the `PROTOC` environment variable with the specific path to your
15191530
installed `protoc` binary.";
1520-
let msg = format!(
1531+
format!(
15211532
"{}{}
15221533
15231534
For more information: https://docs.rs/prost-build/#sourcing-protoc
15241535
",
15251536
error_msg, os_specific_hint
1526-
);
1527-
1528-
env::var_os("PROTOC")
1529-
.map(PathBuf::from)
1530-
.or_else(|| which::which("protoc").ok())
1531-
.expect(&msg)
1537+
)
15321538
}
15331539

15341540
/// Returns the path to the Protobuf include directory.

0 commit comments

Comments
 (0)