-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.rs
executable file
·108 lines (97 loc) · 3.47 KB
/
build.rs
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
use glob::glob;
use std::io::Write;
use std::path::PathBuf;
use std::process::{Command, Stdio};
// BESS_DIR = os.path.dirname(os.path.abspath(__file__))
// DEPS_DIR = '%s/deps' % BESS_DIR
const DPDK_URL: &str = "https://fast.dpdk.org/rel";
const DPDK_VER: &str = "dpdk-22.07";
const DPDK_TARGET: &str = "x86_64-native-linuxapp-gcc";
// kernel_release = cmd('uname -r', quiet=True).strip()
// DPDK_DIR = '%s/%s' % (DEPS_DIR, DPDK_VER)
// DPDK_CFLAGS = '"-g -w"'
// DPDK_CONFIG = '%s/build/.config' % DPDK_DIR
fn cmd(cmd: &str, quiet: bool) {
let mut c = Command::new("python");
if quiet == true {
c.stdout(Stdio::inherit()).stderr(Stdio::inherit());
} else {
c.stdout(Stdio::null()).stderr(Stdio::null());
}
for arg in cmd.split_whitespace() {
c.arg(arg);
}
match c.output() {
Ok(result) => println!("{}", String::from_utf8(result.stdout).unwrap()),
Err(e) => println!(
"Error has occured running command: python {} : {:?}",
cmd, e
),
}
}
fn generate_protobuf_files() {
println!("Generating protobuf codes for pybess...");
// std::io::stdout().flush().unwrap();
gen_one_set_of_files("protobuf", "pybess/builtin_pb");
gen_one_set_of_files("protobuf/tests", "pybess/builtin_pb");
// for path in plugins {
// gen_one_set_of_files(std::path::Path::new(&format!("{}/{}",path, "protobuf")),"pybess/plugin_pb");
// }
}
fn gen_one_set_of_files(srcdir: &str, outdir: &str) {
// run grpc_tools.protoc on *.proto in srcdir, with python output to outdir"
// python -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. helloworld.proto
// let stddir = "protobuf";
let files = glob(
std::path::Path::new(&format!("{}/{}", srcdir, "*.proto"))
.to_str()
.unwrap(),
)
.unwrap();
for file in files {
match file {
Ok(proto_file) => {
let cmd_args= &format!("-m grpc_tools.protoc --proto_path={srcdir} --python_out={outdir} --grpc_python_out={outdir} {}", proto_file.display());
cmd(cmd_args, false);
}
Err(e) => println!("{:?}", e),
}
}
// Note: when run as, e.g.
// grpc_tools.protoc protobuf/ports/port_msg.proto \
// --proto_path=protobuf \
// --python_out=pybess/builtin_pb ...
// protoc writes its output to:
// pybess/builtin_pb/ports/port_msg.proto
// which is automatically where we want it.
let files = glob(
std::path::Path::new(&format!("{}/{}/{}", srcdir, "ports", "*.proto"))
.to_str()
.unwrap(),
)
.unwrap();
for file in files {
match file {
Ok(proto_file) => {
let cmd_args= &format!("-m grpc_tools.protoc --proto_path={srcdir} --python_out={outdir} --grpc_python_out={outdir} {}", proto_file.display());
cmd(cmd_args, false);
}
Err(e) => println!("{:?}", e),
}
}
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
// build_data::set_GIT_BRANCH();
// build_data::set_GIT_COMMIT();
// build_data::set_GIT_DIRTY();
// build_data::set_SOURCE_TIMESTAMP();
// build_data::no_debug_rebuilds();
build_data::set_RUSTC_VERSION();
// build_data::set_RUSTC_VERSION_SEMVER();
generate_protobuf_files();
tonic_build::compile_protos("protobuf/service.proto")?;
Ok(())
}