@@ -17,6 +17,7 @@ const STD_TO_CORE_REPLACEMENTS: &[(&str, &str)] = &[
1717#[ derive( Debug , Clone , Copy ) ]
1818struct BindingSpec {
1919 module : & ' static str ,
20+ feature : Option < & ' static str > ,
2021 header : & ' static str ,
2122 include_dirs : & ' static [ & ' static str ] ,
2223 clang_args : & ' static [ & ' static str ] ,
@@ -33,26 +34,27 @@ struct LibraryArtifact {
3334
3435const BINDING_SPECS : & [ BindingSpec ] = & [
3536 BindingSpec {
36- module : "mac_802_15_4" ,
37- header : "stm32-bindings-gen/inc/wpan-wba.h" ,
37+ module : "wba_wpan_mac" ,
38+ feature : Some ( "wba_wpan_mac" ) ,
39+ header : "stm32-bindings-gen/inc/wba_wpan_mac.h" ,
3840 include_dirs : & [
41+ "Middlewares/ST/STM32_WPAN" ,
3942 "Middlewares/ST/STM32_WPAN/mac_802_15_4/core/inc" ,
4043 "Middlewares/ST/STM32_WPAN/mac_802_15_4/mac_utilities/inc" ,
41- "Middlewares/ST/STM32_WPAN" ,
42- "Drivers/CMSIS/Core/Include" ,
44+ "Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc" ,
4345 "Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc/_40nm_reg_files" ,
46+ "Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc/ot_inc" ,
4447 "Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/config" ,
4548 "Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/config/ieee_15_4_basic" ,
46- "Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc" ,
47- "Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc/ot_inc" ,
49+ "Drivers/CMSIS/Core/Include" ,
4850 ] ,
4951 clang_args : & [ "-DSUPPORT_MAC=1" , "-DMAC=1" , "-DMAC_LAYER=1" ] ,
5052 allowlist : & [ ] ,
51- aliases : & [ "mac" , "wpan_wba" ] ,
53+ aliases : & [ "mac" , "mac_802_15_4" , " wpan_wba"] ,
5254 library_artifacts : & [
5355 LibraryArtifact {
5456 source : "Middlewares/ST/STM32_WPAN/mac_802_15_4/lib" ,
55- destination : "src/lib/mac " ,
57+ destination : "src/lib/wba_wpan_mac " ,
5658 } ,
5759 LibraryArtifact {
5860 source : "Middlewares/ST/STM32_WPAN/mac_802_15_4/lib/wba_mac_lib.a" ,
@@ -66,20 +68,21 @@ const BINDING_SPECS: &[BindingSpec] = &[
6668 } ,
6769 BindingSpec {
6870 module : "ble_stack" ,
71+ feature : Some ( "wba_wpan_ble" ) ,
6972 header : "stm32-bindings-gen/inc/ble-wba.h" ,
7073 include_dirs : & [
74+ "Middlewares/ST/STM32_WPAN" ,
7175 "Middlewares/ST/STM32_WPAN/ble/stack/include" ,
7276 "Middlewares/ST/STM32_WPAN/ble/stack/include/auto" ,
73- "Middlewares/ST/STM32_WPAN" ,
74- "Drivers/CMSIS/Core/Include" ,
77+ "Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc" ,
7578 "Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc/_40nm_reg_files" ,
79+ "Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc/ot_inc" ,
7680 "Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/config" ,
7781 "Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/config/ble_basic_plus" ,
78- "Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc" ,
79- "Middlewares/ST/STM32_WPAN/link_layer/ll_cmd_lib/inc/ot_inc" ,
8082 "Middlewares/ST/STM32_WPAN/ble/audio/Inc" ,
8183 "Middlewares/ST/STM32_WPAN/ble/codec/codec_manager/Inc" ,
8284 "Middlewares/ST/STM32_WPAN/ble/codec/lc3/Inc" ,
85+ "Drivers/CMSIS/Core/Include" ,
8386 ] ,
8487 clang_args : & [ "-DBLE=1" , "-DSUPPORT_BLE=1" , "-DEXT_ADDRESS_LENGTH=8" ] ,
8588 allowlist : & [ ] ,
@@ -162,13 +165,19 @@ impl Gen {
162165
163166 let mut modules = Vec :: new ( ) ;
164167 let mut aliases = Vec :: new ( ) ;
168+
165169 for spec in BINDING_SPECS {
166170 println ! ( " -> generating `{}` bindings" , spec. module) ;
167171 self . generate_bindings_for_spec ( spec) ;
168172 self . copy_artifacts_for_spec ( spec) ;
169- modules. push ( spec. module . to_owned ( ) ) ;
173+
174+ modules. push ( ( spec. module . to_owned ( ) , spec. feature . map ( str:: to_owned) ) ) ;
170175 for alias in spec. aliases {
171- aliases. push ( ( spec. module . to_owned ( ) , alias. to_string ( ) ) ) ;
176+ aliases. push ( (
177+ spec. module . to_owned ( ) ,
178+ alias. to_string ( ) ,
179+ spec. feature . map ( str:: to_owned) ,
180+ ) ) ;
172181 }
173182 }
174183
@@ -188,16 +197,26 @@ impl Gen {
188197 self . write_bytes ( "src/lib.rs" , include_bytes ! ( "../res/src/lib.rs" ) ) ;
189198 }
190199
191- fn write_bindings_mod ( & self , modules : & [ String ] , aliases : & [ ( String , String ) ] ) {
200+ fn write_bindings_mod (
201+ & self ,
202+ modules : & [ ( String , Option < String > ) ] ,
203+ aliases : & [ ( String , String , Option < String > ) ] ,
204+ ) {
192205 let mut body = String :: new ( ) ;
193- for module in modules {
206+ for ( module, feature) in modules {
207+ if let Some ( feature) = feature {
208+ body. push_str ( & format ! ( "#[cfg(feature = \" {feature}\" )]\n " ) ) ;
209+ }
194210 body. push_str ( "pub mod " ) ;
195211 body. push_str ( module) ;
196212 body. push_str ( ";\n " ) ;
197213 }
198214 if !aliases. is_empty ( ) {
199215 body. push ( '\n' ) ;
200- for ( module, alias) in aliases {
216+ for ( module, alias, feature) in aliases {
217+ if let Some ( feature) = feature {
218+ body. push_str ( & format ! ( "#[cfg(feature = \" {feature}\" )]\n " ) ) ;
219+ }
201220 body. push_str ( "pub use self::" ) ;
202221 body. push_str ( module) ;
203222 body. push_str ( " as " ) ;
@@ -273,9 +292,8 @@ impl Gen {
273292 self . copy_file ( & src, & dst)
274293 . unwrap_or_else ( |err| panic ! ( "Failed to copy file {}: {err}" , src. display( ) ) ) ;
275294 } else if src. is_dir ( ) {
276- self . copy_dir ( & src, & dst) . unwrap_or_else ( |err| {
277- panic ! ( "Failed to copy directory {}: {err}" , src. display( ) )
278- } ) ;
295+ self . copy_dir ( & src, & dst)
296+ . unwrap_or_else ( |err| panic ! ( "Failed to copy dir {}: {err}" , src. display( ) ) ) ;
279297 } else {
280298 panic ! (
281299 "Artifact source {} is neither file nor directory" ,
@@ -345,7 +363,7 @@ impl Gen {
345363 contents = contents. replace ( from, to) ;
346364 }
347365
348- let normalized = contents
366+ contents
349367 . lines ( )
350368 . map ( |line| {
351369 if let Some ( rest) = line. strip_prefix ( "pub const " ) {
@@ -357,9 +375,7 @@ impl Gen {
357375 line. to_owned ( )
358376 } )
359377 . collect :: < Vec < _ > > ( )
360- . join ( "\n " ) ;
361-
362- normalized
378+ . join ( "\n " )
363379 }
364380
365381 fn is_thumb_target ( triple : & str ) -> bool {
0 commit comments