1212ROOT_DIR = pathlib .Path (__file__ ).resolve ().parent .parent .parent
1313ROOT_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
2531def 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
3959if __name__ == "__main__" :
0 commit comments