Skip to content

Commit 9277831

Browse files
authored
Merge pull request #235 from LedgerHQ/y333/better_glyphs_management
Generate glyphs automatically when building sys crate
2 parents 296440f + 4c93f64 commit 9277831

File tree

8 files changed

+74
-1901
lines changed

8 files changed

+74
-1901
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ledger_device_sdk/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ledger_device_sdk"
3-
version = "1.19.5"
3+
version = "1.19.6"
44
authors = ["yhql", "yogh333", "agrojean-ledger", "kingofpayne"]
55
edition = "2021"
66
license.workspace = true
@@ -21,7 +21,7 @@ rand_core = { version = "0.6.3", default-features = false }
2121
zeroize = { version = "1.6.0", default-features = false }
2222
numtoa = "0.2.4"
2323
const-zero = "0.1.1"
24-
ledger_secure_sdk_sys = { path = "../ledger_secure_sdk_sys", version = "1.6.1" }
24+
ledger_secure_sdk_sys = { path = "../ledger_secure_sdk_sys", version = "1.6.3" }
2525

2626
[features]
2727
debug = []

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: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,59 @@ 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 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+
403456
pub fn build_c_sdk(&self) {
404457
let mut command = cc::Build::new();
405458
if env::var_os("CC").is_none() {
@@ -534,11 +587,15 @@ impl SDKBuilder {
534587
)
535588
}
536589
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()]);
542599

543600
bindings = bindings.clang_args([
544601
format!("-I{bsdk}/lib_nbgl/include/").as_str(),
@@ -618,6 +675,7 @@ fn main() {
618675
sdk_builder.device();
619676
sdk_builder.bolos_sdk().unwrap();
620677
sdk_builder.cxdefines();
678+
sdk_builder.generate_glyphs();
621679
sdk_builder.build_c_sdk();
622680
sdk_builder.generate_bindings();
623681
sdk_builder.generate_heap_size();
@@ -721,6 +779,7 @@ fn finalize_stax_configuration(command: &mut cc::Build, bolos_sdk: &Path) {
721779
command.define(define.as_str(), value.as_deref());
722780
}
723781

782+
let glyphs_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("glyphs_stax");
724783
command
725784
.target("thumbv8m.main-none-eabi")
726785
.file(bolos_sdk.join("src/ledger_protocol.c"))
@@ -739,8 +798,8 @@ fn finalize_stax_configuration(command: &mut cc::Build, bolos_sdk: &Path) {
739798
.include(bolos_sdk.join("target/stax/include/"))
740799
.flag("-fropi")
741800
.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"));
744803
configure_lib_nbgl(command, bolos_sdk);
745804
}
746805

@@ -750,6 +809,7 @@ fn finalize_flex_configuration(command: &mut cc::Build, bolos_sdk: &Path) {
750809
command.define(define.as_str(), value.as_deref());
751810
}
752811

812+
let glyphs_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("glyphs_flex");
753813
command
754814
.target("thumbv8m.main-none-eabi")
755815
.file(bolos_sdk.join("src/ledger_protocol.c"))
@@ -768,8 +828,8 @@ fn finalize_flex_configuration(command: &mut cc::Build, bolos_sdk: &Path) {
768828
.include(bolos_sdk.join("target/flex/include/"))
769829
.flag("-fropi")
770830
.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"));
773833
configure_lib_nbgl(command, bolos_sdk);
774834
}
775835

0 commit comments

Comments
 (0)