Skip to content

Commit 6320ef2

Browse files
committed
Move glyphs_folders into Device
1 parent 4a47de6 commit 6320ef2

File tree

1 file changed

+66
-57
lines changed

1 file changed

+66
-57
lines changed

ledger_secure_sdk_sys/build.rs

Lines changed: 66 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ struct Device<'a> {
110110
pub target: &'a str,
111111
pub defines: Vec<(String, Option<String>)>,
112112
pub cflags: Vec<&'a str>,
113+
pub glyphs_folders: Vec<PathBuf>,
113114
}
114115

115116
impl std::fmt::Display for DeviceName {
@@ -316,6 +317,31 @@ fn clone_sdk(devicename: &DeviceName) -> PathBuf {
316317
c_sdk
317318
}
318319

320+
pub fn generate_glyphs(c_sdk: &PathBuf, glyphs_folders: &[PathBuf]) {
321+
let icon2glyph = c_sdk.join("lib_nbgl/tools/icon2glyph.py");
322+
323+
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
324+
let dest_path = out_path.join("glyphs");
325+
if !dest_path.exists() {
326+
fs::create_dir_all(&dest_path).ok();
327+
}
328+
329+
let mut cmd = Command::new(icon2glyph.as_os_str());
330+
cmd.arg("--glyphcheader")
331+
.arg(dest_path.join("glyphs.h").as_os_str())
332+
.arg("--glyphcfile")
333+
.arg(dest_path.join("glyphs.c").as_os_str());
334+
335+
for folder in glyphs_folders.iter() {
336+
for file in std::fs::read_dir(folder).unwrap() {
337+
let path = file.unwrap().path();
338+
let path_str = path.to_str().unwrap().to_string();
339+
cmd.arg(path_str);
340+
}
341+
}
342+
let _ = cmd.output();
343+
}
344+
319345
#[derive(Debug)]
320346
enum SDKBuildError {
321347
UnsupportedDevice,
@@ -361,7 +387,6 @@ struct SDKBuilder<'a> {
361387
api_level: u32,
362388
gcc_toolchain: PathBuf,
363389
device: Device<'a>,
364-
glyphs_folders: Vec<PathBuf>,
365390
cxdefines: Vec<String>,
366391
}
367392

@@ -371,7 +396,6 @@ impl SDKBuilder<'_> {
371396
api_level: 0,
372397
gcc_toolchain: PathBuf::new(),
373398
device: Device::default(),
374-
glyphs_folders: Vec::new(),
375399
cxdefines: Vec::new(),
376400
}
377401
}
@@ -412,6 +436,7 @@ impl SDKBuilder<'_> {
412436
target: "thumbv6m-none-eabi",
413437
defines: header2define("csdk_nanos.h"),
414438
cflags: Vec::from(CFLAGS_NANOS),
439+
glyphs_folders: Vec::new(),
415440
},
416441
"nanosplus" => Device {
417442
name: DeviceName::NanoSPlus,
@@ -431,6 +456,7 @@ impl SDKBuilder<'_> {
431456
v
432457
},
433458
cflags: Vec::from(CFLAGS_NANOSPLUS),
459+
glyphs_folders: Vec::new(),
434460
},
435461
"nanox" => Device {
436462
name: DeviceName::NanoX,
@@ -450,20 +476,23 @@ impl SDKBuilder<'_> {
450476
v
451477
},
452478
cflags: Vec::from(CFLAGS_NANOX),
479+
glyphs_folders: Vec::new(),
453480
},
454481
"stax" => Device {
455482
name: DeviceName::Stax,
456483
c_sdk: Default::default(),
457484
target: "thumbv8m.main-none-eabi",
458485
defines: header2define("csdk_stax.h"),
459486
cflags: Vec::from(CFLAGS_STAX),
487+
glyphs_folders: Vec::new(),
460488
},
461489
"flex" => Device {
462490
name: DeviceName::Flex,
463491
c_sdk: Default::default(),
464492
target: "thumbv8m.main-none-eabi",
465493
defines: header2define("csdk_flex.h"),
466494
cflags: Vec::from(CFLAGS_FLEX),
495+
glyphs_folders: Vec::new(),
467496
},
468497
_ => {
469498
return Err(SDKBuildError::UnsupportedDevice);
@@ -476,6 +505,37 @@ impl SDKBuilder<'_> {
476505
Ok(path) => PathBuf::from(path),
477506
};
478507

