@@ -4,7 +4,7 @@ use std::fs;
4
4
use std:: path:: { Path , PathBuf } ;
5
5
use std:: process:: Command ;
6
6
use std:: time:: Instant ;
7
- use std:: { env, fs:: File , io:: BufRead , io:: BufReader , io:: Read } ;
7
+ use std:: { env, fs:: File , io:: BufRead , io:: BufReader , io:: Read , io :: Write } ;
8
8
9
9
const AUX_C_FILES : [ & str ; 2 ] = [ "./src/c/src.c" , "./src/c/sjlj.s" ] ;
10
10
@@ -315,10 +315,16 @@ impl SDKBuilder<'_> {
315
315
. glyphs_folders
316
316
. push ( self . device . c_sdk . join ( "lib_nbgl/glyphs/24px" ) ) ;
317
317
}
318
- _ => {
319
- self . device
320
- . glyphs_folders
321
- . push ( self . device . c_sdk . join ( "lib_nbgl/glyphs/nano" ) ) ;
318
+ DeviceName :: NanoSPlus | DeviceName :: NanoX => {
319
+ if env:: var_os ( "CARGO_FEATURE_NANO_NBGL" ) . is_some ( ) {
320
+ self . device
321
+ . glyphs_folders
322
+ . push ( self . device . c_sdk . join ( "lib_nbgl/glyphs/nano" ) ) ;
323
+ } else {
324
+ self . device
325
+ . glyphs_folders
326
+ . push ( self . device . c_sdk . join ( "lib_ux/glyphs" ) ) ;
327
+ }
322
328
}
323
329
}
324
330
@@ -523,18 +529,17 @@ impl SDKBuilder<'_> {
523
529
}
524
530
525
531
// BAGL or NBGL bindings
532
+ let out_path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
533
+ let mut include_path = "-I" . to_string ( ) ;
534
+ let glyphs = out_path. join ( "glyphs" ) ;
535
+ include_path += glyphs. to_str ( ) . unwrap ( ) ;
536
+ bindings = bindings. clang_args ( [ include_path. as_str ( ) ] ) ;
526
537
if ( ( self . device . name == DeviceName :: NanoX || self . device . name == DeviceName :: NanoSPlus )
527
538
&& env:: var_os ( "CARGO_FEATURE_NANO_NBGL" ) . is_some ( ) )
528
539
|| self . device . name == DeviceName :: Stax
529
540
|| self . device . name == DeviceName :: Flex
530
541
|| self . device . name == DeviceName :: ApexP
531
542
{
532
- let out_path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
533
- let mut include_path = "-I" . to_string ( ) ;
534
- let glyphs = out_path. join ( "glyphs" ) ;
535
- include_path += glyphs. to_str ( ) . unwrap ( ) ;
536
- bindings = bindings. clang_args ( [ include_path. as_str ( ) ] ) ;
537
-
538
543
bindings = bindings. clang_args ( [
539
544
format ! ( "-I{bsdk}/lib_nbgl/include/" ) . as_str ( ) ,
540
545
format ! ( "-I{bsdk}/lib_ux_nbgl/" ) . as_str ( ) ,
@@ -550,7 +555,11 @@ impl SDKBuilder<'_> {
550
555
bindings = bindings. clang_args ( [ "-DHAVE_NBGL" , "-DNBGL_STEP" , "-DNBGL_USE_CASE" ] ) ;
551
556
}
552
557
} else {
553
- bindings = bindings. clang_arg ( "-DHAVE_UX_FLOW" ) ;
558
+ bindings = bindings. clang_args ( [
559
+ format ! ( "-I{bsdk}/lib_bagl/include/" ) . as_str ( ) ,
560
+ format ! ( "-I{bsdk}/lib_ux/include/" ) . as_str ( ) ,
561
+ ] ) ;
562
+ bindings = bindings. clang_args ( [ "-DHAVE_BAGL" , "-DHAVE_UX_FLOW" ] ) ;
554
563
}
555
564
556
565
for define in & self . cxdefines {
@@ -878,32 +887,74 @@ fn clone_sdk(devicename: &DeviceName) -> PathBuf {
878
887
}
879
888
880
889
fn generate_glyphs ( device : & Device ) {
881
- let icon2glyph = device. c_sdk . join ( "lib_nbgl/tools/icon2glyph.py" ) ;
882
-
883
890
let out_path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
884
891
let dest_path = out_path. join ( "glyphs" ) ;
885
892
if !dest_path. exists ( ) {
886
893
fs:: create_dir_all ( & dest_path) . ok ( ) ;
887
894
}
888
895
889
- let mut cmd = Command :: new ( icon2glyph. as_os_str ( ) ) ;
890
- cmd. arg ( "--glyphcheader" )
891
- . arg ( dest_path. join ( "glyphs.h" ) . as_os_str ( ) )
892
- . arg ( "--glyphcfile" )
893
- . arg ( dest_path. join ( "glyphs.c" ) . as_os_str ( ) ) ;
896
+ // NBGL Glyphs
897
+ if ( ( device. name == DeviceName :: NanoSPlus || device. name == DeviceName :: NanoX )
898
+ && env:: var_os ( "CARGO_FEATURE_NANO_NBGL" ) . is_some ( ) )
899
+ || device. name == DeviceName :: Stax
900
+ || device. name == DeviceName :: Flex
901
+ || device. name == DeviceName :: ApexP
902
+ {
903
+ println ! ( "cargo:warning=NBGL glyphs are generated" ) ;
904
+ let icon2glyph = device. c_sdk . join ( "lib_nbgl/tools/icon2glyph.py" ) ;
894
905
895
- if device. name == DeviceName :: NanoSPlus || device. name == DeviceName :: NanoX {
896
- cmd. arg ( "--reverse" ) ;
897
- }
906
+ let mut cmd = Command :: new ( icon2glyph. as_os_str ( ) ) ;
907
+ cmd. arg ( "--glyphcheader" )
908
+ . arg ( dest_path. join ( "glyphs.h" ) . as_os_str ( ) )
909
+ . arg ( "--glyphcfile" )
910
+ . arg ( dest_path. join ( "glyphs.c" ) . as_os_str ( ) ) ;
911
+
912
+ if device. name == DeviceName :: NanoSPlus || device. name == DeviceName :: NanoX {
913
+ cmd. arg ( "--reverse" ) ;
914
+ }
898
915
899
- for folder in device. glyphs_folders . iter ( ) {
900
- for file in std:: fs:: read_dir ( folder) . unwrap ( ) {
901
- let path = file. unwrap ( ) . path ( ) ;
902
- let path_str = path. to_str ( ) . unwrap ( ) . to_string ( ) ;
903
- cmd. arg ( path_str) ;
916
+ for folder in device. glyphs_folders . iter ( ) {
917
+ for file in std:: fs:: read_dir ( folder) . unwrap ( ) {
918
+ let path = file. unwrap ( ) . path ( ) ;
919
+ let path_str = path. to_str ( ) . unwrap ( ) . to_string ( ) ;
920
+ cmd. arg ( path_str) ;
921
+ }
922
+ }
923
+ let _ = cmd. output ( ) ;
924
+ }
925
+ // BAGL Glyphs
926
+ else {
927
+ println ! ( "cargo:warning=BAGL glyphs are generated" ) ;
928
+ let icon2glyph = device. c_sdk . join ( "icon3.py" ) ;
929
+
930
+ let mut cmd1 = Command :: new ( "python3" ) ;
931
+ cmd1. arg ( icon2glyph. as_os_str ( ) ) ;
932
+ cmd1. arg ( "--glyphcheader" ) ;
933
+ let mut cmd2 = Command :: new ( "python3" ) ;
934
+ cmd2. arg ( icon2glyph. as_os_str ( ) ) ;
935
+ cmd2. arg ( "--glyphcfile" ) . arg ( "--factorize" ) ;
936
+
937
+ for folder in device. glyphs_folders . iter ( ) {
938
+ for file in std:: fs:: read_dir ( folder) . unwrap ( ) {
939
+ let path = file. unwrap ( ) . path ( ) ;
940
+ let path_str = path. to_str ( ) . unwrap ( ) . to_string ( ) ;
941
+ cmd1. arg ( & path_str) ;
942
+ cmd2. arg ( & path_str) ;
943
+ }
904
944
}
945
+ let output1 = cmd1. output ( ) . unwrap ( ) ;
946
+ let output2 = cmd2. output ( ) . unwrap ( ) ;
947
+
948
+ let mut glyphs_header: File = File :: create ( dest_path. join ( "glyphs.h" ) ) . unwrap ( ) ;
949
+ glyphs_header
950
+ . write_all ( & output1. stdout )
951
+ . expect ( "Failed to write glyphs.h" ) ;
952
+
953
+ let mut glyphs_cfile = File :: create ( dest_path. join ( "glyphs.c" ) ) . unwrap ( ) ;
954
+ glyphs_cfile
955
+ . write_all ( & output2. stdout )
956
+ . expect ( "Failed to write glyphs.c" ) ;
905
957
}
906
- let _ = cmd. output ( ) ;
907
958
}
908
959
909
960
/// Helper function to concatenate all paths in pathlist to c_sdk's path
0 commit comments