diff --git a/ledger_secure_sdk_sys/build.rs b/ledger_secure_sdk_sys/build.rs index 98e163c7..3fa464b2 100644 --- a/ledger_secure_sdk_sys/build.rs +++ b/ledger_secure_sdk_sys/build.rs @@ -92,7 +92,7 @@ impl Device { #[derive(Default)] struct SDKInfo { pub bolos_sdk: PathBuf, - pub api_level: u32, + pub api_level: Option, pub target_id: String, pub target_name: String, pub c_sdk_name: String, @@ -163,7 +163,7 @@ fn retrieve_sdk_git_info(bolos_sdk: &Path) -> (String, String) { (c_sdk_hash, c_sdk_version) } -fn retrieve_makefile_infos(bolos_sdk: &Path) -> Result<(u32, String), SDKBuildError> { +fn retrieve_makefile_infos(bolos_sdk: &Path) -> Result<(Option, String), SDKBuildError> { let makefile_defines = File::open(bolos_sdk.join("Makefile.defines")).expect("Could not find Makefile.defines"); let mut api_level: Option = None; @@ -182,11 +182,8 @@ fn retrieve_makefile_infos(bolos_sdk: &Path) -> Result<(u32, String), SDKBuildEr break; } } - - let api_level = api_level.ok_or(SDKBuildError::InvalidAPILevel)?; let sdk_name = sdk_name.ok_or(SDKBuildError::MissingSDKName)?; - - Ok((api_level as u32, sdk_name)) + Ok((api_level, sdk_name)) } fn retrieve_target_file_infos( @@ -348,15 +345,21 @@ impl SDKBuilder { let sdk_info = retrieve_sdk_info(&self.device, &sdk_path)?; self.bolos_sdk = sdk_info.bolos_sdk; - self.api_level = sdk_info.api_level; - // Export SDK infos into env for 'infos.rs' - println!("cargo:rustc-env=API_LEVEL={}", self.api_level); - println!( - "cargo:rustc-env=API_LEVEL_STR={}", - format!("{}", self.api_level) - ); - println!("cargo:warning=API_LEVEL is {}", self.api_level); + match sdk_info.api_level { + Some(api_level) => { + self.api_level = api_level; + // Export api level into env for 'infos.rs' + println!("cargo:rustc-env=API_LEVEL={}", self.api_level); + println!("cargo:warning=API_LEVEL is {}", self.api_level); + } + None => { + if self.device != Device::NanoS { + return Err(SDKBuildError::InvalidAPILevel); + } + } + } + // Export other SDK infos into env for 'infos.rs' println!("cargo:rustc-env=TARGET_ID={}", sdk_info.target_id); println!("cargo:warning=TARGET_ID is {}", sdk_info.target_id); println!("cargo:rustc-env=TARGET_NAME={}", sdk_info.target_name); diff --git a/ledger_secure_sdk_sys/src/infos.rs b/ledger_secure_sdk_sys/src/infos.rs index 58db6a54..3fcd805b 100644 --- a/ledger_secure_sdk_sys/src/infos.rs +++ b/ledger_secure_sdk_sys/src/infos.rs @@ -17,6 +17,7 @@ macro_rules! const_cstr { }; } +#[cfg(not(target_os = "nanos"))] const fn const_parse_api_level(x: &str) -> u8 { let a = x.as_bytes(); let mut res = a[0] - b'0'; @@ -31,10 +32,13 @@ const fn const_parse_api_level(x: &str) -> u8 { /// Expose the API_LEVEL #[used] +#[cfg(not(target_os = "nanos"))] static API_LEVEL: u8 = const_parse_api_level(env!("API_LEVEL")); // Store metadata in the ELF file -const_cstr!(ELF_API_LEVEL, "ledger.api_level", env!("API_LEVEL_STR")); +#[cfg(not(target_os = "nanos"))] +const_cstr!(ELF_API_LEVEL, "ledger.api_level", env!("API_LEVEL")); + const_cstr!(ELF_TARGET, "ledger.target", env!("TARGET")); const_cstr!(ELF_TARGET_ID, "ledger.target_id", env!("TARGET_ID")); const_cstr!(ELF_TARGET_NAME, "ledger.target_name", env!("TARGET_NAME"));