Skip to content

Commit a534ef4

Browse files
authored
Use "nicer" cfgs (#38)
Instead of hacking in the specific device in the `build.rs`, which doesn't work for downstream packages, specify it as the "os" in the target json. Also specify "bolos" as a `target_family` to make a catch-all `cfg` for any Ledger device easy too.
1 parent cdd7d41 commit a534ef4

File tree

8 files changed

+22
-18
lines changed

8 files changed

+22
-18
lines changed

build.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::process::Command;
44
use std::{env, error::Error, fs::File, io::Read};
55

66
fn finalize_nanos_configuration(command: &mut cc::Build, bolos_sdk: &String) -> String {
7-
println!("cargo:rustc-cfg=nanos");
87
command
98
.target("thumbv6m-none-eabi")
109
.define("ST31", None)
@@ -25,7 +24,6 @@ fn finalize_nanos_configuration(command: &mut cc::Build, bolos_sdk: &String) ->
2524
}
2625

2726
fn finalize_nanox_configuration(command: &mut cc::Build, bolos_sdk: &String) -> String {
28-
println!("cargo:rustc-cfg=nanox");
2927
command
3028
.target("thumbv6m-none-eabi")
3129
.define("ST33", None)
@@ -86,7 +84,6 @@ fn finalize_nanox_configuration(command: &mut cc::Build, bolos_sdk: &String) ->
8684
}
8785

8886
fn finalize_nanosplus_configuration(command: &mut cc::Build, bolos_sdk: &String) -> String {
89-
println!("cargo:rustc-cfg=nanosplus");
9087
command
9188
.target("thumbv8m.main-none-eabi")
9289
.define("ST33K1M5", None)

nanos.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@
2020
},
2121
"relocation-model": "ropi",
2222
"singlethread": true,
23-
"target-pointer-width": "32"
24-
}
23+
"target-pointer-width": "32",
24+
"os": "nanos",
25+
"target-family": [ "bolos" ]
26+
}

nanosplus.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@
1919
},
2020
"relocation-model": "ropi-rwpi",
2121
"singlethread": true,
22-
"target-pointer-width": "32"
23-
}
22+
"target-pointer-width": "32",
23+
"os": "nanosplus",
24+
"target-family": [ "bolos" ]
25+
}

nanox.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@
1919
},
2020
"relocation-model": "ropi-rwpi",
2121
"singlethread": true,
22-
"target-pointer-width": "32"
23-
}
22+
"target-pointer-width": "32",
23+
"os": "nanox",
24+
"target-family": [ "bolos" ]
25+
26+
}

src/io.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::bindings::*;
2-
#[cfg(nanox)]
2+
#[cfg(target_os = "nanox")]
33
use crate::ble;
44
use crate::buttons::{get_button_event, ButtonEvent, ButtonsState};
55

@@ -136,7 +136,7 @@ impl Comm {
136136
seph::seph_send(&[seph::SephTags::RawAPDU as u8, len[0], len[1]]);
137137
seph::seph_send(&self.apdu_buffer[..self.tx]);
138138
}
139-
#[cfg(nanox)]
139+
#[cfg(target_os = "nanox")]
140140
APDU_BLE => {
141141
ble::send(&self.apdu_buffer[..self.tx]);
142142
}
@@ -266,7 +266,7 @@ impl Comm {
266266
seph::handle_capdu_event(&mut self.apdu_buffer, &spi_buffer)
267267
}
268268

269-
#[cfg(nanox)]
269+
#[cfg(target_os = "nanox")]
270270
seph::Events::BleReceive => ble::receive(&mut self.apdu_buffer, &spi_buffer),
271271

272272
seph::Events::TickerEvent => return Event::Ticker,

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
pub mod bindings;
1010

11-
#[cfg(nanox)]
11+
#[cfg(target_os = "nanox")]
1212
pub mod ble;
1313

1414
pub mod buttons;

src/nvm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,11 @@ macro_rules! atomic_storage {
184184
};
185185
}
186186

187-
#[cfg(nanos)]
187+
#[cfg(target_os = "nanos")]
188188
atomic_storage!(64);
189-
#[cfg(nanox)]
189+
#[cfg(target_os = "nanox")]
190190
atomic_storage!(256);
191-
#[cfg(nanosplus)]
191+
#[cfg(target_os = "nanosplus")]
192192
atomic_storage!(512);
193193

194194
pub enum AtomicStorageElem {

src/seph.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::bindings::*;
44
use crate::usbbindings::*;
55

6-
#[cfg(nanox)]
6+
#[cfg(target_os = "nanox")]
77
use crate::ble;
88

99
#[repr(u8)]
@@ -245,7 +245,7 @@ pub fn handle_event(apdu_buffer: &mut [u8], spi_buffer: &[u8]) {
245245
handle_usb_ep_xfer_event(apdu_buffer, spi_buffer);
246246
}
247247
}
248-
#[cfg(nanox)]
248+
#[cfg(target_os = "nanox")]
249249
Events::BleReceive => ble::receive(apdu_buffer, spi_buffer),
250250
Events::CAPDUEvent => handle_capdu_event(apdu_buffer, spi_buffer),
251251
Events::TickerEvent => { /* unsafe{ G_io_app.ms += 100; } */ }

0 commit comments

Comments
 (0)