Skip to content

Commit a753eed

Browse files
committed
fix(build): improve error messages when cmake is not found
Replace bare .unwrap() calls on cmake Command invocations with descriptive error handling.
1 parent 0eadd82 commit a753eed

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

libbitcoinkernel-sys/build.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main() {
1717

1818
let build_config = "RelWithDebInfo";
1919

20-
Command::new("cmake")
20+
let configure_status = Command::new("cmake")
2121
.arg("-B")
2222
.arg(&build_dir)
2323
.arg("-S")
@@ -42,29 +42,44 @@ fn main() {
4242
.arg("-DENABLE_IPC=OFF")
4343
.arg(format!("-DCMAKE_INSTALL_PREFIX={}", install_dir.display()))
4444
.status()
45-
.unwrap();
45+
.unwrap_or_else(|e| panic!("Failed to run cmake configure: {e}."));
46+
47+
if !configure_status.success() {
48+
panic!("cmake configure failed (exit status: {configure_status}).");
49+
}
4650

4751
let num_jobs = env::var("NUM_JOBS")
4852
.ok()
4953
.and_then(|v| v.parse::<u32>().ok())
5054
.unwrap_or(1); // Default to 1 if not set
5155

52-
Command::new("cmake")
56+
let build_status = Command::new("cmake")
5357
.arg("--build")
5458
.arg(&build_dir)
5559
.arg("--config")
5660
.arg(build_config)
5761
.arg(format!("--parallel={num_jobs}"))
5862
.status()
59-
.unwrap();
63+
.unwrap_or_else(|e| panic!("Failed to run cmake build: {e}."));
64+
65+
if !build_status.success() {
66+
panic!(
67+
"cmake build failed (exit status: {build_status}). Check the build output above for details. Build directory: '{}'",
68+
build_dir.display()
69+
);
70+
}
6071

61-
Command::new("cmake")
72+
let install_status = Command::new("cmake")
6273
.arg("--install")
6374
.arg(&build_dir)
6475
.arg("--config")
6576
.arg(build_config)
6677
.status()
67-
.unwrap();
78+
.unwrap_or_else(|e| panic!("Failed to run cmake install: {e}"));
79+
80+
if !install_status.success() {
81+
panic!("cmake install failed (exit status: {install_status}).");
82+
}
6883

6984
// Check if the build system used a multi-config generator
7085
let lib_dir = if install_dir.join("lib").join(build_config).exists() {

0 commit comments

Comments
 (0)