Skip to content

Commit f7f58c3

Browse files
committed
Generate glyphs automatically when building sys crate
1 parent 296440f commit f7f58c3

File tree

7 files changed

+72
-1895
lines changed

7 files changed

+72
-1895
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ledger_secure_sdk_sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ledger_secure_sdk_sys"
3-
version = "1.6.2"
3+
version = "1.6.3"
44
authors = ["yhql", "agrojean-ledger", "yogh333"]
55
edition = "2021"
66
license.workspace = true

ledger_secure_sdk_sys/build.rs

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,60 @@ impl SDKBuilder {
400400
self.cxdefines = cxdefines;
401401
}
402402

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+
403457
pub fn build_c_sdk(&self) {
404458
let mut command = cc::Build::new();
405459
if env::var_os("CC").is_none() {
@@ -534,10 +588,17 @@ impl SDKBuilder {
534588
)
535589
}
536590
Device::Stax | Device::Flex => {
591+
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
537592
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()]);
539597
} 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()]);
541602
}
542603

543604
bindings = bindings.clang_args([
@@ -618,6 +679,7 @@ fn main() {
618679
sdk_builder.device();
619680
sdk_builder.bolos_sdk().unwrap();
620681
sdk_builder.cxdefines();
682+
sdk_builder.generate_glyphs();
621683
sdk_builder.build_c_sdk();
622684
sdk_builder.generate_bindings();
623685
sdk_builder.generate_heap_size();
@@ -721,6 +783,7 @@ fn finalize_stax_configuration(command: &mut cc::Build, bolos_sdk: &Path) {
721783
command.define(define.as_str(), value.as_deref());
722784
}
723785

786+
let glyphs_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("glyphs_stax");
724787
command
725788
.target("thumbv8m.main-none-eabi")
726789
.file(bolos_sdk.join("src/ledger_protocol.c"))
@@ -739,8 +802,8 @@ fn finalize_stax_configuration(command: &mut cc::Build, bolos_sdk: &Path) {
739802
.include(bolos_sdk.join("target/stax/include/"))
740803
.flag("-fropi")
741804
.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"));
744807
configure_lib_nbgl(command, bolos_sdk);
745808
}
746809

@@ -750,6 +813,7 @@ fn finalize_flex_configuration(command: &mut cc::Build, bolos_sdk: &Path) {
750813
command.define(define.as_str(), value.as_deref());
751814
}
752815

816+
let glyphs_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("glyphs_flex");
753817
command
754818
.target("thumbv8m.main-none-eabi")
755819
.file(bolos_sdk.join("src/ledger_protocol.c"))
@@ -768,8 +832,8 @@ fn finalize_flex_configuration(command: &mut cc::Build, bolos_sdk: &Path) {
768832
.include(bolos_sdk.join("target/flex/include/"))
769833
.flag("-fropi")
770834
.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"));
773837
configure_lib_nbgl(command, bolos_sdk);
774838
}
775839

0 commit comments

Comments
 (0)