Skip to content

Commit bf7b135

Browse files
authored
Merge pull request #1295 from NickeZ/nickez/rust-version-optional
Nickez/rust version optional
2 parents 70a2929 + 91683a1 commit bf7b135

File tree

3 files changed

+43
-17
lines changed

3 files changed

+43
-17
lines changed

src/rust/bitbox02-rust/build.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2024 Shift Crypto AG
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Emit a warning if FIRMWARE_VERSION_SHORT isn't set. We don't want this to be a hard error during
16+
// development so that rust tools are happy.
17+
fn main() {
18+
let version = option_env!("FIRMWARE_VERSION_SHORT");
19+
if let Some(version) = version {
20+
if version.is_empty() {
21+
println!("cargo::warning=FIRMWARE_VERSION_SHORT is empty");
22+
}
23+
} else {
24+
println!("cargo::warning=FIRMWARE_VERSION_SHORT is not set");
25+
}
26+
}

src/rust/bitbox02-rust/src/version.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@
1313
// limitations under the License.
1414

1515
/// Firmware version, short format, e.g. "v9.12.0".
16-
// This is evaluated at compile time, if the env var is missing or not set, there will be a compiler error.
16+
// We don't want this to be a hard error during development so that rust tools are happy.
1717
pub static FIRMWARE_VERSION_SHORT: &str = {
18-
let version = env!("FIRMWARE_VERSION_SHORT");
19-
// Need explicit check as the env var could be set to an empty string accidentally (env!() only
20-
// panics if it is not set at all).
21-
if version.is_empty() {
22-
panic!("FIRMWARE_VERSION_SHORT is not set");
18+
let version = option_env!("FIRMWARE_VERSION_SHORT");
19+
if let Some(version) = version {
20+
version
21+
} else {
22+
""
2323
}
24-
version
2524
};

src/rust/bitbox02/build.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,28 @@ fn main() {
22
#[cfg(feature = "testing")]
33
{
44
if let Ok(cmake_dir) = std::env::var("CMAKE_CURRENT_BINARY_DIR") {
5-
println!("cargo:rustc-link-search={}/../lib", cmake_dir);
5+
println!("cargo::rustc-link-search={}/../lib", cmake_dir);
66
// c and rust code merged :O
7-
println!("cargo:rustc-link-lib=bitbox_merged");
7+
println!("cargo::rustc-link-lib=bitbox_merged");
88
println!(
9-
"cargo:rerun-if-changed={}/../lib/libbitbox_merged.a",
9+
"cargo::rerun-if-changed={}/../lib/libbitbox_merged.a",
1010
cmake_dir
1111
);
12+
println!("cargo::rerun-if-changed=build.rs");
1213

1314
// 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");
15+
println!("cargo::rustc-link-lib=wallycore");
16+
println!("cargo::rustc-link-lib=secp256k1");
17+
println!("cargo::rustc-link-lib=ctaes");
18+
println!("cargo::rustc-link-lib=fatfs");
19+
println!("cargo::rustc-link-lib=sd-mock");
1920

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

0 commit comments

Comments
 (0)