Skip to content

Commit e9802c2

Browse files
committed
Merge branch 'rust-prost-2'
2 parents cbf2184 + 7b3f5f1 commit e9802c2

File tree

192 files changed

+35367
-104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

192 files changed

+35367
-104
lines changed

.ci/ci

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ make prepare-tidy
2323
make -j8 unit-test
2424
make -j8 run-unit-tests
2525
make -j8 run-rust-unit-tests
26+
27+
# Rust linter
28+
make -j8 run-rust-clippy
29+
2630
# Check that coverage report building is working.
2731
make coverage
2832

messages/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ add_custom_command(
5151
--proto_path=${CMAKE_CURRENT_SOURCE_DIR}
5252
'--nanopb_out=-I${CMAKE_CURRENT_SOURCE_DIR}:${CMAKE_CURRENT_BINARY_DIR}'
5353
${PROTO_FILES_ABSOLUTE}
54+
# We build the Rust protobuf files here and put them straight into the crate.
55+
# This way, the crate can be compiled and tested without relying on cmake environment vars.
56+
# Using prost-build the normal way as part of build.rs does not work due to a cargo bug:
57+
# https://github.com/danburkert/prost/issues/344#issuecomment-650721245
58+
COMMAND
59+
${CMAKE_COMMAND} -E env
60+
cargo run --manifest-path=${CMAKE_SOURCE_DIR}/tools/prost-build/Cargo.toml -- --messages-dir=${CMAKE_CURRENT_SOURCE_DIR} --out-dir=${CMAKE_SOURCE_DIR}/src/rust/bitbox02-rust/src/hww/api/
5461
)
5562

5663
add_custom_target(

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ add_custom_target(rust-bindgen
373373
--whitelist-type commander_error_t
374374
--rustified-enum commander_error_t
375375
--whitelist-function commander
376+
--whitelist-function commander_states_can_call
377+
--whitelist-function commander_states_clear_force_next
376378
--whitelist-type BitBoxBaseRequest
377379
--whitelist-var ".*_tag"
378380
--whitelist-var MAX_LABEL_SIZE

src/commander/commander.c

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,6 @@ static commander_error_t _api_get_info(DeviceInfoResponse* device_info)
123123
return COMMANDER_OK;
124124
}
125125

126-
static commander_error_t _api_set_device_name(const SetDeviceNameRequest* request)
127-
{
128-
const confirm_params_t params = {
129-
.title = "Name",
130-
.body = request->name,
131-
.scrollable = true,
132-
};
133-
if (!workflow_confirm_blocking(&params)) {
134-
return COMMANDER_ERR_USER_ABORT;
135-
}
136-
if (!memory_set_device_name(request->name)) {
137-
return COMMANDER_ERR_MEMORY;
138-
}
139-
return COMMANDER_OK;
140-
}
141-
142126
static commander_error_t _api_set_password(const SetPasswordRequest* request)
143127
{
144128
if (!workflow_create_seed(request->entropy)) {
@@ -282,9 +266,6 @@ static commander_error_t _api_process(const Request* request, Response* response
282266
case Request_device_info_tag:
283267
response->which_response = Response_device_info_tag;
284268
return _api_get_info(&(response->response.device_info));
285-
case Request_device_name_tag:
286-
response->which_response = Response_success_tag;
287-
return _api_set_device_name(&(request->request.device_name));
288269
case Request_set_password_tag:
289270
response->which_response = Response_success_tag;
290271
return _api_set_password(&(request->request.set_password));
@@ -381,17 +362,8 @@ void commander(const in_buffer_t* in_buf, buffer_t* out_buf)
381362
commander_error_t err =
382363
protobuf_decode(in_buf, &request) ? COMMANDER_OK : COMMANDER_ERR_INVALID_INPUT;
383364
if (err == COMMANDER_OK) {
384-
if (!commander_states_can_call(request.which_request)) {
385-
err = COMMANDER_ERR_INVALID_STATE;
386-
} else {
387-
// Since we will process the call now, so can clear the 'force next' info.
388-
// We do this before processing as the api call can potentially define the next api call
389-
// to be forced.
390-
commander_states_clear_force_next();
391-
392-
err = _api_process(&request, &response);
393-
util_zero(&request, sizeof(request));
394-
}
365+
err = _api_process(&request, &response);
366+
util_zero(&request, sizeof(request));
395367
}
396368
if (err != COMMANDER_OK) {
397369
_report_error(&response, err);
@@ -401,10 +373,6 @@ void commander(const in_buffer_t* in_buf, buffer_t* out_buf)
401373
}
402374

403375
#ifdef TESTING
404-
commander_error_t commander_api_set_device_name(const SetDeviceNameRequest* request)
405-
{
406-
return _api_set_device_name(request);
407-
}
408376
commander_error_t commander_api_set_mnemonic_passphrase_enabled(
409377
const SetMnemonicPassphraseEnabledRequest* request)
410378
{

src/rust/Cargo.lock

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rust/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ lto = true
3333

3434
[profile.dev]
3535
opt-level = 'z'
36+
37+
[patch.crates-io]
38+
bytes = { git = "https://github.com/digitalbitbox/bytes.git", branch = "bitbox02-firmware-20200702" }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl CStrMut {
189189
/// then are available.
190190
pub fn write<F>(&mut self, req: usize, f: F)
191191
where
192-
F: FnOnce(&mut [u8]) -> (),
192+
F: FnOnce(&mut [u8]),
193193
{
194194
// Must be room for requested amount of bytes and null terminator.
195195
if self.cap - self.len < req + 1 {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub unsafe extern "C" fn rust_workflow_confirm_blocking(
155155
) -> bool {
156156
let title = crate::util::rust_util_cstr(params.title);
157157
let body = crate::util::rust_util_cstr(params.body);
158-
if params.font != core::ptr::null() {
158+
if !params.font.is_null() {
159159
panic!("Only default font supported");
160160
}
161161
let params = confirm::Params {

src/rust/bitbox02-rust/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,10 @@ bitbox02-noise = {path = "../bitbox02-noise"}
3535
version = "0.5.1"
3636
# Disable the "std" feature
3737
default-features = false
38+
39+
[dependencies.prost]
40+
git = "https://github.com/danburkert/prost.git"
41+
# keep rev in sync with tools/prost-build/Cargo.toml
42+
rev = "6113789f70b69709820becba4242824b4fb3ffec"
43+
default-features = false
44+
features = ["prost-derive"]

0 commit comments

Comments
 (0)