Skip to content

Commit 4a5b65c

Browse files
committed
rust: update toolchain to 1.65.0
rust-bindgen CLI is now available under `bindgen-cli`. The CHANGELOG (https://github.com/rust-lang/rust-bindgen/blob/0631a27bee19601e393e31e7dfc2563412b2fe01/CHANGELOG.md#0610) mentions at 0.61.0: > The --size_t-is-usize flag is enabled by default. Since we previously manually set size_t to usize anyway, we can adopt this change and just use usize everywhere. Rust 1.65.0 uses LLVM 15. For the C unit tests, the LLVM version installed in Docker must be at least the version that Rust uses for compatibility, so we update to LLVM-15 (this was the intention in #1001, but updating llvm was missed). New clippy linter results are addressed. rust_eh_personality now seems to be included by Rust in the Rust unit tests and we only need to include it in the C unit tests :S Signed-off-by: Marko Bencun <[email protected]>
1 parent 1a930f8 commit 4a5b65c

File tree

19 files changed

+53
-45
lines changed

19 files changed

+53
-45
lines changed

.ci/run-container-ci

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
set -e
2626
set -x
2727

28-
CONTAINER=shiftcrypto/firmware_v2:28
28+
CONTAINER=shiftcrypto/firmware_v2:29
2929

3030
if [ "$1" == "pull" ] ; then
3131
docker pull "$CONTAINER"

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ RUN mkdir ~/Downloads &&\
3737
# Tools for building
3838
RUN apt-get update && apt-get install -y \
3939
build-essential \
40-
llvm \
40+
llvm-15 \
4141
gcc-10 \
4242
binutils \
4343
valgrind \
@@ -129,8 +129,8 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | CARGO_HOME=/opt/
129129
RUN rustup target add thumbv7em-none-eabi
130130
RUN rustup component add rustfmt
131131
RUN rustup component add clippy
132-
RUN CARGO_HOME=/opt/cargo cargo install cbindgen --version 0.23.0
133-
RUN CARGO_HOME=/opt/cargo cargo install bindgen --version 0.59.2
132+
RUN CARGO_HOME=/opt/cargo cargo install cbindgen --version 0.24.3
133+
RUN CARGO_HOME=/opt/cargo cargo install bindgen-cli --version 0.61.0
134134

135135
COPY tools/prost-build prost-build
136136
RUN CARGO_HOME=/opt/cargo cargo install --path prost-build --locked

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,8 @@ if(NOT CMAKE_CROSSCOMPILING)
453453
-A clippy::manual_range_contains
454454
-A clippy::match_ref_pats
455455
-A clippy::enum_variant_names
456+
-A clippy::derive_partial_eq_without_eq
457+
-A clippy::forget_non_drop
456458
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/rust/
457459
)
458460
add_dependencies(rust-clippy rust-bindgen generate-protobufs)

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ sha3 = { version = "0.9.1", default-features = false, optional = true }
3333
bs58 = { version = "0.4.0", default-features = false, features = ["alloc", "check"] }
3434

3535
[features]
36-
# "Negative" feature is a hack because tests are ran with `--all-features`, currently without a way to exclude specific features.
37-
# This should be enabled for Rust unit tests and Clippy, and not enabled for the firmware targets and the C unit tests.
38-
dont-export-eh-personality = []
39-
4036
# Only one of the "target-" should be activated, which in turn defines/activates the dependent features.
4137
target-bootloader = ["bootloader", "platform-bitbox02"]
4238
target-bootloader-development = ["bootloader", "platform-bitbox02"]

src/rust/bitbox02-rust-c/src/alloc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn bitbox02_alloc_error_handler(layout: core::alloc::Layout) -> ! {
2323
struct BB02Allocator;
2424

2525
extern "C" {
26-
pub fn malloc(size: util::c_types::size_t) -> *mut util::c_types::c_void;
26+
pub fn malloc(size: usize) -> *mut util::c_types::c_void;
2727
pub fn free(p: *mut util::c_types::c_void);
2828
}
2929

src/rust/bitbox02-rust-c/src/lib.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,3 @@ fn panic(info: &core::panic::PanicInfo) -> ! {
5151
bitbox02_rust::print_debug!(0, "Error: {}", info);
5252
loop {}
5353
}
54-
55-
// Needed to link the C unit test executables in /test/unit-test.
56-
//
57-
// See https://doc.rust-lang.org/unstable-book/language-features/lang-items.html#writing-an-executable-without-stdlib.
58-
//
59-
// One could get rid of this and also considerably shrink the binary size by compiling core instead
60-
// of using pre-built binaries. See a proof of concept implementation here:
61-
// https://github.com/digitalbitbox/bitbox02-firmware/tree/build-std-PoC. We decided against doing
62-
// this for now as the feature seems immature and because of the warnings against using it in
63-
// production:
64-
// https://github.com/rust-lang/wg-cargo-std-aware/tree/81765f0eb744b9c47840c16f43a32c9f61fd7f0c#mvp-implementation
65-
#[cfg(not(feature = "dont-export-eh-personality"))]
66-
#[lang = "eh_personality"]
67-
#[no_mangle]
68-
pub extern "C" fn rust_eh_personality() {}

src/rust/bitbox02-rust-c/src/sha2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub unsafe extern "C" fn rust_sha256_finish(ctx: *mut *mut c_void, out: *mut c_u
5757
pub unsafe extern "C" fn rust_sha256_free(ctx: *mut *mut c_void) {
5858
if !(*ctx).is_null() {
5959
#[allow(clippy::cast_ptr_alignment)] // ctx is properly aligned, see `Box::into_raw`.
60-
Box::from_raw(*ctx as *mut Sha256);
60+
drop(Box::from_raw(*ctx as *mut Sha256));
6161
*ctx = core::ptr::null_mut();
6262
}
6363
}

src/rust/bitbox02-rust/src/backup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn compute_checksum(
8686
result[..name.len()].copy_from_slice(name);
8787
result
8888
};
89-
hasher.update(&padded_name);
89+
hasher.update(padded_name);
9090
hasher.update(data.seed_length.to_le_bytes());
9191
if data.seed.len() != 32 {
9292
return Err(());
@@ -102,7 +102,7 @@ fn compute_checksum(
102102
result[..generator.len()].copy_from_slice(generator);
103103
result
104104
};
105-
hasher.update(&padded_generator);
105+
hasher.update(padded_generator);
106106
hasher.update(data_length.to_le_bytes());
107107
Ok(hasher.finalize().to_vec())
108108
}

src/rust/bitbox02-rust/src/hww/api/bitcoin.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,7 @@ pub async fn process_pub(request: &pb::BtcPubRequest) -> Result<Response, Error>
214214
Some(coin) => coin,
215215
None => return Err(Error::InvalidInput),
216216
};
217-
if let Err(err) = coin_enabled(coin) {
218-
return Err(err);
219-
}
217+
coin_enabled(coin)?;
220218
match request.output {
221219
None => Err(Error::InvalidInput),
222220
Some(Output::XpubType(xpub_type)) => {

src/rust/bitbox02-rust/src/hww/api/bitcoin/bip341.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ pub struct Args {
3838
pub fn sighash(args: &Args) -> [u8; 32] {
3939
let tag = Sha256::digest(b"TapSighash");
4040
let mut ctx = Sha256::new();
41-
ctx.update(&tag);
42-
ctx.update(&tag);
41+
ctx.update(tag);
42+
ctx.update(tag);
4343
// Sighash epoch 0
4444
ctx.update(0u8.to_le_bytes());
4545
// Control:

0 commit comments

Comments
 (0)