Skip to content

Commit

Permalink
Set toolchain to 1.70, and make it easier to update toolchains.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSouther authored and meyertst-aws committed Sep 29, 2023
1 parent f0c3183 commit 5b63bb1
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
)
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
toolchain: "1.70.0"
components: clippy, rustfmt
- uses: actions/checkout@v3
- name: Rust format
Expand Down
2 changes: 1 addition & 1 deletion rust_dev_preview/cross_service/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# This should be kept in sync with https://github.com/awslabs/aws-sdk-rust#supported-rust-versions-msrv
[toolchain]
channel = "stable"
channel = "1.70.0"
2 changes: 1 addition & 1 deletion rust_dev_preview/examples/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# This should be kept in sync with https://github.com/awslabs/aws-sdk-rust#supported-rust-versions-msrv
[toolchain]
channel = "1.69.0"
channel = "1.70.0"
85 changes: 85 additions & 0 deletions rust_dev_preview/tools/set_rust_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env python3

try:
import tomlkit
except:
print("Couldn't import tomlkit, either install it directly or instantiate a venv.")
exit(1)

from glob import glob
import argparse
import logging
import pathlib


def read_toml(path: pathlib.Path) -> tomlkit.TOMLDocument:
with open(path, "rt") as file:
return tomlkit.parse(file.read())


def write_toml(path: pathlib.Path, toml: tomlkit.TOMLDocument):
with open(path, "wt") as file:
tomlkit.dump(toml, file)


def update_toolchains(root: pathlib.Path, channel: str, dry_run: bool):
for file in glob(f"{root}/rust_dev_preview/**/rust-toolchain.toml", recursive=True):
toolchain_toml = read_toml(file)
logging.debug(
f"Setting {file} to {channel} from {toolchain_toml['toolchain']['channel']}"
)
toolchain_toml["toolchain"]["channel"] = channel
if not dry_run:
write_toml(file, toolchain_toml)


def update_actions(root: pathlib.Path, channel: str, dry_run: bool):
rust_yaml = root / ".github" / "workflows" / "rust.yml"
with open(rust_yaml, "rt") as file:
action = file.readlines()
found = None
for i, line in enumerate(action):
if "toolchain:" in line:
sep = line.find(":")
found = i, line[sep + 2 :]
action[i] = f'{line[: sep + 1]} "{channel}"\n'
if found == None:
raise Exception(f"Did not find toolchain entry in {rust_yaml}")
logging.debug(f"Setting {rust_yaml} to {channel} from {found}")
if not dry_run:
with open(rust_yaml, "wt") as file:
file.writelines(action)


argument_parser = argparse.ArgumentParser()
argument_parser.add_argument(
"--root",
type=pathlib.Path,
default=pathlib.Path(__file__).absolute().parent.parent.parent,
help="Root path for aws-doc-sdk-examples. Default ../../ assumes running this script from its location in tools.",
)
argument_parser.add_argument(
"channel", help="Toolchain channel to use for Rust code examples."
)
argument_parser.add_argument(
"--dry-run",
dest="dry_run",
action="store_true",
default=False,
help="Don't write updated files.",
)
argument_parser.add_argument(
"--verbose", action="store_true", default=False, help="Write verbose logging"
)


def main():
args = argument_parser.parse_args()
if args.verbose:
logging.basicConfig(level=logging.DEBUG)
update_toolchains(args.root, args.channel, args.dry_run)
update_actions(args.root, args.channel, args.dry_run)


if __name__ == "__main__":
main()

0 comments on commit 5b63bb1

Please sign in to comment.