Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/code_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Install Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
--default-toolchain $(python ./build-tools/cargo-info-extractor/extract.py --rust-version)
--default-toolchain $(python ./build-tools/cargo-info-extractor/extract.py --rust-version-for-checks)

- name: Install Clippy
run: rustup component add clippy
Expand All @@ -63,7 +63,7 @@ jobs:
- name: Install Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
--default-toolchain $(python ./build-tools/cargo-info-extractor/extract.py --rust-version)
--default-toolchain $(python ./build-tools/cargo-info-extractor/extract.py --rust-version-for-checks)

- name: Install Clippy
run: rustup component add clippy
Expand Down Expand Up @@ -99,7 +99,7 @@ jobs:
shell: bash
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
--default-toolchain $(python ./build-tools/cargo-info-extractor/extract.py --rust-version)
--default-toolchain $(python ./build-tools/cargo-info-extractor/extract.py --rust-version-for-checks)

- name: Install Clippy
run: rustup component add clippy
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ readme = "README.md"
license = "MIT"
version = "1.0.0"
edition = "2021"
# Note: the maximum Rust version we can use here is limited by the Rust toolchains available
# in the Nix packages and Docker images used by the Trezor firmware and Ledger app repositories.
# There is also another Rust version hard-coded in `build-tools/cargo-info-extractor/extract.py` -
# `RUST_VERSION_FOR_CHECKS`; it's used to run `do_checks.sh` and it may be higher than this one.
rust-version = "1.85"

[dependencies]
Expand Down
28 changes: 24 additions & 4 deletions build-tools/cargo-info-extractor/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@
ROOT_DIR = pathlib.Path(__file__).resolve().parent.parent.parent
ROOT_CARGO_TOML = ROOT_DIR.joinpath("Cargo.toml")

# Note: running `do_checks.sh` may need a Rust version that is higher than the one we can use
# for compilation. In particular, at the time of writing this, installing the latest cargo-deny
# requires Rust 1.88.
# TODO: put it elsewhere?
RUST_VERSION_FOR_CHECKS = "1.88.0"

def get_rust_version(cargo_toml_root):

def get_rust_version_from_cargo_toml(cargo_toml_root):
version = cargo_toml_root["package"]["rust-version"]

if len(version.split('.')) == 2:
Expand All @@ -23,17 +29,31 @@ def get_rust_version(cargo_toml_root):


def main():
parser = argparse.ArgumentParser()
parser = argparse.ArgumentParser(
# Use a bigger max_help_position, so that each parameter's help fits into one line.
formatter_class=lambda prog: argparse.HelpFormatter(prog, max_help_position=30)
)
mutex_group = parser.add_mutually_exclusive_group(required=True)
mutex_group.add_argument('--rust-version', action='store_true', help='extract Rust version')
mutex_group.add_argument(
'--rust-version',
action='store_true',
help='extract Rust version from Cargo.toml; this is the version that should be used for compilation'
)
mutex_group.add_argument(
'--rust-version-for-checks',
action='store_true',
help='return the Rust version needed to run do_checks.sh'
)
args = parser.parse_args()

with open(ROOT_CARGO_TOML, "rb") as file:
cargo_toml_root = tomllib.load(file)

if args.rust_version:
result = get_rust_version(cargo_toml_root)
result = get_rust_version_from_cargo_toml(cargo_toml_root)
print(result)
elif args.rust_version_for_checks:
print(RUST_VERSION_FOR_CHECKS)


if __name__ == "__main__":
Expand Down
10 changes: 5 additions & 5 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ use parity_scale_codec::Encode;
use strum::IntoEnumIterator as _;

use crate::tests::utils::{
SCALE_CODEC_COMPACT_ENC_10_BYTE_VAL_START, SCALE_CODEC_COMPACT_ENC_11_BYTE_VAL_START,
SCALE_CODEC_COMPACT_ENC_12_BYTE_VAL_START, SCALE_CODEC_COMPACT_ENC_13_BYTE_VAL_START,
SCALE_CODEC_COMPACT_ENC_14_BYTE_VAL_START, SCALE_CODEC_COMPACT_ENC_15_BYTE_VAL_START,
SCALE_CODEC_COMPACT_ENC_16_BYTE_VAL_START, SCALE_CODEC_COMPACT_ENC_17_BYTE_VAL_START,
SCALE_CODEC_COMPACT_ENC_2_BYTE_VAL_START, SCALE_CODEC_COMPACT_ENC_4_BYTE_VAL_START,
SCALE_CODEC_COMPACT_ENC_5_BYTE_VAL_START, SCALE_CODEC_COMPACT_ENC_6_BYTE_VAL_START,
SCALE_CODEC_COMPACT_ENC_7_BYTE_VAL_START, SCALE_CODEC_COMPACT_ENC_8_BYTE_VAL_START,
SCALE_CODEC_COMPACT_ENC_9_BYTE_VAL_START, SCALE_CODEC_COMPACT_ENC_10_BYTE_VAL_START,
SCALE_CODEC_COMPACT_ENC_11_BYTE_VAL_START, SCALE_CODEC_COMPACT_ENC_12_BYTE_VAL_START,
SCALE_CODEC_COMPACT_ENC_13_BYTE_VAL_START, SCALE_CODEC_COMPACT_ENC_14_BYTE_VAL_START,
SCALE_CODEC_COMPACT_ENC_15_BYTE_VAL_START, SCALE_CODEC_COMPACT_ENC_16_BYTE_VAL_START,
SCALE_CODEC_COMPACT_ENC_17_BYTE_VAL_START,
SCALE_CODEC_COMPACT_ENC_9_BYTE_VAL_START,
};

use super::*;
Expand Down