Debian Codegraph @

gen/pb-rust/sigstore-protobuf-specs-codegen/src/main.rs

raw
1 use std::path::Path;
2
3 /// Find the standard protobuf include directory.
4 fn protobuf_include_path() -> String {
5 let mut protobuf_root = which::which("protoc")
6 .ok()
7 // dirname(/bin/protoc) / ../
8 .and_then(|path| path.ancestors().nth(2).map(|p| p.to_path_buf()))
9 .expect("protobuf installation directory not found!");
10 protobuf_root.push("include");
11 protobuf_root.to_str().unwrap().to_owned()
12 }
13
14 fn main() -> anyhow::Result<()> {
15 let includes = vec![
16 concat!(env!("CARGO_MANIFEST_DIR"), "/../../../protos").to_owned(),
17 concat!(env!("CARGO_MANIFEST_DIR"), "/../../../service-protos").to_owned(),
18 // WKTs path
19 protobuf_include_path(),
20 "/googleapis".to_owned(),
21 // googleapis types path: set `SIGSTORE_PROTOBUF_EXTRA_INCLUDE` to override.
22 std::env::var("SIGSTORE_PROTOBUF_EXTRA_INCLUDE").unwrap_or("/opt/include".to_owned()),
23 ];
24
25 for include in &includes {
26 let include = Path::new(include);
27 if !include.is_dir() {
28 panic!("invalid include dir: {:?}", include);
29 }
30 }
31
32 let mut config = prost_build::Config::new();
33 config
34 .include_file("mod.rs")
35 .type_attribute(
36 ".",
37 "#[derive(sigstore_protobuf_specs_derive::Deserialize_proto, sigstore_protobuf_specs_derive::Serialize_proto)]",
38 )
39 // Disable problematic comments interpreted as doctests.
40 .disable_comments([".io.intoto.Envelope"])
41 .out_dir("sigstore-protobuf-specs/src/generated/");
42
43 let protos = glob::glob(concat!(
44 env!("CARGO_MANIFEST_DIR"),
45 "/../../../protos/*.proto"
46 ))
47 .expect("no protos found!")
48 .flatten();
49
50 let service_protos = glob::glob(concat!(
51 env!("CARGO_MANIFEST_DIR"),
52 "/../../../service-protos/rekor/v2/*.proto"
53 ))
54 .expect("no service protos found!")
55 .flatten();
56
57 prost_reflect_build::Builder::new()
58 .file_descriptor_set_bytes("crate::FILE_DESCRIPTOR_SET_BYTES")
59 .file_descriptor_set_path("sigstore-protobuf-specs/src/generated/file_descriptor_set.bin")
60 .compile_protos_with_config(
61 config,
62 &protos.chain(service_protos).collect::<Vec<_>>(),
63 &includes,
64 )?;
65
66 Ok(())
67 }