@@ -400,6 +400,59 @@ 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 cmd = Command :: new ( icon2glyph. as_os_str ( ) ) ;
440
+ cmd. arg ( "--glyphcheader" )
441
+ . arg ( dest_path. join ( "glyphs.h" ) . as_os_str ( ) )
442
+ . arg ( "--glyphcfile" )
443
+ . arg ( dest_path. join ( "glyphs.c" ) . as_os_str ( ) ) ;
444
+
445
+ for folder in glyph_folders. iter ( ) {
446
+ for file in std:: fs:: read_dir ( folder) . unwrap ( ) {
447
+ let path = file. unwrap ( ) . path ( ) ;
448
+ let path_str = path. to_str ( ) . unwrap ( ) . to_string ( ) ;
449
+ cmd. arg ( path_str) ;
450
+ }
451
+ }
452
+
453
+ let _ = cmd. output ( ) ;
454
+ }
455
+
403
456
pub fn build_c_sdk ( & self ) {
404
457
let mut command = cc:: Build :: new ( ) ;
405
458
if env:: var_os ( "CC" ) . is_none ( ) {
@@ -534,11 +587,15 @@ impl SDKBuilder {
534
587
)
535
588
}
536
589
Device :: Stax | Device :: Flex => {
537
- if Device :: Stax == self . device {
538
- bindings = bindings. clang_args ( [ "-I./src/c/glyphs_stax" ] ) ;
539
- } else {
540
- bindings = bindings. clang_args ( [ "-I./src/c/glyphs_flex" ] ) ;
541
- }
590
+ let out_path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
591
+ let mut include_path = "-I" . to_string ( ) ;
592
+ let glyphs = match self . device {
593
+ Device :: Stax => out_path. join ( "glyphs_stax" ) ,
594
+ Device :: Flex => out_path. join ( "glyphs_flex" ) ,
595
+ _ => panic ! ( "Invalid device" ) ,
596
+ } ;
597
+ include_path += glyphs. to_str ( ) . unwrap ( ) ;
598
+ bindings = bindings. clang_args ( [ include_path. as_str ( ) ] ) ;
542
599
543
600
bindings = bindings. clang_args ( [
544
601
format ! ( "-I{bsdk}/lib_nbgl/include/" ) . as_str ( ) ,
@@ -618,6 +675,7 @@ fn main() {
618
675
sdk_builder. device ( ) ;
619
676
sdk_builder. bolos_sdk ( ) . unwrap ( ) ;
620
677
sdk_builder. cxdefines ( ) ;
678
+ sdk_builder. generate_glyphs ( ) ;
621
679
sdk_builder. build_c_sdk ( ) ;
622
680
sdk_builder. generate_bindings ( ) ;
623
681
sdk_builder. generate_heap_size ( ) ;
@@ -721,6 +779,7 @@ fn finalize_stax_configuration(command: &mut cc::Build, bolos_sdk: &Path) {
721
779
command. define ( define. as_str ( ) , value. as_deref ( ) ) ;
722
780
}
723
781
782
+ let glyphs_path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) . join ( "glyphs_stax" ) ;
724
783
command
725
784
. target ( "thumbv8m.main-none-eabi" )
726
785
. file ( bolos_sdk. join ( "src/ledger_protocol.c" ) )
@@ -739,8 +798,8 @@ fn finalize_stax_configuration(command: &mut cc::Build, bolos_sdk: &Path) {
739
798
. include ( bolos_sdk. join ( "target/stax/include/" ) )
740
799
. flag ( "-fropi" )
741
800
. flag ( "-frwpi" )
742
- . include ( "./src/c/glyphs_stax/" )
743
- . file ( "./src/c/glyphs_stax/ glyphs.c") ;
801
+ . include ( & glyphs_path )
802
+ . file ( glyphs_path . join ( " glyphs.c") ) ;
744
803
configure_lib_nbgl ( command, bolos_sdk) ;
745
804
}
746
805
@@ -750,6 +809,7 @@ fn finalize_flex_configuration(command: &mut cc::Build, bolos_sdk: &Path) {
750
809
command. define ( define. as_str ( ) , value. as_deref ( ) ) ;
751
810
}
752
811
812
+ let glyphs_path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) . join ( "glyphs_flex" ) ;
753
813
command
754
814
. target ( "thumbv8m.main-none-eabi" )
755
815
. file ( bolos_sdk. join ( "src/ledger_protocol.c" ) )
@@ -768,8 +828,8 @@ fn finalize_flex_configuration(command: &mut cc::Build, bolos_sdk: &Path) {
768
828
. include ( bolos_sdk. join ( "target/flex/include/" ) )
769
829
. flag ( "-fropi" )
770
830
. flag ( "-frwpi" )
771
- . include ( "./src/c/glyphs_flex/" )
772
- . file ( "./src/c/glyphs_flex/ glyphs.c") ;
831
+ . include ( & glyphs_path )
832
+ . file ( glyphs_path . join ( " glyphs.c") ) ;
773
833
configure_lib_nbgl ( command, bolos_sdk) ;
774
834
}
775
835
0 commit comments