-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.rs
143 lines (135 loc) · 5.08 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
use std::process::Command;
#[allow(missing_docs)]
fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::compile_protos("proto/crawler.proto")?;
tonic_build::compile_protos("proto/website.proto")?;
tonic_build::compile_protos("proto/health.proto")?;
// os info validate protbuf install. If not installed - install and remove after.
let info = os_info::get();
let os_type = info.os_type();
// check if protoc is installed
let protoc_installed = match Command::new("protoc").arg("--version").output() {
Ok(_) => true,
_ => false,
};
// TODO: use binary
// curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v3.15.8/protoc-3.15.8-linux-x86_64.zip
// unzip protoc-3.15.8-linux-x86_64.zip -d $HOME/.local
// export PATH="$PATH:$HOME/.local/bin"
// OR git clone source
// git clone https://github.com/protocolbuffers/protobuf
// cd protobuf
// git submodule update --init --recursive
// cmake --build .
if !protoc_installed {
if os_type == os_info::Type::Ubuntu
|| os_type == os_info::Type::Pop
|| os_type == os_info::Type::Debian
{
match Command::new("apt")
.args(["install", "-y", "protobuf-compiler", "libprotobuf-dev"])
.output()
{
Ok(_) => {}
_ => {
println!("failed to install protobuf-compiler and libprotobuf-dev");
}
};
}
if os_type == os_info::Type::FreeBSD {
match Command::new("pkg").args(["install", "protobuf"]).output() {
Ok(_) => {}
_ => {
println!("failed to install protobuf");
}
};
}
if os_type == os_info::Type::Alpine {
match Command::new("apk")
.args(["add", "protoc", "protobuf-dev"])
.output()
{
Ok(_) => {}
_ => {
println!("failed to install protoc and protobuf-dev");
}
};
}
if os_type == os_info::Type::CentOS {
match Command::new("yum").args(["install", "protobuf"]).output() {
Ok(_) => {}
_ => {
println!("failed to install protobuf");
}
};
}
if os_type == os_info::Type::Fedora {
match Command::new("snap")
.args(["install", "protobuf", "--classic"])
.output()
{
Ok(_) => {}
_ => {
println!("failed to install protobuf from snap");
}
};
}
// brew install protobuf ( does not accept xcode licenses )
if os_type == os_info::Type::Macos {
match Command::new("brew").arg("--version").output() {
Ok(_) => {}
_ => {
match Command::new("curl")
.args([
"-fsSL",
"-o",
"install.sh",
"https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh",
])
.output()
{
Ok(_) => {
match Command::new("./install.sh").output() {
Ok(_) => {
match Command::new("echo")
.args([
"export PATH=/usr/local/bin:$PATH",
">",
"~/.bash_profile",
])
.output()
{
Ok(_) => {}
_ => {
println!("failed to update $PATH");
}
};
}
_ => {
println!("failed to run install.sh");
}
};
}
_ => {
println!("failed to curl brew install.sh");
}
};
}
};
match Command::new("brew").args(["install", "protobuf"]).output() {
Ok(_) => {}
_ => {
println!("failed to install protobuf");
}
};
}
if os_type == os_info::Type::Windows {
// todo: check 32 bit or 64 bit
// protoc-21.12-win32.zip
// protoc-21.12-win64.zip
// download and extract to path
println!("windows installation wip.");
}
}
Ok(())
}