Skip to content

Commit 23be89d

Browse files
committed
rust: add c-unit-testing feature
The `testing` feature is enabled for *Rust* unit tests, but not for the Rust code when compiled to be linked to the *C* unit tests. We want to add a simulator in the unit-test directory (as C unit tests are already standalone host binaries that link the full C/Rust firmware code), but need a way to change behavior for the simulator only. The `testing` flag is not enabled there as mentioned above. We add a `c-unit-testing` feature that is active only in Rust code when linked to the C unit tests (including the simulator) for this purpose. We wanted to simply enable `testing` there as well, but ran into compilation problems when compiling the Rust unit tests: ``` /usr/bin/ld: .../build-build-rust-unit-tests/src/../lib/libbitbox_merged.a(bitbox02_rust_c-06ac99f37ae6bb45.bitbox02_rust_c.ff44fdfedc2996e0-cgu.0.rcgu.o):(.init_array.00099+0x0): multiple definition of `std::sys::unix::args::imp::ARGV_INIT_ARRAY'; .../build-build-rust-unit-tests/src/rust/target/all-features/release/deps/bitbox02-5ad04c78e548693d.bitbox02.5d97720ccc25f2c4-cgu.0.rcgu.o:(.init_array.00099+0x0): first defined here ```
1 parent 91dc87f commit 23be89d

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

src/rust/bitbox02-rust-c/Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,21 @@ target-c-unit-tests = [
5959
# enable these features
6060
"app-bitcoin",
6161
"app-ethereum",
62-
"firmware"
62+
"firmware",
63+
"c-unit-testing",
6364
]
6465

6566
platform-bitbox02 = []
6667

6768
bootloader = []
6869
firmware = ["bitbox02-rust", "bitbox02", "bitbox02-noise", "sha2"]
6970

70-
# Only to be enabled in unit tests.
71+
# Only to be enabled in Rust unit tests.
7172
testing = ["bitbox02-rust/testing", "bitbox02/testing"]
7273

74+
# Active when the Rust code is compiled to be linked into the C unit tests and simulator.
75+
c-unit-testing = ["bitbox02-rust/c-unit-testing", "bitbox02/c-unit-testing"]
76+
7377
app-ethereum = [
7478
# enable this dep
7579
"sha3",

src/rust/bitbox02-rust/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,6 @@ testing = [
115115

116116
# enable these features
117117
"bitbox02/testing"
118-
]
118+
]
119+
120+
c-unit-testing = []

src/rust/bitbox02/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ lazy_static = { version = "1.4.0", optional = true }
2929
[features]
3030
# Only to be enabled in unit tests.
3131
testing = ["lazy_static"]
32+
# Active when the Rust code is compiled to be linked into the C unit tests and simulator.
33+
c-unit-testing = []
3234

3335
app-ethereum = []
3436
app-bitcoin = []

src/rust/bitbox02/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ pub fn reboot() -> ! {
176176
panic!("reboot called")
177177
}
178178

179-
#[cfg(feature = "testing")]
179+
#[cfg(any(feature = "testing", feature = "c-unit-testing"))]
180180
pub fn print_stdout(msg: &str) {
181181
unsafe {
182182
bitbox02_sys::printf(crate::util::str_to_cstr_vec(msg).unwrap().as_ptr());

0 commit comments

Comments
 (0)