|
| 1 | +use std::io::Write; |
1 | 2 | use std::path::PathBuf; |
2 | 3 |
|
3 | 4 | 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(); |
9 | 9 |
|
10 | 10 | 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()); |
13 | 16 | } |
14 | 17 |
|
15 | 18 | wasm_tonic_build::configure() |
16 | 19 | .build_server(false) |
17 | | - .build_client(feature_client.is_ok()) |
| 20 | + .build_client(feature_client) |
18 | 21 | .file_descriptor_set_path(out_dir.join("world_descriptor.bin")) |
19 | 22 | .compile_protos(&["proto/world.proto"], &["proto"])?; |
20 | 23 | } else { |
21 | 24 | 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) |
24 | 27 | .file_descriptor_set_path(out_dir.join("world_descriptor.bin")) |
25 | 28 | .compile(&["proto/world.proto"], &["proto"])?; |
26 | 29 | } |
27 | 30 |
|
28 | | - println!("cargo:rerun-if-changed=proto"); |
| 31 | + std::io::stdout().write_all(b"cargo:rerun-if-changed=proto\n")?; |
29 | 32 |
|
30 | 33 | Ok(()) |
31 | 34 | } |
0 commit comments