@@ -7,20 +7,6 @@ use std::{
77 path:: { self , Path , PathBuf } ,
88} ;
99
10- mandatory_and_unique ! ( "mcu-esp32" , "mcu-esp32c3" , "mcu-nrf52832" , "mcu-nrf52840" ) ;
11- mandatory_and_unique ! ( "imu-stubbed" , "imu-mpu6050" , "imu-bmi160" ) ;
12- mandatory_and_unique ! ( "log-rtt" , "log-usb-serial" , "log-uart" ) ;
13- mandatory_and_unique ! ( "net-wifi" , "net-ble" , "net-stubbed" ) ;
14- mandatory_and_unique ! ( "fusion-stubbed" , "fusion-dcm" ) ;
15-
16- #[ cfg( any( feature = "mcu-nrf52840" , feature = "mcu-nrf52832" ) ) ]
17- mandatory_and_unique ! (
18- "nrf-boot-none" ,
19- "nrf-boot-mbr" ,
20- "nrf-boot-s132" ,
21- "nrf-boot-s140"
22- ) ;
23-
2410/// Use memory.x.feature file as memory map
2511macro_rules! memory_x {
2612 ( $mcu: literal) => {
@@ -40,12 +26,26 @@ fn main() -> Result<()> {
4026 println ! ( "cargo:rerun-if-changed=linker_scripts/" ) ;
4127 println ! ( "cargo:rerun-if-changed=boards/" ) ;
4228 println ! ( "cargo:rerun-if-changed=.env" ) ;
43-
44- // Any relevant env vars for the build script are listed here.
4529 println ! ( "cargo:rerun-if-env-changed=BOARD" ) ;
30+
31+ load_env_and_aliases ( ) ;
32+ check_features_compatible ( ) ;
33+
34+ // Link into Espressif's radio driver blobs
35+ #[ cfg( all( feature = "esp-wifi" ) ) ]
36+ println ! ( "cargo:rustc-link-arg=-Trom_functions.x" ) ;
37+
38+ memory_x ! ( "mcu-nrf52832" ) ;
39+ memory_x ! ( "mcu-nrf52840" ) ;
40+
41+ let board_cfg = BoardConfig :: from_file ( & BoardConfig :: get_path ( ) ?) ?;
42+ board_cfg. apply_to_env ( ) ;
43+
44+ Ok ( ( ) )
45+ }
46+
47+ fn load_env_and_aliases ( ) {
4648 let _ = dotenvy:: dotenv ( ) ;
47- #[ cfg( all( feature = "mcu-nrf52832" , feature = "log-usb-serial" ) ) ]
48- compile_error ! ( "the nrf52832 doesn't support USB!" ) ;
4949
5050 // NOTE: Can't use the `cfg_aliases` in the build script itself, only applies to
5151 // rest of codebase.
@@ -60,18 +60,31 @@ fn main() -> Result<()> {
6060 xtensa: { any( feature = "mcu-esp32" ) } ,
6161 riscv: { any( feature = "mcu-esp32c3" ) } ,
6262 }
63+ }
6364
64- // Link into Espressif's radio driver blobs
65- #[ cfg( all( feature = "esp-wifi" ) ) ]
66- println ! ( "cargo:rustc-link-arg=-Trom_functions.x" ) ;
67-
68- memory_x ! ( "mcu-nrf52832" ) ;
69- memory_x ! ( "mcu-nrf52840" ) ;
65+ fn check_features_compatible ( ) {
66+ mandatory_and_unique ! ( "mcu-esp32" , "mcu-esp32c3" , "mcu-nrf52832" , "mcu-nrf52840" ) ;
67+ mandatory_and_unique ! ( "imu-stubbed" , "imu-mpu6050" , "imu-bmi160" ) ;
68+ mandatory_and_unique ! ( "log-rtt" , "log-usb-serial" , "log-uart" ) ;
69+ mandatory_and_unique ! ( "net-wifi" , "net-ble" , "net-stubbed" ) ;
70+ mandatory_and_unique ! ( "fusion-stubbed" , "fusion-dcm" ) ;
71+
72+ #[ cfg( any( feature = "mcu-nrf52840" , feature = "mcu-nrf52832" ) ) ]
73+ mandatory_and_unique ! (
74+ "nrf-boot-none" ,
75+ "nrf-boot-mbr" ,
76+ "nrf-boot-s132" ,
77+ "nrf-boot-s140"
78+ ) ;
7079
71- let board_cfg = BoardConfig :: from_file ( & BoardConfig :: get_path ( ) ?) ?;
72- board_cfg. apply_to_env ( ) ;
80+ #[ cfg( all(
81+ feature = "net-wifi" ,
82+ any( feature = "mcu-nrf52840" , feature = "mcu-nrf52832" )
83+ ) ) ]
84+ compile_error ! ( "nrf52 mcu family doesn't support wifi!" ) ;
7385
74- Ok ( ( ) )
86+ #[ cfg( all( feature = "mcu-nrf52832" , feature = "log-usb-serial" ) ) ]
87+ compile_error ! ( "the nrf52832 doesn't support USB!" ) ;
7588}
7689
7790#[ allow( dead_code) ]
0 commit comments