Skip to content

Commit

Permalink
revert LEDGER_C_SDK_PATH to LEDGER_SDK_PATH and in cargo-ledger check…
Browse files Browse the repository at this point in the history
… if not already defined
  • Loading branch information
yogh333 committed Jan 10, 2024
1 parent 6684876 commit dda29dc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
39 changes: 22 additions & 17 deletions cargo-ledger/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,33 +194,38 @@ fn build_app(
) {
let exe_path = match use_prebuilt {
None => {
let mut cargo_cmd = Command::new("cargo")
.args([
"build",
"--release",
format!("--target={}", device.as_ref()).as_str(),
"--message-format=json-diagnostic-rendered-ansi",
])
.args(&remaining_args)
.stdout(Stdio::piped());

let c_sdk_path = match device {
Device::Nanos => std::env::var("NANOS_SDK"),
Device::Nanosplus => std::env::var("NANOSP_SDK"),
Device::Nanox => std::env::var("NANOX_SDK"),
};

match c_sdk_path {
Ok(path) => {
cargo_cmd = cargo_cmd
.arg(format!("--config env.LEDGER_C_SDK_PATH={}", path))
}
let mut args: Vec<String> = vec![];
args.push(String::from("build"));
args.push(String::from("--release"));
args.push(format!("--target={}", device.as_ref()));
args.push(String::from(
"--message-format=json-diagnostic-rendered-ansi",
));

match std::env::var("LEDGER_SDK_PATH") {
Ok(_) => (),
Err(_) => {
println!("No C SDK, it will be cloned while building the Rust SDK")
if let Ok(path) = c_sdk_path {
args.push(format!(
"--config env.LEDGER_SDK_PATH={}",
path
))
}
}
}

let mut cargo_cmd = cargo_cmd.spawn().unwrap();
let mut cargo_cmd = Command::new("cargo")
.args(args)
.args(&remaining_args)
.stdout(Stdio::piped())
.spawn()
.unwrap();

let mut exe_path = PathBuf::new();
let out = cargo_cmd.stdout.take().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions ledger_secure_sdk_sys/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Provides access to low-level APIs to the operating system of Ledger devices.

Depending on the target (`--target nanos`, `--target nanox`, ...), this crate will `git clone` the appropriate branch (`API_LEVEL_x`) of the [C SDK](https://github.com/LedgerHQ/ledger-secure-sdk/) and compile the subset of files necessary for the [Rust SDK](https://github.com/LedgerHQ/ledger-nanos-sdk/) to work.

To use an already-cloned C SDK, you can pass its path through the environment variable `LEDGER_C_SDK_PATH=/path/to/c_sdk` or through `cargo`'s `--config` flag:
To use an already-cloned C SDK, you can pass its path through the environment variable `LEDGER_SDK_PATH=/path/to/c_sdk` or through `cargo`'s `--config` flag:

```sh
cargo build --target nanosplus --config env.LEDGER_C_SDK_PATH="../ledger-secure-sdk/"
cargo build --target nanosplus --config env.LEDGER_SDK_PATH="../ledger-secure-sdk/"
```
4 changes: 2 additions & 2 deletions ledger_secure_sdk_sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ impl SDKBuilder {
}

pub fn bolos_sdk(&mut self) -> Result<(), SDKBuildError> {
println!("cargo:rerun-if-env-changed=LEDGER_C_SDK_PATH");
let sdk_path = match env::var("LEDGER_C_SDK_PATH") {
println!("cargo:rerun-if-env-changed=LEDGER_SDK_PATH");
let sdk_path = match env::var("LEDGER_SDK_PATH") {
Err(_) => clone_sdk(&self.device),
Ok(path) => PathBuf::from(path),
};
Expand Down

0 comments on commit dda29dc

Please sign in to comment.