use std::{env, fs, io};
const PROTO_FILES: &[&str] = &[
"vendor/github.com/containerd/containerd/api/types/descriptor.proto",
"vendor/github.com/containerd/containerd/api/types/metrics.proto",
"vendor/github.com/containerd/containerd/api/types/mount.proto",
"vendor/github.com/containerd/containerd/api/types/platform.proto",
"vendor/github.com/containerd/containerd/api/types/sandbox.proto",
"vendor/github.com/containerd/containerd/api/types/task/task.proto",
"vendor/github.com/containerd/containerd/api/types/transfer/imagestore.proto",
"vendor/github.com/containerd/containerd/api/types/transfer/importexport.proto",
"vendor/github.com/containerd/containerd/api/types/transfer/progress.proto",
"vendor/github.com/containerd/containerd/api/types/transfer/registry.proto",
"vendor/github.com/containerd/containerd/api/types/transfer/streaming.proto",
"vendor/github.com/containerd/containerd/api/services/containers/v1/containers.proto",
"vendor/github.com/containerd/containerd/api/services/content/v1/content.proto",
"vendor/github.com/containerd/containerd/api/services/diff/v1/diff.proto",
"vendor/github.com/containerd/containerd/api/services/events/v1/events.proto",
"vendor/github.com/containerd/containerd/api/services/images/v1/images.proto",
"vendor/github.com/containerd/containerd/api/services/introspection/v1/introspection.proto",
"vendor/github.com/containerd/containerd/api/services/leases/v1/leases.proto",
"vendor/github.com/containerd/containerd/api/services/namespaces/v1/namespace.proto",
"vendor/github.com/containerd/containerd/api/services/sandbox/v1/sandbox.proto",
"vendor/github.com/containerd/containerd/api/services/snapshots/v1/snapshots.proto",
"vendor/github.com/containerd/containerd/api/services/streaming/v1/streaming.proto",
"vendor/github.com/containerd/containerd/api/services/tasks/v1/tasks.proto",
"vendor/github.com/containerd/containerd/api/services/transfer/v1/transfer.proto",
"vendor/github.com/containerd/containerd/api/services/version/v1/version.proto",
"vendor/github.com/containerd/containerd/api/events/container.proto",
"vendor/github.com/containerd/containerd/api/events/content.proto",
"vendor/github.com/containerd/containerd/api/events/image.proto",
"vendor/github.com/containerd/containerd/api/events/namespace.proto",
"vendor/github.com/containerd/containerd/api/events/snapshot.proto",
"vendor/github.com/containerd/containerd/api/events/task.proto",
];
const FIXUP_MODULES: &[&str] = &[
"containerd.services.diff.v1",
"containerd.services.images.v1",
"containerd.services.introspection.v1",
"containerd.services.sandbox.v1",
"containerd.services.snapshots.v1",
"containerd.services.tasks.v1",
"containerd.services.containers.v1",
"containerd.services.content.v1",
];
fn main() {
let mut config = prost_build::Config::new();
config.enable_type_names();
tonic_build::configure()
.build_server(false)
.compile_protos_with_config(config, PROTO_FILES, &["vendor/"])
.expect("Failed to generate GRPC bindings");
for module in FIXUP_MODULES {
fixup_imports(module).expect("Failed to fixup module");
}
}
fn fixup_imports(path: &str) -> Result<(), io::Error> {
let out_dir = env::var("OUT_DIR").unwrap();
let path = format!("{}/{}.rs", out_dir, path);
let contents = fs::read_to_string(&path)?
.replace("super::super::super::v1::types", "crate::types::v1") .replace("super::super::super::types", "crate::types")
.replace("super::super::super::super::google", "crate::google")
.replace(
"/// filters\\[0\\] or filters\\[1\\] or ... or filters\\[n-1\\] or filters\\[n\\]",
r#"
/// ```notrust
/// filters[0] or filters[1] or ... or filters[n-1] or filters[n]
/// ```"#,
);
fs::write(path, contents)?;
Ok(())
}