mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-10-22 12:29:49 +00:00
agent: agent-protocol support async
1. support async. 2. update ttrpc and protobuf update ttrpc to 0.6.0 update protobuf to 2.23.0 3. support trans from oci Fixes: #3746 Signed-off-by: Quanwei Zhou <quanweiZhou@linux.alibaba.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
use std::fs::File;
|
||||
use std::fs::{self, File};
|
||||
use std::io::{BufRead, BufReader, Read, Write};
|
||||
use std::path::Path;
|
||||
use std::process::exit;
|
||||
@@ -90,17 +90,8 @@ fn handle_file(autogen_comment: &str, rust_filename: &str) -> Result<(), std::io
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn real_main() -> Result<(), std::io::Error> {
|
||||
let autogen_comment = format!("\n//! Generated by {:?} ({:?})", file!(), module_path!());
|
||||
|
||||
let protos = vec![
|
||||
"protos/agent.proto",
|
||||
"protos/csi.proto",
|
||||
"protos/google/protobuf/empty.proto",
|
||||
"protos/health.proto",
|
||||
"protos/oci.proto",
|
||||
"protos/types.proto",
|
||||
];
|
||||
fn codegen(path: &str, protos: &[&str], async_all: bool) -> Result<(), std::io::Error> {
|
||||
fs::create_dir_all(path).unwrap();
|
||||
|
||||
// Tell Cargo that if the .proto files changed, to rerun this build script.
|
||||
protos
|
||||
@@ -108,7 +99,7 @@ fn real_main() -> Result<(), std::io::Error> {
|
||||
.for_each(|p| println!("cargo:rerun-if-changed={}", &p));
|
||||
|
||||
let ttrpc_options = Customize {
|
||||
async_server: true,
|
||||
async_all,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
@@ -121,13 +112,14 @@ fn real_main() -> Result<(), std::io::Error> {
|
||||
|
||||
Codegen::new()
|
||||
.out_dir(out_dir)
|
||||
.inputs(&protos)
|
||||
.inputs(protos)
|
||||
.include("protos")
|
||||
.customize(ttrpc_options)
|
||||
.rust_protobuf()
|
||||
.rust_protobuf_customize(protobuf_options)
|
||||
.run()?;
|
||||
|
||||
let autogen_comment = format!("\n//! Generated by {:?} ({:?})", file!(), module_path!());
|
||||
for file in protos.iter() {
|
||||
let proto_filename = Path::new(file).file_name().unwrap();
|
||||
|
||||
@@ -147,6 +139,31 @@ fn real_main() -> Result<(), std::io::Error> {
|
||||
handle_file(&autogen_comment, out_file_str)?;
|
||||
}
|
||||
|
||||
use_serde(protos, out_dir)?;
|
||||
Ok(())
|
||||
}
|
||||
fn real_main() -> Result<(), std::io::Error> {
|
||||
codegen(
|
||||
"src",
|
||||
&[
|
||||
"protos/google/protobuf/empty.proto",
|
||||
"protos/oci.proto",
|
||||
"protos/types.proto",
|
||||
],
|
||||
false,
|
||||
)?;
|
||||
|
||||
// generate async
|
||||
#[cfg(feature = "async")]
|
||||
{
|
||||
codegen("src", &["protos/agent.proto", "protos/health.proto"], true)?;
|
||||
|
||||
fs::rename("src/agent_ttrpc.rs", "src/agent_ttrpc_async.rs")?;
|
||||
fs::rename("src/health_ttrpc.rs", "src/health_ttrpc_async.rs")?;
|
||||
}
|
||||
|
||||
codegen("src", &["protos/agent.proto", "protos/health.proto"], false)?;
|
||||
|
||||
// There is a message named 'Box' in oci.proto
|
||||
// so there is a struct named 'Box', we should replace Box<Self> to ::std::boxed::Box<Self>
|
||||
// to avoid the conflict.
|
||||
@@ -156,8 +173,6 @@ fn real_main() -> Result<(), std::io::Error> {
|
||||
"self: ::std::boxed::Box<Self>",
|
||||
)?;
|
||||
|
||||
use_serde(&protos, out_dir)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user