1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-18 05:28:40 +00:00

build(core): move default values for bindgen macros (back) into build.rs

This commit is contained in:
matejcik 2024-05-17 12:12:35 +02:00 committed by matejcik
parent 751390ec08
commit cf58fdd313
2 changed files with 50 additions and 17 deletions

View File

@ -43,8 +43,6 @@ OPENOCD_INTERFACE ?= stlink
# OpenOCD transport default. Alternative: jtag # OpenOCD transport default. Alternative: jtag
OPENOCD_TRANSPORT ?= hla_swd OPENOCD_TRANSPORT ?= hla_swd
BINDGEN_MACROS_COMMON=-I../unix,-I../trezorhal/unix,-I../../build/unix,-I../../vendor/micropython/ports/unix,-I../../../crypto,-I../../../storage,-I../../vendor/micropython,-I../../vendor/micropython/lib/uzlib,-I../lib,-I../trezorhal,-I../trezorhal/unix,-I../models,-DTREZOR_EMULATOR,-DTREZOR_BOARD="boards/board-unix.h",
ifeq ($(TREZOR_MODEL), 1) ifeq ($(TREZOR_MODEL), 1)
MCU = STM32F2 MCU = STM32F2
LAYOUT_FILE = embed/models/model_T1B1.h LAYOUT_FILE = embed/models/model_T1B1.h
@ -53,13 +51,11 @@ else ifeq ($(TREZOR_MODEL),$(filter $(TREZOR_MODEL),T))
MCU = STM32F4 MCU = STM32F4
LAYOUT_FILE = embed/models/model_T2T1.h LAYOUT_FILE = embed/models/model_T2T1.h
OPENOCD_TARGET = target/stm32f4x.cfg OPENOCD_TARGET = target/stm32f4x.cfg
BINDGEN_MACROS_MODEL = -DSTM32F427,-DTREZOR_MODEL_T,-DFLASH_BIT_ACCESS=1,-DFLASH_BLOCK_WORDS=1,
MODEL_FEATURE = model_tt MODEL_FEATURE = model_tt
else ifeq ($(TREZOR_MODEL),$(filter $(TREZOR_MODEL),R)) else ifeq ($(TREZOR_MODEL),$(filter $(TREZOR_MODEL),R))
MCU = STM32F4 MCU = STM32F4
LAYOUT_FILE = embed/models/model_T2B1.h LAYOUT_FILE = embed/models/model_T2B1.h
OPENOCD_TARGET = target/stm32f4x.cfg OPENOCD_TARGET = target/stm32f4x.cfg
BINDGEN_MACROS_MODEL =-DSTM32F427,-DTREZOR_MODEL_R,-DFLASH_BIT_ACCESS=1,-DFLASH_BLOCK_WORDS=1,
MODEL_FEATURE = model_tr MODEL_FEATURE = model_tr
else ifeq ($(TREZOR_MODEL),$(filter $(TREZOR_MODEL),T3T1)) else ifeq ($(TREZOR_MODEL),$(filter $(TREZOR_MODEL),T3T1))
MCU = STM32U5 MCU = STM32U5
@ -144,7 +140,6 @@ emu: ## run emulator
test: ## run unit tests test: ## run unit tests
cd tests ; ./run_tests.sh $(TESTOPTS) cd tests ; ./run_tests.sh $(TESTOPTS)
test_rust: export BINDGEN_MACROS=$(BINDGEN_MACROS_COMMON)$(BINDGEN_MACROS_MODEL)
test_rust: ## run rs unit tests test_rust: ## run rs unit tests
cd embed/rust ; cargo test $(TESTOPTS) --target=$(RUST_TARGET) \ cd embed/rust ; cargo test $(TESTOPTS) --target=$(RUST_TARGET) \
--no-default-features --features $(MODEL_FEATURE),test \ --no-default-features --features $(MODEL_FEATURE),test \
@ -214,7 +209,6 @@ typecheck: pyright
pyright: pyright:
python ../tools/pyright_tool.py python ../tools/pyright_tool.py
clippy: export BINDGEN_MACROS:=$(BINDGEN_MACROS_COMMON)$(BINDGEN_MACROS_MODEL)
clippy: clippy:
cd embed/rust ; cargo clippy $(TESTOPTS) --all-features --target=$(RUST_TARGET) cd embed/rust ; cargo clippy $(TESTOPTS) --all-features --target=$(RUST_TARGET)

View File

@ -14,12 +14,54 @@ fn main() {
link_core_objects(); link_core_objects();
} }
// fn block_words() -> String { const DEFAULT_BINDGEN_MACROS_COMMON: &[&str] = &[
// match env::var("FLASH_BLOCK_WORDS") { "-I../unix",
// Ok(model) => model, "-I../trezorhal/unix",
// Err(_) => panic!("FLASH_BLOCK_WORDS not set") "-I../../build/unix",
// } "-I../../vendor/micropython/ports/unix",
// } "-I../../../crypto",
"-I../../../storage",
"-I../../vendor/micropython",
"-I../../vendor/micropython/lib/uzlib",
"-I../lib",
"-I../trezorhal",
"-I../trezorhal/unix",
"-I../models",
"-DTREZOR_EMULATOR",
"-DTREZOR_BOARD=\"boards/board-unix.h\"",
];
#[cfg(feature = "model_tt")]
const DEFAULT_BINDGEN_MACROS_T2T1: &[&str] = &[
"-DSTM32F427",
"-DTREZOR_MODEL_T",
"-DFLASH_BIT_ACCESS=1",
"-DFLASH_BLOCK_WORDS=1",
];
#[cfg(not(feature = "model_tt"))]
const DEFAULT_BINDGEN_MACROS_T2T1: &[&str] = &[];
#[cfg(feature = "model_tr")]
const DEFAULT_BINDGEN_MACROS_T2B1: &[&str] = &[
"-DSTM32F427",
"-DTREZOR_MODEL_R",
"-DFLASH_BIT_ACCESS=1",
"-DFLASH_BLOCK_WORDS=1",
];
#[cfg(not(feature = "model_tr"))]
const DEFAULT_BINDGEN_MACROS_T2B1: &[&str] = &[];
fn add_bindgen_macros<'a>(clang_args: &mut Vec<&'a str>, envvar: Option<&'a str>) {
let default_macros = DEFAULT_BINDGEN_MACROS_COMMON
.iter()
.chain(DEFAULT_BINDGEN_MACROS_T2T1)
.chain(DEFAULT_BINDGEN_MACROS_T2B1);
match envvar {
Some(envvar) => clang_args.extend(envvar.split(',')),
None => clang_args.extend(default_macros),
}
}
/// Generates Rust module that exports QSTR constants used in firmware. /// Generates Rust module that exports QSTR constants used in firmware.
#[cfg(feature = "micropython")] #[cfg(feature = "micropython")]
@ -70,12 +112,9 @@ fn prepare_bindings() -> bindgen::Builder {
let mut bindings = bindgen::Builder::default(); let mut bindings = bindgen::Builder::default();
let mut clang_args: Vec<&str> = Vec::new(); let mut clang_args: Vec<&str> = Vec::new();
let includes = env::var("BINDGEN_MACROS").unwrap();
let args = includes.split(',');
for arg in args { let bindgen_macros_env = env::var("BINDGEN_MACROS").ok();
clang_args.push(arg); add_bindgen_macros(&mut clang_args, bindgen_macros_env.as_deref());
}
#[cfg(feature = "xframebuffer")] #[cfg(feature = "xframebuffer")]
{ {