Skip to content

Commit 3710b6a

Browse files
committed
Try even harder to recover from protoc missing
1 parent faebddb commit 3710b6a

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

objdiff-cli/build.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::path::PathBuf;
1+
use std::path::{Path, PathBuf};
22

33
fn main() {
44
let output = std::process::Command::new("git")
@@ -28,15 +28,29 @@ fn main() {
2828
}
2929
}
3030

31-
let mut config = prost_build::Config::new();
32-
config.file_descriptor_set_path(&descriptor_path);
33-
// If our cached descriptor is up-to-date, we don't need to run protoc.
34-
// This is helpful so that users don't need to have protoc installed
35-
// unless they're updating the protos.
36-
if !run_protoc {
37-
config.skip_protoc_run();
31+
fn prost_config(descriptor_path: &Path, run_protoc: bool) -> prost_build::Config {
32+
let mut config = prost_build::Config::new();
33+
config.file_descriptor_set_path(descriptor_path);
34+
// If our cached descriptor is up-to-date, we don't need to run protoc.
35+
// This is helpful so that users don't need to have protoc installed
36+
// unless they're updating the protos.
37+
if !run_protoc {
38+
config.skip_protoc_run();
39+
}
40+
config
41+
}
42+
if let Err(e) =
43+
prost_config(&descriptor_path, run_protoc).compile_protos(&proto_files, &[root.as_path()])
44+
{
45+
if e.kind() == std::io::ErrorKind::NotFound && e.to_string().contains("protoc") {
46+
eprintln!("protoc not found, skipping protobuf compilation");
47+
prost_config(&descriptor_path, false)
48+
.compile_protos(&proto_files, &[root.as_path()])
49+
.expect("Failed to compile protos");
50+
} else {
51+
panic!("Failed to compile protos: {e:?}");
52+
}
3853
}
39-
config.compile_protos(&proto_files, &[root]).expect("Failed to compile protos");
4054

4155
let descriptor_set = std::fs::read(descriptor_path).expect("Failed to read descriptor set");
4256
pbjson_build::Builder::new()

0 commit comments

Comments
 (0)