Skip to content

Commit 2aa8a76

Browse files
committed
Set C SDK path when building sys crate
1 parent 720e0db commit 2aa8a76

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

.cargo/config.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,4 @@ build-std = ["core", "alloc"]
33
build-std-features = ["compiler-builtins-mem"]
44

55
[build]
6-
target = "flex"
7-
8-
[env]
9-
LEDGER_SDK_PATH="/opt/flex-secure-sdk/"
6+
target = "flex"

ledger_secure_sdk_sys/build.rs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ enum SDKBuildError {
132132
UnsupportedDevice,
133133
InvalidAPILevel,
134134
MissingSDKName,
135+
MissingSDKPath,
135136
TargetFileNotFound,
136137
MissingTargetId,
137138
MissingTargetName,
@@ -186,7 +187,13 @@ impl SDKBuilder<'_> {
186187
{
187188
"nanosplus" => Device {
188189
name: DeviceName::NanoSPlus,
189-
c_sdk: Default::default(),
190+
c_sdk: match env::var("LEDGER_SDK_PATH") {
191+
Ok(path) => PathBuf::from(path),
192+
Err(_) => match env::var("NANOSP_SDK") {
193+
Ok(path) => PathBuf::from(path),
194+
Err(_) => return Err(SDKBuildError::MissingSDKPath),
195+
},
196+
},
190197
target: "thumbv8m.main-none-eabi",
191198
defines: {
192199
let mut v = header2define("csdk_nanos2.h");
@@ -209,7 +216,13 @@ impl SDKBuilder<'_> {
209216
},
210217
"nanox" => Device {
211218
name: DeviceName::NanoX,
212-
c_sdk: Default::default(),
219+
c_sdk: match env::var("LEDGER_SDK_PATH") {
220+
Ok(path) => PathBuf::from(path),
221+
Err(_) => match env::var("NANOX_SDK") {
222+
Ok(path) => PathBuf::from(path),
223+
Err(_) => return Err(SDKBuildError::MissingSDKPath),
224+
},
225+
},
213226
target: "thumbv6m-none-eabi",
214227
defines: {
215228
let mut v = header2define("csdk_nanox.h");
@@ -232,7 +245,13 @@ impl SDKBuilder<'_> {
232245
},
233246
"stax" => Device {
234247
name: DeviceName::Stax,
235-
c_sdk: Default::default(),
248+
c_sdk: match env::var("LEDGER_SDK_PATH") {
249+
Ok(path) => PathBuf::from(path),
250+
Err(_) => match env::var("STAX_SDK") {
251+
Ok(path) => PathBuf::from(path),
252+
Err(_) => return Err(SDKBuildError::MissingSDKPath),
253+
},
254+
},
236255
target: "thumbv8m.main-none-eabi",
237256
defines: header2define("csdk_stax.h"),
238257
cflags: Vec::from(CFLAGS_STAX),
@@ -242,7 +261,13 @@ impl SDKBuilder<'_> {
242261
},
243262
"flex" => Device {
244263
name: DeviceName::Flex,
245-
c_sdk: Default::default(),
264+
c_sdk: match env::var("LEDGER_SDK_PATH") {
265+
Ok(path) => PathBuf::from(path),
266+
Err(_) => match env::var("FLEX_SDK") {
267+
Ok(path) => PathBuf::from(path),
268+
Err(_) => return Err(SDKBuildError::MissingSDKPath),
269+
},
270+
},
246271
target: "thumbv8m.main-none-eabi",
247272
defines: header2define("csdk_flex.h"),
248273
cflags: Vec::from(CFLAGS_FLEX),
@@ -255,12 +280,6 @@ impl SDKBuilder<'_> {
255280
}
256281
};
257282

258-
// set the C SDK path
259-
self.device.c_sdk = match env::var("LEDGER_SDK_PATH") {
260-
Err(_) => clone_sdk(&self.device.name),
261-
Ok(path) => PathBuf::from(path),
262-
};
263-
264283
// set glyphs folders
265284
match self.device.name {
266285
DeviceName::Flex => {
@@ -780,6 +799,7 @@ fn retrieve_target_file_infos(
780799
}
781800

782801
/// Fetch the appropriate C SDK to build
802+
#[allow(dead_code)]
783803
fn clone_sdk(devicename: &DeviceName) -> PathBuf {
784804
let (repo_url, sdk_branch) = match devicename {
785805
DeviceName::NanoX => (

0 commit comments

Comments
 (0)