@@ -400,6 +400,60 @@ impl SDKBuilder {
400
400
self . cxdefines = cxdefines;
401
401
}
402
402
403
+ pub fn generate_glyphs ( & self ) {
404
+ if self . device == Device :: NanoS {
405
+ return ;
406
+ }
407
+
408
+ let icon2glyph = self . bolos_sdk . join ( "lib_nbgl/tools/icon2glyph.py" ) ;
409
+
410
+ let out_path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
411
+ let dest_path = match self . device {
412
+ Device :: Flex => out_path. join ( "glyphs_flex" ) ,
413
+ Device :: Stax => out_path. join ( "glyphs_stax" ) ,
414
+ Device :: NanoSPlus => out_path. join ( "glyphs_nanosplus" ) ,
415
+ Device :: NanoX => out_path. join ( "glyphs_nanox" ) ,
416
+ Device :: NanoS => panic ! ( "Nano S does not support glyphs" ) ,
417
+ } ;
418
+ if !dest_path. exists ( ) {
419
+ fs:: create_dir_all ( & dest_path) . ok ( ) ;
420
+ }
421
+
422
+ let mut glyph_folders: Vec < PathBuf > = Vec :: new ( ) ;
423
+ match self . device {
424
+ Device :: Flex => {
425
+ glyph_folders. push ( self . bolos_sdk . join ( "lib_nbgl/glyphs/wallet" ) ) ;
426
+ glyph_folders. push ( self . bolos_sdk . join ( "lib_nbgl/glyphs/64px" ) ) ;
427
+ glyph_folders. push ( self . bolos_sdk . join ( "lib_nbgl/glyphs/40px" ) ) ;
428
+ }
429
+ Device :: Stax => {
430
+ glyph_folders. push ( self . bolos_sdk . join ( "lib_nbgl/glyphs/wallet" ) ) ;
431
+ glyph_folders. push ( self . bolos_sdk . join ( "lib_nbgl/glyphs/64px" ) ) ;
432
+ glyph_folders. push ( self . bolos_sdk . join ( "lib_nbgl/glyphs/32px" ) ) ;
433
+ }
434
+ _ => {
435
+ glyph_folders. push ( self . bolos_sdk . join ( "lib_nbgl/glyphs/nano" ) ) ;
436
+ }
437
+ }
438
+
439
+ let mut png_list: Vec < String > = Vec :: new ( ) ;
440
+ for folder in glyph_folders. iter ( ) {
441
+ for file in std:: fs:: read_dir ( folder) . unwrap ( ) {
442
+ let path = file. unwrap ( ) . path ( ) ;
443
+ let path_str = path. to_str ( ) . unwrap ( ) . to_string ( ) ;
444
+ png_list. push ( path_str) ;
445
+ }
446
+ }
447
+
448
+ let _ = Command :: new ( icon2glyph. as_os_str ( ) )
449
+ . arg ( "--glyphcheader" )
450
+ . arg ( dest_path. join ( "glyphs.h" ) . as_os_str ( ) )
451
+ . arg ( "--glyphcfile" )
452
+ . arg ( dest_path. join ( "glyphs.c" ) . as_os_str ( ) )
453
+ . args ( png_list)
454
+ . output ( ) ;
455
+ }
456
+
403
457
pub fn build_c_sdk ( & self ) {
404
458
let mut command = cc:: Build :: new ( ) ;
405
459
if env:: var_os ( "CC" ) . is_none ( ) {
@@ -534,10 +588,17 @@ impl SDKBuilder {
534
588
)
535
589
}
536
590
Device :: Stax | Device :: Flex => {
591
+ let out_path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
537
592
if Device :: Stax == self . device {
538
- bindings = bindings. clang_args ( [ "-I./src/c/glyphs_stax" ] ) ;
593
+ let glyphs = out_path. join ( "glyphs_stax" ) ;
594
+ let include_path = glyphs. to_str ( ) . unwrap ( ) ;
595
+ let s = "-I" . to_string ( ) + include_path;
596
+ bindings = bindings. clang_args ( [ s. as_str ( ) ] ) ;
539
597
} else {
540
- bindings = bindings. clang_args ( [ "-I./src/c/glyphs_flex" ] ) ;
598
+ let glyphs = out_path. join ( "glyphs_flex" ) ;
599
+ let include_path = glyphs. to_str ( ) . unwrap ( ) ;
600
+ let s = "-I" . to_string ( ) + include_path;
601
+ bindings = bindings. clang_args ( [ s. as_str ( ) ] ) ;
541
602
}
542
603
543
604
bindings = bindings. clang_args ( [
@@ -618,6 +679,7 @@ fn main() {
618
679
sdk_builder. device ( ) ;
619
680
sdk_builder. bolos_sdk ( ) . unwrap ( ) ;
620
681
sdk_builder. cxdefines ( ) ;
682
+ sdk_builder. generate_glyphs ( ) ;
621
683
sdk_builder. build_c_sdk ( ) ;
622
684
sdk_builder. generate_bindings ( ) ;
623
685
sdk_builder. generate_heap_size ( ) ;
@@ -721,6 +783,7 @@ fn finalize_stax_configuration(command: &mut cc::Build, bolos_sdk: &Path) {
721
783
command. define ( define. as_str ( ) , value. as_deref ( ) ) ;
722
784
}
723
785
786
+ let glyphs_path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) . join ( "glyphs_stax" ) ;
724
787
command
725
788
. target ( "thumbv8m.main-none-eabi" )
726
789
. file ( bolos_sdk. join ( "src/ledger_protocol.c" ) )
@@ -739,8 +802,8 @@ fn finalize_stax_configuration(command: &mut cc::Build, bolos_sdk: &Path) {
739
802
. include ( bolos_sdk. join ( "target/stax/include/" ) )
740
803
. flag ( "-fropi" )
741
804
. flag ( "-frwpi" )
742
- . include ( "./src/c/glyphs_stax/" )
743
- . file ( "./src/c/glyphs_stax/ glyphs.c") ;
805
+ . include ( & glyphs_path )
806
+ . file ( glyphs_path . join ( " glyphs.c") ) ;
744
807
configure_lib_nbgl ( command, bolos_sdk) ;
745
808
}
746
809
@@ -750,6 +813,7 @@ fn finalize_flex_configuration(command: &mut cc::Build, bolos_sdk: &Path) {
750
813
command. define ( define. as_str ( ) , value. as_deref ( ) ) ;
751
814
}
752
815
816
+ let glyphs_path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) . join ( "glyphs_flex" ) ;
753
817
command
754
818
. target ( "thumbv8m.main-none-eabi" )
755
819
. file ( bolos_sdk. join ( "src/ledger_protocol.c" ) )
@@ -768,8 +832,8 @@ fn finalize_flex_configuration(command: &mut cc::Build, bolos_sdk: &Path) {
768
832
. include ( bolos_sdk. join ( "target/flex/include/" ) )
769
833
. flag ( "-fropi" )
770
834
. flag ( "-frwpi" )
771
- . include ( "./src/c/glyphs_flex/" )
772
- . file ( "./src/c/glyphs_flex/ glyphs.c") ;
835
+ . include ( & glyphs_path )
836
+ . file ( glyphs_path . join ( " glyphs.c") ) ;
773
837
configure_lib_nbgl ( command, bolos_sdk) ;
774
838
}
775
839
0 commit comments