Skip to content

Commit 6e3a9ca

Browse files
authored
Merge pull request #3 from mintlayer/fix_cargo_deny_installation_on_ci
CI fix: hardcode a separate Rust version to use with do_checks.sh
2 parents 32d9e3c + 7cc3c6f commit 6e3a9ca

4 files changed

Lines changed: 36 additions & 12 deletions

File tree

.github/workflows/code_checks.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: Install Rust
3737
run: |
3838
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
39-
--default-toolchain $(python ./build-tools/cargo-info-extractor/extract.py --rust-version)
39+
--default-toolchain $(python ./build-tools/cargo-info-extractor/extract.py --rust-version-for-checks)
4040
4141
- name: Install Clippy
4242
run: rustup component add clippy
@@ -63,7 +63,7 @@ jobs:
6363
- name: Install Rust
6464
run: |
6565
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
66-
--default-toolchain $(python ./build-tools/cargo-info-extractor/extract.py --rust-version)
66+
--default-toolchain $(python ./build-tools/cargo-info-extractor/extract.py --rust-version-for-checks)
6767
6868
- name: Install Clippy
6969
run: rustup component add clippy
@@ -99,7 +99,7 @@ jobs:
9999
shell: bash
100100
run: |
101101
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
102-
--default-toolchain $(python ./build-tools/cargo-info-extractor/extract.py --rust-version)
102+
--default-toolchain $(python ./build-tools/cargo-info-extractor/extract.py --rust-version-for-checks)
103103
104104
- name: Install Clippy
105105
run: rustup component add clippy

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ readme = "README.md"
77
license = "MIT"
88
version = "1.0.0"
99
edition = "2021"
10+
# Note: the maximum Rust version we can use here is limited by the Rust toolchains available
11+
# in the Nix packages and Docker images used by the Trezor firmware and Ledger app repositories.
12+
# There is also another Rust version hard-coded in `build-tools/cargo-info-extractor/extract.py` -
13+
# `RUST_VERSION_FOR_CHECKS`; it's used to run `do_checks.sh` and it may be higher than this one.
1014
rust-version = "1.85"
1115

1216
[dependencies]

build-tools/cargo-info-extractor/extract.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@
1212
ROOT_DIR = pathlib.Path(__file__).resolve().parent.parent.parent
1313
ROOT_CARGO_TOML = ROOT_DIR.joinpath("Cargo.toml")
1414

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

16-
def get_rust_version(cargo_toml_root):
21+
22+
def get_rust_version_from_cargo_toml(cargo_toml_root):
1723
version = cargo_toml_root["package"]["rust-version"]
1824

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

2430

2531
def main():
26-
parser = argparse.ArgumentParser()
32+
parser = argparse.ArgumentParser(
33+
# Use a bigger max_help_position, so that each parameter's help fits into one line.
34+
formatter_class=lambda prog: argparse.HelpFormatter(prog, max_help_position=30)
35+
)
2736
mutex_group = parser.add_mutually_exclusive_group(required=True)
28-
mutex_group.add_argument('--rust-version', action='store_true', help='extract Rust version')
37+
mutex_group.add_argument(
38+
'--rust-version',
39+
action='store_true',
40+
help='extract Rust version from Cargo.toml; this is the version that should be used for compilation'
41+
)
42+
mutex_group.add_argument(
43+
'--rust-version-for-checks',
44+
action='store_true',
45+
help='return the Rust version needed to run do_checks.sh'
46+
)
2947
args = parser.parse_args()
3048

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

3452
if args.rust_version:
35-
result = get_rust_version(cargo_toml_root)
53+
result = get_rust_version_from_cargo_toml(cargo_toml_root)
3654
print(result)
55+
elif args.rust_version_for_checks:
56+
print(RUST_VERSION_FOR_CHECKS)
3757

3858

3959
if __name__ == "__main__":

src/tests/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ use parity_scale_codec::Encode;
2525
use strum::IntoEnumIterator as _;
2626

2727
use crate::tests::utils::{
28+
SCALE_CODEC_COMPACT_ENC_10_BYTE_VAL_START, SCALE_CODEC_COMPACT_ENC_11_BYTE_VAL_START,
29+
SCALE_CODEC_COMPACT_ENC_12_BYTE_VAL_START, SCALE_CODEC_COMPACT_ENC_13_BYTE_VAL_START,
30+
SCALE_CODEC_COMPACT_ENC_14_BYTE_VAL_START, SCALE_CODEC_COMPACT_ENC_15_BYTE_VAL_START,
31+
SCALE_CODEC_COMPACT_ENC_16_BYTE_VAL_START, SCALE_CODEC_COMPACT_ENC_17_BYTE_VAL_START,
2832
SCALE_CODEC_COMPACT_ENC_2_BYTE_VAL_START, SCALE_CODEC_COMPACT_ENC_4_BYTE_VAL_START,
2933
SCALE_CODEC_COMPACT_ENC_5_BYTE_VAL_START, SCALE_CODEC_COMPACT_ENC_6_BYTE_VAL_START,
3034
SCALE_CODEC_COMPACT_ENC_7_BYTE_VAL_START, SCALE_CODEC_COMPACT_ENC_8_BYTE_VAL_START,
31-
SCALE_CODEC_COMPACT_ENC_9_BYTE_VAL_START, SCALE_CODEC_COMPACT_ENC_10_BYTE_VAL_START,
32-
SCALE_CODEC_COMPACT_ENC_11_BYTE_VAL_START, SCALE_CODEC_COMPACT_ENC_12_BYTE_VAL_START,
33-
SCALE_CODEC_COMPACT_ENC_13_BYTE_VAL_START, SCALE_CODEC_COMPACT_ENC_14_BYTE_VAL_START,
34-
SCALE_CODEC_COMPACT_ENC_15_BYTE_VAL_START, SCALE_CODEC_COMPACT_ENC_16_BYTE_VAL_START,
35-
SCALE_CODEC_COMPACT_ENC_17_BYTE_VAL_START,
35+
SCALE_CODEC_COMPACT_ENC_9_BYTE_VAL_START,
3636
};
3737

3838
use super::*;

0 commit comments

Comments
 (0)