Skip to content

Commit 016639b

Browse files
committed
rust: Don't panic in build.rs script
In this commit the error of missing the cmake build directory is downgraded to a warning. When rust-analyzer and clippy builds the project they will not link the final binary. Therefore it is OK if we are missing the cmake build directory.
1 parent 73aa02f commit 016639b

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

src/rust/bitbox02/build.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
fn main() {
22
#[cfg(feature = "testing")]
33
{
4-
let cmake_dir = std::env::var("CMAKE_CURRENT_BINARY_DIR").unwrap();
5-
println!("cargo:rustc-link-search={}/../lib", cmake_dir);
6-
// c and rust code merged :O
7-
println!("cargo:rustc-link-lib=bitbox_merged");
8-
println!(
9-
"cargo:rerun-if-changed={}/../lib/libbitbox_merged.a",
10-
cmake_dir
11-
);
4+
if let Ok(cmake_dir) = std::env::var("CMAKE_CURRENT_BINARY_DIR") {
5+
println!("cargo:rustc-link-search={}/../lib", cmake_dir);
6+
// c and rust code merged :O
7+
println!("cargo:rustc-link-lib=bitbox_merged");
8+
println!(
9+
"cargo:rerun-if-changed={}/../lib/libbitbox_merged.a",
10+
cmake_dir
11+
);
1212

13-
// external libs
14-
println!("cargo:rustc-link-lib=wallycore");
15-
println!("cargo:rustc-link-lib=secp256k1");
16-
println!("cargo:rustc-link-lib=ctaes");
17-
println!("cargo:rustc-link-lib=fatfs");
18-
println!("cargo:rustc-link-lib=sd-mock");
13+
// external libs
14+
println!("cargo:rustc-link-lib=wallycore");
15+
println!("cargo:rustc-link-lib=secp256k1");
16+
println!("cargo:rustc-link-lib=ctaes");
17+
println!("cargo:rustc-link-lib=fatfs");
18+
println!("cargo:rustc-link-lib=sd-mock");
1919

20-
// system libs
21-
println!("cargo:rustc-link-lib=cmocka");
20+
// system libs
21+
println!("cargo:rustc-link-lib=cmocka");
22+
} else {
23+
// This is useful in case project is built by tool that doesn't need to link the final
24+
// target, like rust-analyzer and clippy.
25+
eprintln!("Missing env variable CMAKE_CURRENT_BINARY_DIR, linking will fail");
26+
}
2227
}
2328
}

0 commit comments

Comments
 (0)