summaryrefslogtreecommitdiffstats
path: root/chromium/tools/rust/package_rust.py
blob: abffce1df1b6045b42f19de88613f4918632bdce (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
#!/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.

import argparse
import os
import shutil
import sys
import tarfile

THIS_DIR = os.path.dirname(__file__)
sys.path.append(
    os.path.join(os.path.dirname(THIS_DIR), '..', 'clang', 'scripts'))

from build_rust import (RUST_TOOLCHAIN_OUT_DIR, THIRD_PARTY_DIR,
                        VERSION_STAMP_PATH)
from update_rust import (GetPackageVersion)
from package import (MaybeUpload, TeeCmd)
from update import (CHROMIUM_DIR)

PACKAGE_VERSION = GetPackageVersion()
BUILDLOG_NAME = f'rust-buildlog-{PACKAGE_VERSION}.txt'
RUST_TOOLCHAIN_PACKAGE_NAME = f'rust-toolchain-{PACKAGE_VERSION}.tgz'


def main():
  parser = argparse.ArgumentParser(description='build and package Rust')
  parser.add_argument('--upload',
                      action='store_true',
                      help='upload package to GCS')
  args = parser.parse_args()

  # Only build on Linux. Other platforms are currently unsupported.
  if not sys.platform.startswith('linux'):
    print('Only Linux is supported!')
    return 1

  gcs_platform = 'Linux_x64'

  # Clean build output directory
  if os.path.exists(RUST_TOOLCHAIN_OUT_DIR):
    shutil.rmtree(RUST_TOOLCHAIN_OUT_DIR)

  with open(os.path.join(THIRD_PARTY_DIR, BUILDLOG_NAME), 'w') as log:
    build_cmd = [sys.executable, os.path.join(THIS_DIR, 'build_rust.py')]
    TeeCmd(build_cmd, log)

  with tarfile.open(os.path.join(THIRD_PARTY_DIR, RUST_TOOLCHAIN_PACKAGE_NAME),
                    'w:gz') as tar:
    tar.add(RUST_TOOLCHAIN_OUT_DIR, arcname='rust-toolchain')

  os.chdir(THIRD_PARTY_DIR)
  MaybeUpload(args.upload, RUST_TOOLCHAIN_PACKAGE_NAME, gcs_platform)
  MaybeUpload(args.upload, BUILDLOG_NAME, gcs_platform)

  return 0


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