Skip to content

Commit

Permalink
revert MSRV to 1.67.0 for upstream ledger builds (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryankurte authored Jul 22, 2023
1 parent 3b3ca8d commit 69e9f2f
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 39 deletions.
24 changes: 14 additions & 10 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Configure toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2023-01-04
toolchain: nightly-2022-12-02
target: ${{ matrix.target }}
override: true
components: rustfmt, clippy, rust-src
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
- name: Configure toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2023-01-04
toolchain: nightly-2022-12-02
override: true

- name: Install protobuf tools
Expand Down Expand Up @@ -126,7 +126,7 @@ jobs:
- name: Configure toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2023-01-04
toolchain: nightly-2022-12-02
target: ${{ matrix.target }}
override: true

Expand Down Expand Up @@ -227,7 +227,7 @@ jobs:
- name: Configure toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2023-01-04
toolchain: nightly-2022-12-02
target: ${{ matrix.target }}
override: true
components: rust-src
Expand Down Expand Up @@ -292,7 +292,7 @@ jobs:
- name: Configure toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2023-01-04
toolchain: nightly-2022-12-02
target: ${{ matrix.target }}
override: true

Expand Down Expand Up @@ -352,13 +352,13 @@ jobs:
- name: Configure rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2023-01-04
toolchain: nightly-2022-12-02
override: true

- name: Install libusb / hidapi / libudev
run: sudo apt update && sudo apt install -y libusb-1.0-0 libusb-1.0-0-dev libudev-dev libdbus-1-dev

- name: Restore cache from test build
- name: Restore test cache
uses: actions/cache/restore@v3
with:
key: sim
Expand All @@ -370,6 +370,10 @@ jobs:
run: |
docker pull ghcr.io/ledgerhq/speculos:latest
- name: Fetch nextest
run: |
curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin
- name: Fetch firmware artifacts
uses: actions/download-artifact@v3
with:
Expand All @@ -379,8 +383,8 @@ jobs:
- name: Run simulator tests
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path=lib/Cargo.toml
command: nextest
args: run --package ledger-mob

# Package firmware for distribution
package-fw:
Expand Down Expand Up @@ -461,7 +465,7 @@ jobs:
- name: Fetch rust tooling
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2023-01-04
toolchain: nightly-2022-12-02
override: true

- name: Restore core cache
Expand Down
5 changes: 5 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
[submodule "vendor/mob"]
path = vendor/mob
url = ../../mobilecoinfoundation/mobilecoin.git

[submodule "vendor/mc-rand"]
path = vendor/mc-rand
url = ../../ryankurte/mc-rand

[submodule "vendor/speculos"]
path = vendor/speculos
url = ../../LedgerHQ/speculos.git
Expand Down
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ mc-util-from-random = { path = "./vendor/mob/util/from-random" }
mc-util-test-helper = { path = "./vendor/mob/util/test-helper" }
mc-util-serial = { path = "./vendor/mob/util/serial" }

# patched to support ledger required 1.67.0 MSRV
mc-rand = { path = "./vendor/mc-rand" }

6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ lib:
test: core-test nanosplus-test nanox-test

core-test:
cargo test --package ledger-mob-core
cargo nextest run --package ledger-mob-core

nanosplus-test: nanosplus
MODEL=nanosp cargo test --package ledger-mob $(NANOSP_ARGS)
MODEL=nanosp cargo nextest run --package ledger-mob $(NANOSP_ARGS)

nanox-test: nanox
MODEL=nanox cargo test --package ledger-mob
MODEL=nanox cargo nextest run --package ledger-mob

# Build docs
docs:
Expand Down
1 change: 1 addition & 0 deletions fw/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ runner = "speculos.py --model nanox --display qt -a 5 --apdu-port 1237 --zoom 2"
target = "nanosplus"
rustflags = [
"-Z", "emit-stack-sizes",
"-Z", "share-generics=off",
"-C", "link-args=-Map=/tmp/ledger-mob.map",
'--cfg=curve25519_dalek_bits="32"'
]
Expand Down
18 changes: 13 additions & 5 deletions fw/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,22 @@ split-debuginfo = "off"
opt-level = 'z'
lto = 'fat'

# Rust/cargo bug precludes integer overflow checks
# when using LTO, see:
# https://github.com/rust-lang/rust/issues/108853
#overflow-checks = true
# Overflow checks cause the app to run into the stack
# pointer limit bug, these should be enabled when fixed
# in upstream ledger firmware
overflow-checks = false

# When overflow check are enabled these must specifically
# be disabled for compiler_builtins when using LTO
# See:
# - https://github.com/rust-lang/cargo/issues/10118
# - https://github.com/rust-lang/rust/issues/108853
#[profile.release.package.compiler_builtins]
#debug-assertions = false
#overflow-checks = false

[patch.crates-io]


curve25519-dalek = { git = "https://github.com/dalek-cryptography/curve25519-dalek", rev = "99c0520aa79401b69fb51d38172cd58c6a256cfb" }
ed25519-dalek = { git = "https://github.com/dalek-cryptography/ed25519-dalek.git", rev = "2931c688eb11341a1145e257bc41d8ecbe36277c" }
x25519-dalek = { git = "https://github.com/mobilecoinfoundation/x25519-dalek.git", rev = "4fbaa3343301c62cfdbc3023c9f485257e6b718a" }
Expand Down
1 change: 0 additions & 1 deletion fw/rust-toolchain

This file was deleted.

3 changes: 3 additions & 0 deletions fw/rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "nightly-2022-12-02"
components = [ "rustfmt", "clippy", "rust-src" ]
49 changes: 33 additions & 16 deletions lib/tests/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use ledger_lib::{
};
use ledger_sim::*;

const CONNECT_TIMEOUT_S: usize = 10;

// Setup speculos instance and TCP connector with an optional seed
pub async fn setup(seed: Option<String>) -> (GenericDriver, GenericHandle, GenericDevice) {
// Setup logging
Expand Down Expand Up @@ -108,36 +110,51 @@ pub async fn setup(seed: Option<String>) -> (GenericDriver, GenericHandle, Gener
GenericDriver::Docker(DockerDriver::new().expect("Failed to setup docker driver"))
}
};

let s = driver
.run(app_path.to_str().unwrap(), speculos_opts)
.await
.expect("Simulator launch failed");

// Wait for sim to start listening
// TODO: this needs to be a while for CI but is very quick locally...
// could be a retry loop instead of worst-case blocking?
tokio::time::sleep(Duration::from_millis(3000)).await;

// Setup ADPU connector
// Setup TCP ADPU connector
let mut t = TcpTransport::new().expect("APDU connection failed");
let info = TcpInfo {
addr: SocketAddr::new(Ipv4Addr::LOCALHOST.into(), apdu_port),
};

// Connect to simulator APDU socket
// Wait so the simulator has a chance to launch
tokio::time::sleep(Duration::from_secs(3)).await;

debug!("Connecting TCP APDU transport");
let mut t = TcpTransport::new().expect("APDU connection failed");

let device = t.connect(info).await.unwrap();
// Connect to simulator APDU socket
// This can take a variable amount of time in CI so we retry periodically
// until the simulator is available.
let mut device = None;
for i in 0..CONNECT_TIMEOUT_S {
// Attempt to connect to simulator
match t.connect(info.clone()).await {
Ok(v) => {
device = Some(v);
break;
}
Err(_) if i < CONNECT_TIMEOUT_S - 1 => (),
Err(e) => panic!("Failed to connect APDU socket {e:?}"),
};

tokio::time::sleep(Duration::from_secs(1)).await;
}

let device = device.unwrap();

// Press _something_ to dismiss `Review Pending` message
// TODO: remove this from reviewed code? feature gate perhaps?
{
s.button(Button::Right, Action::PressAndRelease)
.await
.expect("Failed to exit review pending");
for i in 0..CONNECT_TIMEOUT_S {
match s.button(Button::Right, Action::PressAndRelease).await {
Ok(_) => break,
Err(_) if i < CONNECT_TIMEOUT_S - 1 => (),
Err(e) => panic!("Failed to exit review pending state {e:?}"),
}

tokio::time::sleep(Duration::from_millis(1000)).await;
tokio::time::sleep(Duration::from_secs(1)).await;
}

(driver, s, device.into())
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-01-04"
channel = "nightly-2022-12-02"
components = [ "rustfmt", "clippy", "rust-src" ]
1 change: 1 addition & 0 deletions vendor/mc-rand
Submodule mc-rand added at e5d04c
2 changes: 1 addition & 1 deletion vendor/mob
Submodule mob updated 2 files
+1 −1 Cargo.toml
+1 −1 docker/rust-toolchain

0 comments on commit 69e9f2f

Please sign in to comment.