Skip to content

Commit 8e7882f

Browse files
committed
fix: remove unwraps in proto build script
1 parent eeed3a6 commit 8e7882f

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

crates/proto/build.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
1+
use std::io::Write;
12
use std::path::PathBuf;
23

34
fn main() -> Result<(), Box<dyn std::error::Error>> {
4-
let out_dir =
5-
PathBuf::from(std::env::var("OUT_DIR").expect("OUT_DIR environment variable not set"));
6-
let target = std::env::var("TARGET").expect("TARGET environment variable not set");
7-
let feature_client = std::env::var("CARGO_FEATURE_CLIENT");
8-
let feature_server = std::env::var("CARGO_FEATURE_SERVER");
5+
let out_dir = PathBuf::from(std::env::var("OUT_DIR")?);
6+
let target = std::env::var("TARGET")?;
7+
let feature_client = std::env::var("CARGO_FEATURE_CLIENT").is_ok();
8+
let feature_server = std::env::var("CARGO_FEATURE_SERVER").is_ok();
99

1010
if target.contains("wasm32") {
11-
if feature_server.is_ok() {
12-
panic!("feature `server` is not supported on target `{target}`");
11+
if feature_server {
12+
return Err(format!(
13+
"feature `server` is not supported on target `{target}`"
14+
)
15+
.into());
1316
}
1417

1518
wasm_tonic_build::configure()
1619
.build_server(false)
17-
.build_client(feature_client.is_ok())
20+
.build_client(feature_client)
1821
.file_descriptor_set_path(out_dir.join("world_descriptor.bin"))
1922
.compile_protos(&["proto/world.proto"], &["proto"])?;
2023
} else {
2124
tonic_build::configure()
22-
.build_server(feature_server.is_ok())
23-
.build_client(feature_client.is_ok())
25+
.build_server(feature_server)
26+
.build_client(feature_client)
2427
.file_descriptor_set_path(out_dir.join("world_descriptor.bin"))
2528
.compile(&["proto/world.proto"], &["proto"])?;
2629
}
2730

28-
println!("cargo:rerun-if-changed=proto");
31+
std::io::stdout().write_all(b"cargo:rerun-if-changed=proto\n")?;
2932

3033
Ok(())
3134
}

0 commit comments

Comments
 (0)