'''Update in-tree checkout of Rust toolchain
When run without arguments, it fetches and unzips the Rust toolchain package
specieid by the `RUST_REVISION` and `RUST_SUB_REVISION` along with the clang
version specified in //tools/clang/scripts/update.py.
'''
import argparse
import glob
import os
import re
import shutil
import sys
import time
import urllib
from pathlib import Path
sys.path.append(
os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'clang',
'scripts'))
RUST_REVISION = '4a0969e06dbeaaa43914d2d00b2e843d49aa3886'
RUST_SUB_REVISION = 1
CRUBIT_REVISION = 'fa6caca0969c9d1dec584186eb85ebdd0fe02955'
ABSL_REVISION = 'ba5fd0979b4e74bd4d1b8da1d84347173bd9f17f'
STAGE0_JSON_SHA256 = '981bcaeac1c5f7035166cd59941e4a8e2070c9eb977bc9ef881e656b60c79055'
THIS_DIR = os.path.abspath(os.path.dirname(__file__))
CHROMIUM_DIR = os.path.abspath(os.path.join(THIS_DIR, '..', '..'))
THIRD_PARTY_DIR = os.path.join(CHROMIUM_DIR, 'third_party')
RUST_TOOLCHAIN_OUT_DIR = os.path.join(THIRD_PARTY_DIR, 'rust-toolchain')
VERSION_SRC_PATH = os.path.join(RUST_TOOLCHAIN_OUT_DIR, 'VERSION')
def GetRustClangRevision():
from update import CLANG_REVISION
return f'{RUST_REVISION}-{RUST_SUB_REVISION}-{CLANG_REVISION}'
def GetStampVersion():
if os.path.exists(VERSION_SRC_PATH):
with open(VERSION_SRC_PATH) as version_file:
existing_stamp = version_file.readline().rstrip()
version_re = re.compile(r'rustc [0-9.]+ [0-9a-f]+ \((.+?) chromium\)')
match = version_re.fullmatch(existing_stamp)
if match is None:
return None
return match.group(1)
return None
def main():
parser = argparse.ArgumentParser(description='Update Rust package')
parser.add_argument(
'--print-rust-revision',
action='store_true',
help='Print Rust revision (without Clang revision) and '
'quit. Can be run outside of a Chromium checkout.')
parser.add_argument('--print-package-version',
action='store_true',
help='Print Rust package version (including both the '
'Rust and Clang revisions) and quit.')
args = parser.parse_args()
if args.print_rust_revision:
print(f'{RUST_REVISION}-{RUST_SUB_REVISION}')
return 0
if args.print_package_version:
stamp_version = GetStampVersion()
if stamp_version != GetRustClangRevision():
print(f'The expected Rust version is {GetRustClangRevision()} '
f'but the actual version is {stamp_version}')
print('Did you run "gclient sync"?')
return 1
print(stamp_version)
return 0
from update import (DownloadAndUnpack, GetDefaultHostOs,
GetPlatformUrlPrefix)
platform_prefix = GetPlatformUrlPrefix(GetDefaultHostOs())
version = GetRustClangRevision()
if os.path.exists(RUST_TOOLCHAIN_OUT_DIR):
if version == GetStampVersion() and not glob.glob(
os.path.join(RUST_TOOLCHAIN_OUT_DIR, '.*_is_first_class_gcs')):
return 0
if os.path.exists(RUST_TOOLCHAIN_OUT_DIR):
shutil.rmtree(RUST_TOOLCHAIN_OUT_DIR)
try:
url = f'{platform_prefix}rust-toolchain-{version}.tar.xz'
DownloadAndUnpack(url, RUST_TOOLCHAIN_OUT_DIR)
except urllib.error.HTTPError as e:
print(f'error: Failed to download Rust package')
return 1
assert version == GetStampVersion()
if __name__ == '__main__':
sys.exit(main())