summaryrefslogtreecommitdiffstats
path: root/chromium/tools/rust/update_rust.py
blob: de0274914ec7579f8dfd921cacaae88abd356463 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
# Copyright 2022 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
'''Update in-tree checkout of Rust toolchain

!!! DO NOT USE IN PRODUCTION
Some functionality can be used outside of a chromium checkout. For example,
running with `--print-rust-revision` will succeed. Other functionality requires
a Chromium checkout to access functions from other scripts.

'''

import argparse
import os
import sys

from pathlib import Path

# Add Clang scripts to path so we can import them later (if running within a
# Chromium checkout.)
sys.path.append(
    os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'clang',
                 'scripts'))

# Trunk on 4/1/2022
RUST_REVISION = '79f178b7'
RUST_SUB_REVISION = 1

# Hash of src/stage0.json, which itself contains the stage0 toolchain hashes.
# We trust the Rust build system checks, but to ensure it is not tampered with
# itself check the hash.
STAGE0_JSON_SHA256 = (
    'a38b7ea8b8cbdb592b1a7ae8b97fa31746a2bda309597de111be4893a035070d')


def GetPackageVersion():
  from update import (CLANG_REVISION, CLANG_SUB_REVISION)
  return '%s-%s-%s-%s' % (RUST_REVISION, RUST_SUB_REVISION, CLANG_REVISION,
                          CLANG_SUB_REVISION)


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). 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)')
  args = parser.parse_args()

  if args.print_rust_revision:
    print(f'{RUST_REVISION}-{RUST_SUB_REVISION}')
    return 0

  if args.print_package_version:
    print(GetPackageVersion())
    return 0


if __name__ == '__main__':
  sys.exit(main())