2021-06-12 10:19:31 +00:00
#[ cfg(feature = " test " ) ]
use std ::ffi ::OsStr ;
2021-03-23 12:14:33 +00:00
use std ::{ env , path ::PathBuf , process ::Command } ;
fn main ( ) {
2022-06-08 08:31:23 +00:00
#[ cfg(feature = " micropython " ) ]
2021-03-23 12:14:33 +00:00
generate_qstr_bindings ( ) ;
2022-06-08 08:31:23 +00:00
#[ cfg(feature = " micropython " ) ]
2021-03-23 12:14:33 +00:00
generate_micropython_bindings ( ) ;
2022-03-05 17:50:49 +00:00
generate_trezorhal_bindings ( ) ;
2024-01-22 12:44:02 +00:00
#[ cfg(feature = " crypto " ) ]
generate_crypto_bindings ( ) ;
2021-06-12 10:19:31 +00:00
#[ cfg(feature = " test " ) ]
link_core_objects ( ) ;
2021-03-23 12:14:33 +00:00
}
2023-06-27 22:10:46 +00:00
fn mcu_type ( ) -> String {
match env ::var ( " MCU_TYPE " ) {
Ok ( mcu ) = > mcu ,
Err ( _ ) = > String ::from ( " STM32F427xx " ) ,
}
}
2022-03-05 17:50:49 +00:00
fn model ( ) -> String {
match env ::var ( " TREZOR_MODEL " ) {
Ok ( model ) = > model ,
Err ( _ ) = > String ::from ( " T " ) ,
}
}
2023-12-27 22:29:22 +00:00
// fn block_words() -> String {
// match env::var("FLASH_BLOCK_WORDS") {
// Ok(model) => model,
// Err(_) => panic!("FLASH_BLOCK_WORDS not set")
// }
// }
2022-10-14 10:43:37 +00:00
fn board ( ) -> String {
if ! is_firmware ( ) {
2023-06-23 14:50:13 +00:00
return String ::from ( " boards/board-unix.h " ) ;
2022-10-14 10:43:37 +00:00
}
match env ::var ( " TREZOR_BOARD " ) {
Ok ( board ) = > {
format! ( " boards/ {} " , board )
}
Err ( _ ) = > String ::from ( " boards/trezor_t.h " ) ,
}
}
2021-03-23 12:14:33 +00:00
/// Generates Rust module that exports QSTR constants used in firmware.
2022-06-08 08:31:23 +00:00
#[ cfg(feature = " micropython " ) ]
2021-03-23 12:14:33 +00:00
fn generate_qstr_bindings ( ) {
let out_path = env ::var ( " OUT_DIR " ) . unwrap ( ) ;
// Tell cargo to invalidate the built crate whenever the header changes.
println! ( " cargo:rerun-if-changed=qstr.h " ) ;
2024-02-06 13:41:20 +00:00
let dest_file = PathBuf ::from ( out_path ) . join ( " qstr.rs " ) ;
2021-03-23 12:14:33 +00:00
bindgen ::Builder ::default ( )
. header ( " qstr.h " )
// Build the Qstr enum as a newtype so we can define method on it.
. default_enum_style ( bindgen ::EnumVariation ::NewType { is_bitfield : false } )
// Pass in correct include paths.
. clang_args ( & [
" -I " ,
2021-05-19 10:07:58 +00:00
if is_firmware ( ) {
2021-03-23 12:14:33 +00:00
" ../../build/firmware "
} else {
" ../../build/unix "
} ,
] )
// Customize the standard types.
. use_core ( )
. ctypes_prefix ( " cty " )
. size_t_is_usize ( true )
// Tell cargo to invalidate the built crate whenever any of the
// included header files change.
. parse_callbacks ( Box ::new ( bindgen ::CargoCallbacks ) )
. generate ( )
. expect ( " Unable to generate Rust QSTR bindings " )
2024-02-06 13:41:20 +00:00
. write_to_file ( & dest_file )
2021-03-23 12:14:33 +00:00
. unwrap ( ) ;
2024-02-06 13:41:20 +00:00
// rewrite the file to change internal representation of the qstr newtype
let qstr_generated = std ::fs ::read_to_string ( & dest_file ) . unwrap ( ) ;
let qstr_modified = qstr_generated . replace (
" pub struct Qstr(pub cty::c_uint); " ,
" pub struct Qstr(pub usize); " ,
) ;
assert_ne! ( qstr_generated , qstr_modified , " Failed to rewrite type of Qstr in qstr.rs file. \n This indicates that the generated file has changed. Please update the rewriting code. " ) ;
std ::fs ::write ( & dest_file , qstr_modified ) . unwrap ( ) ;
2021-03-23 12:14:33 +00:00
}
2022-03-05 17:50:49 +00:00
fn prepare_bindings ( ) -> bindgen ::Builder {
let mut bindings = bindgen ::Builder ::default ( ) ;
// Common include paths and defines
bindings = bindings . clang_args ( [
" -I../../../crypto " ,
" -I../../../storage " ,
" -I../../vendor/micropython " ,
2022-06-14 11:29:29 +00:00
" -I../../vendor/micropython/lib/uzlib " ,
2023-03-27 13:03:54 +00:00
" -I../lib " ,
2023-06-23 14:50:13 +00:00
" -I../trezorhal " ,
2023-09-29 10:42:39 +00:00
" -I../models " ,
2023-06-27 22:10:46 +00:00
format! ( " -D {} " , mcu_type ( ) ) . as_str ( ) ,
2022-03-05 17:50:49 +00:00
format! ( " -DTREZOR_MODEL_ {} " , model ( ) ) . as_str ( ) ,
2022-10-14 10:43:37 +00:00
format! ( " -DTREZOR_BOARD= \" {} \" " , board ( ) ) . as_str ( ) ,
2022-03-05 17:50:49 +00:00
] ) ;
// Pass in correct include paths and defines.
if is_firmware ( ) {
2023-06-27 22:10:46 +00:00
let mut clang_args : Vec < & str > = Vec ::new ( ) ;
let includes = env ::var ( " RUST_INCLUDES " ) . unwrap ( ) ;
2023-08-01 14:54:01 +00:00
let args = includes . split ( ';' ) ;
2023-06-27 22:10:46 +00:00
for arg in args {
clang_args . push ( arg ) ;
}
clang_args . push ( " -nostdinc " ) ;
clang_args . push ( " -I../firmware " ) ;
clang_args . push ( " -I../../build/firmware " ) ;
clang_args . push ( " -DUSE_HAL_DRIVER " ) ;
bindings = bindings . clang_args ( & clang_args ) ;
2022-03-05 17:50:49 +00:00
// Append gcc-arm-none-eabi's include paths.
let cc_output = Command ::new ( " arm-none-eabi-gcc " )
. arg ( " -E " )
. arg ( " -Wp,-v " )
. arg ( " - " )
. output ( )
. expect ( " arm-none-eabi-gcc failed to execute " ) ;
if ! cc_output . status . success ( ) {
panic! ( " arm-none-eabi-gcc failed " ) ;
}
let include_paths =
String ::from_utf8 ( cc_output . stderr ) . expect ( " arm-none-eabi-gcc returned invalid output " ) ;
let include_args = include_paths
. lines ( )
. skip_while ( | s | ! s . contains ( " search starts here: " ) )
. take_while ( | s | ! s . contains ( " End of search list. " ) )
. filter ( | s | s . starts_with ( ' ' ) )
. map ( | s | format! ( " -I {} " , s . trim ( ) ) ) ;
bindings = bindings . clang_args ( include_args ) ;
} else {
bindings = bindings . clang_args ( & [
" -I../unix " ,
2023-06-23 14:50:13 +00:00
" -I../trezorhal/unix " ,
2022-03-05 17:50:49 +00:00
" -I../../build/unix " ,
" -I../../vendor/micropython/ports/unix " ,
2022-08-16 14:51:10 +00:00
" -DTREZOR_EMULATOR " ,
2023-12-27 22:29:22 +00:00
" -DFLASH_BIT_ACCESS=1 " ,
" -DFLASH_BLOCK_WORDS=1 " ,
2022-03-05 17:50:49 +00:00
] ) ;
}
bindings
// Customize the standard types.
. use_core ( )
. ctypes_prefix ( " cty " )
. size_t_is_usize ( true )
// Disable the layout tests. They spew out a lot of code-style bindings, and are not too
// relevant for our use-case.
. layout_tests ( false )
// Tell cargo to invalidate the built crate whenever any of the
// included header files change.
. parse_callbacks ( Box ::new ( bindgen ::CargoCallbacks ) )
}
2022-06-08 08:31:23 +00:00
#[ cfg(feature = " micropython " ) ]
2021-03-23 12:14:33 +00:00
fn generate_micropython_bindings ( ) {
let out_path = env ::var ( " OUT_DIR " ) . unwrap ( ) ;
// Tell cargo to invalidate the built crate whenever the header changes.
println! ( " cargo:rerun-if-changed=micropython.h " ) ;
2022-03-05 17:50:49 +00:00
let bindings = prepare_bindings ( )
2021-03-23 12:14:33 +00:00
. header ( " micropython.h " )
// obj
. new_type_alias ( " mp_obj_t " )
. allowlist_type ( " mp_obj_type_t " )
. allowlist_type ( " mp_obj_base_t " )
. allowlist_function ( " mp_obj_new_int " )
. allowlist_function ( " mp_obj_new_int_from_ll " )
. allowlist_function ( " mp_obj_new_int_from_ull " )
. allowlist_function ( " mp_obj_new_int_from_uint " )
. allowlist_function ( " mp_obj_new_bytes " )
. allowlist_function ( " mp_obj_new_str " )
2022-02-19 12:49:04 +00:00
. allowlist_function ( " mp_obj_new_tuple " )
2024-02-06 09:57:12 +00:00
. allowlist_function ( " mp_obj_new_attrtuple " )
2021-03-23 12:14:33 +00:00
. allowlist_function ( " mp_obj_get_int_maybe " )
. allowlist_function ( " mp_obj_is_true " )
. allowlist_function ( " mp_call_function_n_kw " )
. allowlist_function ( " trezor_obj_get_ll_checked " )
2021-09-09 14:53:05 +00:00
. allowlist_function ( " trezor_obj_str_from_rom_text " )
2021-03-23 12:14:33 +00:00
// buffer
. allowlist_function ( " mp_get_buffer " )
. allowlist_var ( " MP_BUFFER_READ " )
. allowlist_var ( " MP_BUFFER_WRITE " )
2022-03-15 11:32:28 +00:00
. allowlist_var ( " mp_type_str " )
2022-10-19 16:06:13 +00:00
. allowlist_var ( " mp_type_bytes " )
. allowlist_var ( " mp_type_bytearray " )
. allowlist_var ( " mp_type_memoryview " )
2021-03-23 12:14:33 +00:00
// dict
. allowlist_type ( " mp_obj_dict_t " )
. allowlist_function ( " mp_obj_new_dict " )
. allowlist_var ( " mp_type_dict " )
// fun
. allowlist_type ( " mp_obj_fun_builtin_fixed_t " )
2023-02-21 11:30:24 +00:00
. allowlist_var ( " mp_type_fun_builtin_0 " )
2021-03-23 12:14:33 +00:00
. allowlist_var ( " mp_type_fun_builtin_1 " )
. allowlist_var ( " mp_type_fun_builtin_2 " )
. allowlist_var ( " mp_type_fun_builtin_3 " )
2021-11-03 17:38:17 +00:00
. allowlist_type ( " mp_obj_fun_builtin_var_t " )
. allowlist_var ( " mp_type_fun_builtin_var " )
2021-03-23 12:14:33 +00:00
// gc
. allowlist_function ( " gc_alloc " )
// iter
. allowlist_type ( " mp_obj_iter_buf_t " )
. allowlist_function ( " mp_getiter " )
. allowlist_function ( " mp_iternext " )
// list
. allowlist_type ( " mp_obj_list_t " )
. allowlist_function ( " mp_obj_new_list " )
. allowlist_function ( " mp_obj_list_append " )
2022-11-21 15:08:09 +00:00
. allowlist_function ( " mp_obj_list_get " )
2022-04-20 14:52:10 +00:00
. allowlist_function ( " mp_obj_list_set_len " )
2021-03-23 12:14:33 +00:00
. allowlist_var ( " mp_type_list " )
// map
. allowlist_type ( " mp_map_elem_t " )
. allowlist_function ( " mp_map_init " )
. allowlist_function ( " mp_map_init_fixed_table " )
. allowlist_function ( " mp_map_lookup " )
2021-09-09 14:53:05 +00:00
// exceptions
. allowlist_function ( " nlr_jump " )
. allowlist_function ( " mp_obj_new_exception " )
. allowlist_function ( " mp_obj_new_exception_args " )
2021-06-22 17:47:03 +00:00
. allowlist_function ( " trezor_obj_call_protected " )
2021-09-09 14:53:05 +00:00
. allowlist_var ( " mp_type_AttributeError " )
2024-01-15 09:44:25 +00:00
. allowlist_var ( " mp_type_EOFError " )
2022-11-22 11:25:42 +00:00
. allowlist_var ( " mp_type_IndexError " )
2021-09-09 14:53:05 +00:00
. allowlist_var ( " mp_type_KeyError " )
. allowlist_var ( " mp_type_MemoryError " )
. allowlist_var ( " mp_type_OverflowError " )
. allowlist_var ( " mp_type_ValueError " )
. allowlist_var ( " mp_type_TypeError " )
2021-10-24 09:29:44 +00:00
// time
. allowlist_function ( " mp_hal_ticks_ms " )
2021-11-26 18:40:35 +00:00
. allowlist_function ( " mp_hal_delay_ms " )
2022-07-20 09:18:37 +00:00
// debug
. allowlist_function ( " mp_print_strn " )
. allowlist_var ( " mp_plat_print " )
2021-03-23 12:14:33 +00:00
// typ
2022-01-26 18:04:02 +00:00
. allowlist_var ( " mp_type_type " )
// module
. allowlist_type ( " mp_obj_module_t " )
2022-03-05 17:50:49 +00:00
. allowlist_var ( " mp_type_module " )
2023-06-20 09:51:40 +00:00
// qstr
. allowlist_function ( " qstr_data " )
2024-01-17 14:40:19 +00:00
// tuple
. allowlist_type ( " mp_obj_tuple_t " )
2022-03-05 17:50:49 +00:00
// `ffi::mp_map_t` type is not allowed to be `Clone` or `Copy` because we tie it
// to the data lifetimes with the `MapRef` type, see `src/micropython/map.rs`.
// TODO: We should disable `Clone` and `Copy` for all types and only allow-list
// the specific cases we require.
. no_copy ( " _mp_map_t " ) ;
2021-03-23 12:14:33 +00:00
2022-03-05 17:50:49 +00:00
// Write the bindings to a file in the OUR_DIR.
bindings
. generate ( )
. expect ( " Unable to generate bindings " )
. write_to_file ( PathBuf ::from ( out_path ) . join ( " micropython.rs " ) )
. unwrap ( ) ;
}
2021-03-23 12:14:33 +00:00
2022-03-05 17:50:49 +00:00
fn generate_trezorhal_bindings ( ) {
let out_path = env ::var ( " OUT_DIR " ) . unwrap ( ) ;
2021-03-23 12:14:33 +00:00
2022-03-05 17:50:49 +00:00
// Tell cargo to invalidate the built crate whenever the header changes.
println! ( " cargo:rerun-if-changed=trezorhal.h " ) ;
2021-03-23 12:14:33 +00:00
2022-03-05 17:50:49 +00:00
let bindings = prepare_bindings ( )
. header ( " trezorhal.h " )
2023-09-29 10:42:39 +00:00
// model
. allowlist_var ( " MODEL_INTERNAL_NAME " )
. allowlist_var ( " MODEL_FULL_NAME " )
2022-04-01 09:05:19 +00:00
// common
. allowlist_var ( " HW_ENTROPY_DATA " )
2022-03-05 17:50:49 +00:00
// secbool
. allowlist_type ( " secbool " )
. must_use_type ( " secbool " )
. allowlist_var ( " sectrue " )
. allowlist_var ( " secfalse " )
2022-04-01 09:05:19 +00:00
// flash
. allowlist_function ( " flash_init " )
2022-03-05 17:50:49 +00:00
// storage
. allowlist_var ( " EXTERNAL_SALT_SIZE " )
. allowlist_function ( " storage_init " )
. allowlist_function ( " storage_wipe " )
. allowlist_function ( " storage_is_unlocked " )
. allowlist_function ( " storage_lock " )
. allowlist_function ( " storage_unlock " )
. allowlist_function ( " storage_has_pin " )
. allowlist_function ( " storage_get_pin_rem " )
. allowlist_function ( " storage_change_pin " )
2022-04-01 09:05:19 +00:00
. allowlist_function ( " storage_ensure_not_wipe_code " )
2022-03-05 17:50:49 +00:00
. allowlist_function ( " storage_has " )
. allowlist_function ( " storage_get " )
. allowlist_function ( " storage_set " )
. allowlist_function ( " storage_delete " )
. allowlist_function ( " storage_set_counter " )
. allowlist_function ( " storage_next_counter " )
2023-08-11 15:57:32 +00:00
. allowlist_function ( " translations_read " )
. allowlist_function ( " translations_write " )
. allowlist_function ( " translations_erase " )
. allowlist_function ( " translations_area_bytesize " )
2022-03-05 17:50:49 +00:00
// display
2023-09-27 19:42:50 +00:00
. allowlist_function ( " display_clear " )
2022-06-16 12:17:07 +00:00
. allowlist_function ( " display_offset " )
2022-03-05 17:50:49 +00:00
. allowlist_function ( " display_refresh " )
. allowlist_function ( " display_backlight " )
. allowlist_function ( " display_text " )
2022-08-16 14:51:10 +00:00
. allowlist_function ( " display_text_render_buffer " )
2022-03-05 17:50:49 +00:00
. allowlist_function ( " display_pixeldata " )
. allowlist_function ( " display_pixeldata_dirty " )
. allowlist_function ( " display_set_window " )
2022-12-13 11:40:02 +00:00
. allowlist_function ( " display_sync " )
2023-09-20 12:15:50 +00:00
. allowlist_function ( " display_get_fb_addr " )
. allowlist_function ( " display_get_wr_addr " )
2022-03-05 17:50:49 +00:00
. allowlist_var ( " DISPLAY_DATA_ADDRESS " )
2023-09-20 12:15:50 +00:00
. allowlist_var ( " DISPLAY_FRAMEBUFFER_WIDTH " )
. allowlist_var ( " DISPLAY_FRAMEBUFFER_HEIGHT " )
. allowlist_var ( " DISPLAY_FRAMEBUFFER_OFFSET_X " )
. allowlist_var ( " DISPLAY_FRAMEBUFFER_OFFSET_Y " )
2023-04-06 21:19:39 +00:00
. allowlist_var ( " DISPLAY_RESX " )
. allowlist_var ( " DISPLAY_RESY " )
2022-08-18 13:12:02 +00:00
// fonts
. allowlist_function ( " font_height " )
2022-08-16 14:51:10 +00:00
. allowlist_function ( " font_max_height " )
. allowlist_function ( " font_baseline " )
2022-08-18 13:12:02 +00:00
. allowlist_function ( " font_get_glyph " )
2024-01-17 14:29:49 +00:00
. allowlist_function ( " font_text_width " )
2022-06-14 11:29:29 +00:00
// uzlib
. allowlist_function ( " uzlib_uncompress_init " )
. allowlist_function ( " uzlib_uncompress " )
2022-03-05 17:50:49 +00:00
// bip39
. allowlist_function ( " mnemonic_word_completion_mask " )
. allowlist_var ( " BIP39_WORDLIST_ENGLISH " )
. allowlist_var ( " BIP39_WORD_COUNT " )
// slip39
. allowlist_function ( " slip39_word_completion_mask " )
. allowlist_function ( " button_sequence_to_word " )
2023-05-04 12:14:58 +00:00
. allowlist_var ( " SLIP39_WORDLIST " )
. allowlist_var ( " SLIP39_WORD_COUNT " )
2022-03-05 17:50:49 +00:00
// random
2022-06-08 08:31:23 +00:00
. allowlist_function ( " random_uniform " )
2022-05-31 07:31:32 +00:00
// rgb led
. allowlist_function ( " rgb_led_set_color " )
2022-06-08 08:31:23 +00:00
// time
. allowlist_function ( " hal_delay " )
2022-08-16 14:51:10 +00:00
. allowlist_function ( " hal_ticks_ms " )
2024-01-17 14:29:49 +00:00
// toif
. allowlist_type ( " toif_format_t " )
2022-08-16 14:51:10 +00:00
// dma2d
2023-09-20 12:15:50 +00:00
. allowlist_function ( " dma2d_setup_const " )
2023-01-02 15:30:16 +00:00
. allowlist_function ( " dma2d_setup_4bpp " )
2023-04-20 13:07:26 +00:00
. allowlist_function ( " dma2d_setup_16bpp " )
2022-08-16 14:51:10 +00:00
. allowlist_function ( " dma2d_setup_4bpp_over_4bpp " )
. allowlist_function ( " dma2d_setup_4bpp_over_16bpp " )
2023-01-02 15:30:16 +00:00
. allowlist_function ( " dma2d_start " )
2022-08-16 14:51:10 +00:00
. allowlist_function ( " dma2d_start_blend " )
2023-09-20 12:15:50 +00:00
. allowlist_function ( " dma2d_start_const " )
. allowlist_function ( " dma2d_start_const_multiline " )
2022-08-16 14:51:10 +00:00
. allowlist_function ( " dma2d_wait_for_transfer " )
//buffers
2023-01-24 13:16:23 +00:00
. allowlist_function ( " buffers_get_line_16bpp " )
. allowlist_function ( " buffers_free_line_16bpp " )
. allowlist_function ( " buffers_get_line_4bpp " )
. allowlist_function ( " buffers_free_line_4bpp " )
. allowlist_function ( " buffers_get_text " )
. allowlist_function ( " buffers_free_text " )
. allowlist_function ( " buffers_get_jpeg " )
. allowlist_function ( " buffers_free_jpeg " )
. allowlist_function ( " buffers_get_jpeg_work " )
. allowlist_function ( " buffers_free_jpeg_work " )
. allowlist_function ( " buffers_get_blurring " )
. allowlist_function ( " buffers_free_blurring " )
2023-12-11 14:22:51 +00:00
. allowlist_function ( " buffers_get_blurring_totals " )
. allowlist_function ( " buffers_free_blurring_totals " )
2023-09-20 12:15:50 +00:00
. allowlist_var ( " TEXT_BUFFER_HEIGHT " )
2023-01-24 13:16:23 +00:00
. no_copy ( " buffer_line_16bpp_t " )
. no_copy ( " buffer_line_4bpp_t " )
. no_copy ( " buffer_text_t " )
. no_copy ( " buffer_jpeg_t " )
. no_copy ( " buffer_jpeg_work_t " )
. no_copy ( " buffer_blurring_t " )
2023-12-11 14:22:51 +00:00
. no_copy ( " buffer_blurring_totals_t " )
2022-10-13 11:44:31 +00:00
//usb
2022-05-19 08:26:00 +00:00
. allowlist_function ( " usb_configured " )
// touch
. allowlist_function ( " touch_read " )
// button
2023-05-04 12:59:23 +00:00
. allowlist_function ( " button_read " ) ;
2022-05-19 08:26:00 +00:00
2022-03-05 17:50:49 +00:00
// Write the bindings to a file in the OUR_DIR.
2021-03-23 12:14:33 +00:00
bindings
. generate ( )
2022-03-05 17:50:49 +00:00
. expect ( " Unable to generate bindings " )
. write_to_file ( PathBuf ::from ( out_path ) . join ( " trezorhal.rs " ) )
2021-03-23 12:14:33 +00:00
. unwrap ( ) ;
}
2021-05-19 10:07:58 +00:00
2024-01-22 12:44:02 +00:00
fn generate_crypto_bindings ( ) {
let out_path = env ::var ( " OUT_DIR " ) . unwrap ( ) ;
// Tell cargo to invalidate the built crate whenever the header changes.
println! ( " cargo:rerun-if-changed=crypto.h " ) ;
let bindings = prepare_bindings ( )
. header ( " crypto.h " )
// ed25519
. allowlist_type ( " ed25519_signature " )
. allowlist_type ( " ed25519_public_key " )
. allowlist_function ( " ed25519_cosi_combine_publickeys " )
// incorrect signature from bindgen, see crypto::ed25519:ffi_override
//.allowlist_function("ed25519_sign_open")
// sha256
. allowlist_var ( " SHA256_DIGEST_LENGTH " )
. allowlist_type ( " SHA256_CTX " )
. no_copy ( " SHA256_CTX " )
. allowlist_function ( " sha256_Init " )
. allowlist_function ( " sha256_Update " )
. allowlist_function ( " sha256_Final " ) ;
// Write the bindings to a file in the OUR_DIR.
bindings
. clang_arg ( " -fgnuc-version=0 " ) // avoid weirdness with ed25519.h CONST definition
. generate ( )
. expect ( " Unable to generate bindings " )
. write_to_file ( PathBuf ::from ( out_path ) . join ( " crypto.rs " ) )
. unwrap ( ) ;
}
2021-05-19 10:07:58 +00:00
fn is_firmware ( ) -> bool {
let target = env ::var ( " TARGET " ) . unwrap ( ) ;
2023-06-28 08:51:30 +00:00
target . starts_with ( " thumbv7 " ) | | target . starts_with ( " thumbv8 " )
2021-05-19 10:07:58 +00:00
}
2021-06-12 10:19:31 +00:00
#[ cfg(feature = " test " ) ]
fn link_core_objects ( ) {
let crate_path = env ::var ( " CARGO_MANIFEST_DIR " ) . unwrap ( ) ;
let build_path = format! ( " {} /../../build/unix " , crate_path ) ;
2022-01-26 16:49:48 +00:00
// List of object filenames to ignore in the `embed` directory
2021-06-12 10:19:31 +00:00
let embed_blocklist = [ OsStr ::new ( " main_main.o " ) ] ;
2021-06-15 07:54:20 +00:00
// Collect all objects that the `core` library uses, and link it in. We have to
// make sure to avoid the object with the `_main` symbol, so we don't get any
// duplicates.
2021-06-12 10:19:31 +00:00
let mut cc = cc ::Build ::new ( ) ;
for obj in glob ::glob ( & format! ( " {} /embed/**/*.o " , build_path ) ) . unwrap ( ) {
let obj = obj . unwrap ( ) ;
if embed_blocklist . contains ( & obj . file_name ( ) . unwrap ( ) ) {
// Ignore.
} else {
cc . object ( obj ) ;
}
}
2021-10-22 18:05:21 +00:00
2021-06-12 10:19:31 +00:00
for obj in glob ::glob ( & format! ( " {} /vendor/**/*.o " , build_path ) ) . unwrap ( ) {
2021-10-22 18:05:21 +00:00
let obj = obj . unwrap ( ) ;
2022-01-26 16:49:48 +00:00
cc . object ( obj ) ;
2021-06-12 10:19:31 +00:00
}
2022-04-27 09:57:45 +00:00
// Add frozen modules, if present.
for obj in glob ::glob ( & format! ( " {} /*.o " , build_path ) ) . unwrap ( ) {
cc . object ( obj . unwrap ( ) ) ;
}
2021-06-15 07:54:20 +00:00
// Compile all the objects into a static library and link it in automatically.
2021-06-12 10:19:31 +00:00
cc . compile ( " core_lib " ) ;
println! ( " cargo:rustc-link-lib=SDL2 " ) ;
println! ( " cargo:rustc-link-lib=SDL2_image " ) ;
}