From 7cc3c6feb73f32170940f74276b510b16d30335c Mon Sep 17 00:00:00 2001 From: Mykhailo Kremniov Date: Mon, 8 Dec 2025 13:09:12 +0200 Subject: [PATCH] CI fix: hardcode a separate Rust version to use with do_checks.sh. Run "cargo fmt". --- .github/workflows/code_checks.yml | 6 ++--- Cargo.toml | 4 +++ build-tools/cargo-info-extractor/extract.py | 28 ++++++++++++++++++--- src/tests/mod.rs | 10 ++++---- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/.github/workflows/code_checks.yml b/.github/workflows/code_checks.yml index e16703d..3a57ac2 100644 --- a/.github/workflows/code_checks.yml +++ b/.github/workflows/code_checks.yml @@ -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 @@ -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 @@ -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 diff --git a/Cargo.toml b/Cargo.toml index f9c1421..e504329 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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] diff --git a/build-tools/cargo-info-extractor/extract.py b/build-tools/cargo-info-extractor/extract.py index fd631a2..6638c36 100755 --- a/build-tools/cargo-info-extractor/extract.py +++ b/build-tools/cargo-info-extractor/extract.py @@ -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: @@ -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__": diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 8fed9d5..8f99fc0 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -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::*;