|
1 |
| -use std::path::PathBuf; |
| 1 | +use std::path::{Path, PathBuf}; |
2 | 2 |
|
3 | 3 | fn main() {
|
4 | 4 | let output = std::process::Command::new("git")
|
@@ -28,15 +28,29 @@ fn main() {
|
28 | 28 | }
|
29 | 29 | }
|
30 | 30 |
|
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 | + } |
38 | 53 | }
|
39 |
| - config.compile_protos(&proto_files, &[root]).expect("Failed to compile protos"); |
40 | 54 |
|
41 | 55 | let descriptor_set = std::fs::read(descriptor_path).expect("Failed to read descriptor set");
|
42 | 56 | pbjson_build::Builder::new()
|
|
0 commit comments