Skip to content

Commit b86abe3

Browse files
committed
Fix bindings
1 parent 8baa856 commit b86abe3

File tree

1 file changed

+54
-8
lines changed

1 file changed

+54
-8
lines changed

ledger_secure_sdk_sys/build.rs

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ enum DeviceName {
3131
NanoX,
3232
Stax,
3333
Flex,
34+
ApexP,
3435
}
3536

3637
#[derive(Debug, Default)]
@@ -52,6 +53,7 @@ impl std::fmt::Display for DeviceName {
5253
DeviceName::NanoX => write!(f, "nanox"),
5354
DeviceName::Stax => write!(f, "stax"),
5455
DeviceName::Flex => write!(f, "flex"),
56+
DeviceName::ApexP => write!(f, "apex_p"),
5557
}
5658
}
5759
}
@@ -238,6 +240,26 @@ impl SDKBuilder<'_> {
238240
arm_libs: Default::default(),
239241
linker_script: "flex_layout.ld",
240242
},
243+
"apex_p" => Device {
244+
name: DeviceName::ApexP,
245+
c_sdk: match env::var("LEDGER_SDK_PATH").or_else(|_| env::var("APEX_P_SDK")) {
246+
Ok(path) => PathBuf::from(path),
247+
Err(_) => return Err(SDKBuildError::MissingSDKPath),
248+
},
249+
target: "thumbv8m.main-none-eabi",
250+
defines: header2define("c_sdk_build_apex_p.defines"),
251+
cflags: {
252+
let mut m_path = String::from(env!("CARGO_MANIFEST_DIR"));
253+
m_path.push_str("/c_sdk_build_apex_p.cflags");
254+
let f = File::open(m_path)
255+
.expect("Failed to open c_sdk_build_apex_p.cflags file");
256+
let reader = BufReader::new(f);
257+
reader.lines().filter_map(|line| line.ok()).collect::<Vec<String>>()
258+
},
259+
glyphs_folders: Vec::new(),
260+
arm_libs: Default::default(),
261+
linker_script: "apex_p_layout.ld",
262+
},
241263
_ => {
242264
return Err(SDKBuildError::UnsupportedDevice);
243265
}
@@ -267,6 +289,17 @@ impl SDKBuilder<'_> {
267289
.glyphs_folders
268290
.push(self.device.c_sdk.join("lib_nbgl/glyphs/32px"));
269291
}
292+
DeviceName::ApexP => {
293+
self.device
294+
.glyphs_folders
295+
.push(self.device.c_sdk.join("lib_nbgl/glyphs/wallet"));
296+
self.device
297+
.glyphs_folders
298+
.push(self.device.c_sdk.join("lib_nbgl/glyphs/48px"));
299+
self.device
300+
.glyphs_folders
301+
.push(self.device.c_sdk.join("lib_nbgl/glyphs/24px"));
302+
}
270303
_ => {
271304
self.device
272305
.glyphs_folders
@@ -281,7 +314,7 @@ impl SDKBuilder<'_> {
281314
path.push_str("/arch/st33/lib");
282315
path
283316
}
284-
DeviceName::NanoSPlus | DeviceName::Flex | DeviceName::Stax => {
317+
DeviceName::NanoSPlus | DeviceName::Flex | DeviceName::Stax | DeviceName::ApexP => {
285318
let mut path = self.device.c_sdk.display().to_string();
286319
path.push_str("/arch/st33k1/lib");
287320
path
@@ -355,8 +388,6 @@ impl SDKBuilder<'_> {
355388
.files(&AUX_C_FILES)
356389
.files(str2path(&self.device.c_sdk, &SDK_C_FILES));
357390

358-
//command
359-
// .file(c_sdk.join("lib_standard_app/main.c"))
360391

361392
let glyphs_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("glyphs");
362393

@@ -468,6 +499,7 @@ impl SDKBuilder<'_> {
468499
DeviceName::NanoX => String::from("c_sdk_build_nanox.defines"),
469500
DeviceName::Stax => String::from("c_sdk_build_stax.defines"),
470501
DeviceName::Flex => String::from("c_sdk_build_flex.defines"),
502+
DeviceName::ApexP => String::from("c_sdk_build_apex_p.defines"),
471503
};
472504

473505
bindings = bindings.clang_arg(format!("-I{bsdk}/target/{csdk_target_name}/include/"));
@@ -483,6 +515,7 @@ impl SDKBuilder<'_> {
483515
&& env::var_os("CARGO_FEATURE_NANO_NBGL").is_some())
484516
|| self.device.name == DeviceName::Stax
485517
|| self.device.name == DeviceName::Flex
518+
|| self.device.name == DeviceName::ApexP
486519
{
487520
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
488521
let mut include_path = "-I".to_string();
@@ -501,12 +534,21 @@ impl SDKBuilder<'_> {
501534
.join("lib_nbgl/include/nbgl_use_case.h")
502535
.to_str()
503536
.unwrap(),
537+
)
538+
.header(
539+
self.device
540+
.c_sdk
541+
.join("lib_ux_nbgl/ux_nbgl.h")
542+
.to_str()
543+
.unwrap(),
504544
);
545+
} else {
546+
bindings = bindings.clang_arg("-DHAVE_UX_FLOW");
505547
}
506548

507549
// BLE bindings
508550
match self.device.name {
509-
DeviceName::NanoX | DeviceName::Flex | DeviceName::Stax => {
551+
DeviceName::NanoX | DeviceName::Flex | DeviceName::Stax | DeviceName::ApexP => {
510552
bindings = bindings.header(
511553
self.device
512554
.c_sdk
@@ -807,19 +849,23 @@ fn clone_sdk(devicename: &DeviceName) -> PathBuf {
807849
let (repo_url, sdk_branch) = match devicename {
808850
DeviceName::NanoX => (
809851
Path::new("https://github.com/LedgerHQ/ledger-secure-sdk"),
810-
"API_LEVEL_22",
852+
"API_LEVEL_24",
811853
),
812854
DeviceName::NanoSPlus => (
813855
Path::new("https://github.com/LedgerHQ/ledger-secure-sdk"),
814-
"API_LEVEL_22",
856+
"API_LEVEL_24",
815857
),
816858
DeviceName::Stax => (
817859
Path::new("https://github.com/LedgerHQ/ledger-secure-sdk"),
818-
"API_LEVEL_22",
860+
"API_LEVEL_24",
819861
),
820862
DeviceName::Flex => (
821863
Path::new("https://github.com/LedgerHQ/ledger-secure-sdk"),
822-
"API_LEVEL_22",
864+
"API_LEVEL_24",
865+
),
866+
DeviceName::ApexP => (
867+
Path::new("https://github.com/LedgerHQ/ledger-secure-sdk"),
868+
"API_LEVEL_25",
823869
),
824870
};
825871

0 commit comments

Comments
 (0)