508+
// set glyphs folders
509+
match self.device.name {
510+
DeviceName::Flex => {
511+
self.device
512+
.glyphs_folders
513+
.push(self.device.c_sdk.join("lib_nbgl/glyphs/wallet"));
514+
self.device
515+
.glyphs_folders
516+
.push(self.device.c_sdk.join("lib_nbgl/glyphs/64px"));
517+
self.device
518+
.glyphs_folders
519+
.push(self.device.c_sdk.join("lib_nbgl/glyphs/40px"));
520+
}
521+
DeviceName::Stax => {
522+
self.device
523+
.glyphs_folders
524+
.push(self.device.c_sdk.join("lib_nbgl/glyphs/wallet"));
525+
self.device
526+
.glyphs_folders
527+
.push(self.device.c_sdk.join("lib_nbgl/glyphs/64px"));
528+
self.device
529+
.glyphs_folders
530+
.push(self.device.c_sdk.join("lib_nbgl/glyphs/32px"));
531+
}
532+
_ => {
533+
self.device
534+
.glyphs_folders
535+
.push(self.device.c_sdk.join("lib_nbgl/glyphs/nano"));
536+
}
537+
}
538+
479539
// export TARGET into env for 'infos.rs'
480540
println!("cargo:rustc-env=TARGET={}", self.device.name);
481541
println!("cargo:warning=Device is {:?}", self.device.name);
@@ -499,30 +559,6 @@ impl SDKBuilder<'_> {
499559
}
500560
}
501561

502-
// set glyphs folders
503-
match self.device.name {
504-
DeviceName::Flex => {
505-
self.glyphs_folders
506-
.push(self.device.c_sdk.join("lib_nbgl/glyphs/wallet"));
507-
self.glyphs_folders
508-
.push(self.device.c_sdk.join("lib_nbgl/glyphs/64px"));
509-
self.glyphs_folders
510-
.push(self.device.c_sdk.join("lib_nbgl/glyphs/40px"));
511-
}
512-
DeviceName::Stax => {
513-
self.glyphs_folders
514-
.push(self.device.c_sdk.join("lib_nbgl/glyphs/wallet"));
515-
self.glyphs_folders
516-
.push(self.device.c_sdk.join("lib_nbgl/glyphs/64px"));
517-
self.glyphs_folders
518-
.push(self.device.c_sdk.join("lib_nbgl/glyphs/32px"));
519-
}
520-
_ => {
521-
self.glyphs_folders
522-
.push(self.device.c_sdk.join("lib_nbgl/glyphs/nano"));
523-
}
524-
}
525-
526562
// Export other SDK infos into env for 'infos.rs'
527563
println!("cargo:rustc-env=TARGET_ID={}", sdk_info.target_id);
528564
println!("cargo:warning=TARGET_ID is {}", sdk_info.target_id);
@@ -556,38 +592,12 @@ impl SDKBuilder<'_> {
556592
Ok(())
557593
}
558594

559-
pub fn generate_glyphs(&self) -> Result<(), SDKBuildError> {
560-
if self.device.name == DeviceName::NanoS {
561-
return Err(SDKBuildError::UnsupportedDevice);
562-
}
563-
564-
let icon2glyph = self.device.c_sdk.join("lib_nbgl/tools/icon2glyph.py");
565-
566-
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
567-
let dest_path = out_path.join("glyphs");
568-
if !dest_path.exists() {
569-
fs::create_dir_all(&dest_path).ok();
570-
}
571-
572-
let mut cmd = Command::new(icon2glyph.as_os_str());
573-
cmd.arg("--glyphcheader")
574-
.arg(dest_path.join("glyphs.h").as_os_str())
575-
.arg("--glyphcfile")
576-
.arg(dest_path.join("glyphs.c").as_os_str());
577-
578-
for folder in self.glyphs_folders.iter() {
579-
for file in std::fs::read_dir(folder).unwrap() {
580-
let path = file.unwrap().path();
581-
let path_str = path.to_str().unwrap().to_string();
582-
cmd.arg(path_str);
583-
}
595+
pub fn build_c_sdk(&self) -> Result<(), SDKBuildError> {
596+
// Generate glyphs
597+
if self.device.name != DeviceName::NanoS {
598+
generate_glyphs(&self.device.c_sdk, &self.device.glyphs_folders);
584599
}
585600

586-
let _ = cmd.output();
587-
Ok(())
588-
}
589-
590-
pub fn build_c_sdk(&self) -> Result<(), SDKBuildError> {
591601
let mut command = cc::Build::new();
592602
if env::var_os("CC").is_none() {
593603
command.compiler("clang");
@@ -842,7 +852,6 @@ fn main() {
842852
sdk_builder.device().unwrap();
843853
sdk_builder.get_info().unwrap();
844854
sdk_builder.cxdefines().unwrap();
845-
sdk_builder.generate_glyphs().unwrap();
846855
sdk_builder.build_c_sdk().unwrap();
847856
sdk_builder.generate_bindings().unwrap();
848857
sdk_builder.generate_heap_size().unwrap();

0 commit comments

Comments
 (0)