Skip to content

Commit eb352d0

Browse files
committed
Remove which dependency.
1 parent 907e9f6 commit eb352d0

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-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: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,12 +1124,16 @@ impl Config {
11241124

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

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

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

14961500
/// Returns the path to the `protoc` binary.
14971501
pub fn protoc_from_env() -> PathBuf {
1502+
env::var_os("PROTOC")
1503+
.map(PathBuf::from)
1504+
.unwrap_or(PathBuf::from("protoc"))
1505+
}
1506+
1507+
pub fn protoc_not_found() -> String {
14981508
let os_specific_hint = if cfg!(target_os = "macos") {
14991509
"You could try running `brew install protobuf` or downloading it from https://github.com/protocolbuffers/protobuf/releases"
15001510
} else if cfg!(target_os = "linux") {
@@ -1507,18 +1517,13 @@ pub fn protoc_from_env() -> PathBuf {
15071517
this knowledge. If `protoc` is installed and this crate had trouble finding
15081518
it, you can set the `PROTOC` environment variable with the specific path to your
15091519
installed `protoc` binary.";
1510-
let msg = format!(
1520+
format!(
15111521
"{}{}
15121522
15131523
For more information: https://docs.rs/prost-build/#sourcing-protoc
15141524
",
15151525
error_msg, os_specific_hint
1516-
);
1517-
1518-
env::var_os("PROTOC")
1519-
.map(PathBuf::from)
1520-
.or_else(|| which::which("protoc").ok())
1521-
.expect(&msg)
1526+
)
15221527
}
15231528

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

0 commit comments

Comments
 (0)