@@ -188,9 +188,6 @@ set(BOOTLOADER-SOURCES
188
188
${DRIVER-SOURCES}
189
189
)
190
190
191
- # rust-bindgen to generate rust declarations from c-headers.
192
- # The compiled binary to avoid recompiling bindgen on every clean build
193
- find_program (BINDGEN bindgen )
194
191
# cbindgen is used to generate the c-headers from rust code.
195
192
find_program (CBINDGEN cbindgen )
196
193
# cargo is the rust build system and dependency manager
@@ -270,156 +267,6 @@ if(NOT CMAKE_CROSSCOMPILING)
270
267
list (APPEND RUST_INCLUDES -I${CMAKE_SOURCE_DIR}/test/unit-test/framework/includes )
271
268
endif ()
272
269
273
- if (CMAKE_CROSSCOMPILING )
274
- set (RUST_BINDGEN_FLAGS -D__SAMD51J20A__ --target=thumbv7em-none-eabi -mcpu=cortex-m4 -mthumb -mfloat-abi=soft --sysroot=${CMAKE_SYSROOT}
275
- # APP_ vars active when compiling C code to be used in Rust. It
276
- # is okay to activate all of them here - Rust's 'app-' features
277
- # control usage/compilation in Rust.
278
- -DAPP_U2F=1 # needed to wrap securechip_u2f_counter_set() in Rust.
279
- )
280
- else ()
281
- set (RUST_BINDGEN_FLAGS -DTESTING=1 )
282
- endif ()
283
-
284
- add_custom_target (rust-bindgen
285
- # Generate rust bindings
286
- COMMAND
287
- ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR} /rust
288
- COMMAND
289
- ${BINDGEN}
290
- --output ${CMAKE_CURRENT_BINARY_DIR} /rust/bindings.rs.out
291
- --use-core
292
- --with-derive-default
293
- --ctypes-prefix util::c_types
294
- --allowlist-function bip32_derive_xpub
295
- --allowlist-function localtime
296
- --allowlist-function wally_free_string
297
- --allowlist-function mock_memory_factoryreset
298
- --allowlist-function memory_setup
299
- --allowlist-function memory_is_initialized
300
- --allowlist-function memory_set_initialized
301
- --allowlist-function memory_is_seeded
302
- --allowlist-function memory_is_mnemonic_passphrase_enabled
303
- --allowlist-function memory_get_attestation_pubkey_and_certificate
304
- --allowlist-function memory_get_attestation_bootloader_hash
305
- --allowlist-function memory_bootloader_hash
306
- --allowlist-function memory_get_noise_static_private_key
307
- --allowlist-function memory_check_noise_remote_static_pubkey
308
- --allowlist-function memory_add_noise_remote_static_pubkey
309
- --allowlist-function memory_get_device_name
310
- --allowlist-function memory_set_device_name
311
- --allowlist-function memory_set_mnemonic_passphrase_enabled
312
- --allowlist-var MEMORY_MULTISIG_NAME_MAX_LEN
313
- --allowlist-function memory_set_seed_birthdate
314
- --allowlist-function memory_get_seed_birthdate
315
- --allowlist-function memory_multisig_get_by_hash
316
- --allowlist-function memory_multisig_set_by_hash
317
- --allowlist-function smarteeprom_bb02_config
318
- --allowlist-function bitbox02_smarteeprom_init
319
- --rustified-enum memory_result_t
320
- --allowlist-var MEMORY_DEVICE_NAME_MAX_LEN
321
- --allowlist-function securechip_attestation_sign
322
- --allowlist-function securechip_monotonic_increments_remaining
323
- --allowlist-function securechip_u2f_counter_set
324
- --allowlist-function securechip_model
325
- --rustified-enum securechip_model_t
326
- --allowlist-var KEYSTORE_MAX_SEED_LENGTH
327
- --allowlist-function keystore_is_locked
328
- --allowlist-function keystore_unlock
329
- --allowlist-function keystore_unlock_bip39
330
- --allowlist-function keystore_lock
331
- --allowlist-function keystore_create_and_store_seed
332
- --allowlist-function keystore_copy_seed
333
- --allowlist-function keystore_get_bip39_mnemonic
334
- --allowlist-function keystore_get_bip39_word
335
- --allowlist-function keystore_get_ed25519_seed
336
- --allowlist-function keystore_bip85_bip39
337
- --allowlist-function keystore_bip85_ln
338
- --allowlist-function keystore_secp256k1_compressed_to_uncompressed
339
- --allowlist-function keystore_secp256k1_nonce_commit
340
- --allowlist-function keystore_secp256k1_sign
341
- --allowlist-function keystore_secp256k1_schnorr_bip86_sign
342
- --allowlist-function keystore_bip39_mnemonic_to_seed
343
- --allowlist-function keystore_mock_unlocked
344
- --allowlist-var EC_PUBLIC_KEY_UNCOMPRESSED_LEN
345
- --allowlist-var EC_PUBLIC_KEY_LEN
346
- --allowlist-function keystore_encode_xpub_at_keypath
347
- --allowlist-function keystore_encrypt_and_store_seed
348
- --allowlist-var XPUB_ENCODED_LEN
349
- --allowlist-var BIP32_SERIALIZED_LEN
350
- --allowlist-function lock_animation_start
351
- --allowlist-function lock_animation_stop
352
- --allowlist-function delay_us
353
- --rustified-enum keystore_error_t
354
- --rustified-enum keystore_secp256k1_pubkey_format
355
- --allowlist-function keystore_secp256k1_schnorr_bip86_pubkey
356
- --allowlist-function util_format_datetime
357
- --allowlist-type buffer_t
358
- --allowlist-function delay_ms
359
- --allowlist-function UG_PutString
360
- --allowlist-function UG_FontSelect
361
- --allowlist-function UG_ClearBuffer
362
- --allowlist-function UG_SendBuffer
363
- --allowlist-function screen_print_debug
364
- --allowlist-function ui_screen_stack_push
365
- --allowlist-function ui_screen_stack_pop
366
- --allowlist-function ui_screen_stack_pop_all
367
- --allowlist-function screen_saver_disable
368
- --allowlist-function screen_saver_enable
369
- --allowlist-function screen_process
370
- --allowlist-function label_create
371
- --allowlist-function confirm_create
372
- --allowlist-function status_create
373
- --allowlist-function sdcard_create
374
- --allowlist-function menu_create
375
- --allowlist-function trinary_choice_create
376
- --rustified-enum trinary_choice_t
377
- --allowlist-var BASE58_CHECKSUM_LEN
378
- --allowlist-function random_32_bytes_mcu
379
- --allowlist-function random_mock_reset
380
- --allowlist-type component_t
381
- --allowlist-type confirm_params_t
382
- --allowlist-var MAX_LABEL_SIZE
383
- --allowlist-var font_font_a_9X9
384
- --allowlist-var font_font_a_11X10
385
- --allowlist-var font_monogram_5X9
386
- --allowlist-var font_password_11X12
387
- --allowlist-type trinary_input_string_params_t
388
- --allowlist-var INPUT_STRING_MAX_SIZE
389
- --allowlist-function trinary_input_string_create
390
- --allowlist-function trinary_input_string_set_input
391
- --allowlist-function confirm_transaction_address_create
392
- --allowlist-function confirm_transaction_fee_create
393
- --allowlist-function progress_create
394
- --allowlist-function progress_set
395
- --allowlist-function empty_create
396
- --allowlist-function reset_reset
397
- --allowlist-function sd_card_inserted
398
- --allowlist-function sd_format
399
- --allowlist-function sd_list_subdir
400
- --allowlist-function sd_erase_file_in_subdir
401
- --allowlist-function sd_load_bin
402
- --allowlist-function sd_write_bin
403
- --allowlist-var SD_MAX_FILE_SIZE
404
- --allowlist-function sd_free_list
405
- --allowlist-var BIP39_WORDLIST_LEN
406
- --rustified-enum simple_type_t
407
- --rustified-enum multisig_script_type_t
408
- --rustified-enum output_type_t
409
- --allowlist-var MAX_VARINT_SIZE
410
- --allowlist-var MAX_PK_SCRIPT_SIZE
411
- --allowlist-function reboot
412
- --allowlist-function secp256k1_ecdsa_anti_exfil_host_commit
413
- --allowlist-function wally_get_secp_context
414
- --allowlist-function wally_hash160
415
- --allowlist-function wally_sha512
416
- --allowlist-function printf
417
- ${CMAKE_CURRENT_SOURCE_DIR} /rust/bitbox02-sys/wrapper.h --
418
- -DPB_NO_PACKED_STRUCTS=1 -DPB_FIELD_16BIT=1 -fshort-enums ${RUST_BINDGEN_FLAGS} ${RUST_INCLUDES}
419
- COMMAND
420
- ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR} /rust/bindings.rs.out ${CMAKE_CURRENT_BINARY_DIR} /rust/bindings.rs
421
- )
422
-
423
270
424
271
# Test rust crates that contain business logic. Avoid testing crates that depend on hardware.
425
272
if (NOT CMAKE_CROSSCOMPILING )
@@ -429,6 +276,7 @@ if(NOT CMAKE_CROSSCOMPILING)
429
276
add_custom_target (rust-test
430
277
COMMAND
431
278
${CMAKE_COMMAND} -E env
279
+ CMAKE_SYSROOT=${CMAKE_SYSROOT}
432
280
CMAKE_CURRENT_BINARY_DIR =${CMAKE_CURRENT_BINARY_DIR}
433
281
FIRMWARE_VERSION_SHORT=${FIRMWARE_VERSION}
434
282
# only one test thread because of unsafe concurrent access to `SafeData`, `mock_sd()` and `mock_memory()`. Using mutexes instead leads to mutex poisoning and very messy output in case of a unit test failure.
@@ -443,6 +291,7 @@ if(NOT CMAKE_CROSSCOMPILING)
443
291
${CARGO} clean --target-dir ${RUST_BINARY_DIR}
444
292
COMMAND
445
293
${CMAKE_COMMAND} -E env
294
+ CMAKE_SYSROOT=${CMAKE_SYSROOT}
446
295
CMAKE_CURRENT_BINARY_DIR =${CMAKE_CURRENT_BINARY_DIR}
447
296
FIRMWARE_VERSION_SHORT=${FIRMWARE_VERSION}
448
297
${CARGO} clippy
@@ -465,7 +314,7 @@ if(NOT CMAKE_CROSSCOMPILING)
465
314
-A clippy::forget_non_drop
466
315
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} /rust/
467
316
)
468
- add_dependencies (rust-clippy rust-bindgen generate-protobufs )
317
+ add_dependencies (rust-clippy generate-protobufs )
469
318
endif ()
470
319
471
320
# If a bootloader that locks the bootloader is flashed the bootloader area is permanently read-only.
@@ -510,6 +359,7 @@ foreach(type ${RUST_LIBS})
510
359
OUTPUT ${lib} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} /lib${type}_rust_c.a dummy
511
360
COMMAND
512
361
${CMAKE_COMMAND} -E env
362
+ CMAKE_SYSROOT=${CMAKE_SYSROOT}
513
363
CMAKE_CURRENT_BINARY_DIR =${CMAKE_CURRENT_BINARY_DIR}
514
364
RUSTFLAGS=${RUSTFLAGS}
515
365
FIRMWARE_VERSION_SHORT=${FIRMWARE_VERSION}
@@ -521,7 +371,6 @@ foreach(type ${RUST_LIBS})
521
371
# DEPFILES are only supported with the Ninja build tool
522
372
#DEPFILE ${RUST_BINARY_DIR}/feature-${type}/${RUST_TARGET_ARCH_DIR}/${RUST_PROFILE}/libbitbox02_rust_c.d
523
373
WORKING_DIRECTORY ${LIBBITBOX02_RUST_SOURCE_DIR}
524
- DEPENDS rust-bindgen
525
374
COMMENT "Building Rust library lib${type} _rust_c.a"
526
375
)
527
376
add_custom_target (${type} -rust-target DEPENDS ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} /lib${type}_rust_c.a )
@@ -536,17 +385,14 @@ endforeach()
536
385
if (CMAKE_CROSSCOMPILING )
537
386
add_custom_target (rust-docs
538
387
COMMAND
388
+ CMAKE_SYSROOT=${CMAKE_SYSROOT}
539
389
${CMAKE_COMMAND} -E env
540
390
FIRMWARE_VERSION_SHORT=${FIRMWARE_VERSION}
541
- CMAKE_CURRENT_BINARY_DIR =${CMAKE_CURRENT_BINARY_DIR}
542
- SYSROOT=${CMAKE_SYSROOT}
543
- INCLUDES= "${RUST_INCLUDES} "
544
391
${CARGO} doc --document-private-items --target-dir ${CMAKE_BINARY_DIR} /docs-rust --target thumbv7em-none-eabi
545
392
COMMAND
546
393
${CMAKE_COMMAND} -E echo "See docs at file://${CMAKE_BINARY_DIR} /docs-rust/thumbv7em-none-eabi/doc/bitbox02_rust/index.html"
547
394
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} /rust
548
395
)
549
- add_dependencies (rust-docs rust-bindgen )
550
396
551
397
set (STACK_SIZE "0x10000" CACHE STRING "Specify stack size for bootloader/firmware" )
552
398
set (STACK_SIZE ${STACK_SIZE} PARENT_SCOPE )
0 commit comments