-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.rs
More file actions
69 lines (60 loc) · 2.75 KB
/
Copy pathbuild.rs
File metadata and controls
69 lines (60 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use std::path::{Path, PathBuf};
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=protos");
let protoc = protoc_bin_vendored::protoc_bin_path()?;
unsafe {
std::env::set_var("PROTOC", protoc);
}
let proto_root = PathBuf::from("protos");
let service_proto = proto_root.join("squareup/cash/kgoose/api/v3/tool_endpoint_service.proto");
let messages_proto =
proto_root.join("squareup/cash/kgoose/api/v3/tool_endpoint_messages.proto");
let descriptor_path = PathBuf::from(std::env::var("OUT_DIR")?).join("proto_descriptor.bin");
for proto in [&service_proto, &messages_proto] {
ensure_proto_exists(proto)?;
}
tonic_prost_build::configure()
.include_file("proto.rs")
.file_descriptor_set_path(&descriptor_path)
.extern_path(".google.protobuf.Struct", "::pbjson_types::Struct")
.extern_path(".google.protobuf.Value", "::pbjson_types::Value")
.extern_path(".google.protobuf.ListValue", "::pbjson_types::ListValue")
.extern_path(".google.protobuf.NullValue", "::pbjson_types::NullValue")
.compile_protos(&[service_proto, messages_proto], &[proto_root])?;
let descriptor_set = std::fs::read(&descriptor_path)?;
pbjson_build::Builder::new()
.register_descriptors(&descriptor_set)?
.preserve_proto_field_names()
.build(&[
".squareup.cash.kgoose.api.v3.CallToolRequest",
".squareup.cash.kgoose.api.v3.CallToolResponse",
".squareup.cash.kgoose.api.v3.EmbeddedResource",
".squareup.cash.kgoose.api.v3.ExtensionInfo",
".squareup.cash.kgoose.api.v3.ImageContent",
".squareup.cash.kgoose.api.v3.ListExtensionsRequest",
".squareup.cash.kgoose.api.v3.ListExtensionsResponse",
".squareup.cash.kgoose.api.v3.ListToolsRequest",
".squareup.cash.kgoose.api.v3.ListToolsResponse",
".squareup.cash.kgoose.api.v3.ResourceAnnotations",
".squareup.cash.kgoose.api.v3.ResourceContents",
".squareup.cash.kgoose.api.v3.Role",
".squareup.cash.kgoose.api.v3.Source",
".squareup.cash.kgoose.api.v3.StructuredContent",
".squareup.cash.kgoose.api.v3.Tenancy",
".squareup.cash.kgoose.api.v3.TextContent",
".squareup.cash.kgoose.api.v3.ToolConfig",
".squareup.cash.kgoose.api.v3.UserContent",
])?;
Ok(())
}
fn ensure_proto_exists(path: &Path) -> Result<(), Box<dyn std::error::Error>> {
if path.exists() {
return Ok(());
}
Err(format!(
"missing required proto `{}`; run `just download-protos` first",
path.display()
)
.into())
}