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
|
#!/usr/bin/env python3
# Copyright 2024 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
'''Run cargo from the chromium Rust toolchain.
Arguments are passed through to cargo.
Should be run from the checkout root (i.e. as `tools/crates/run_cargo.py ...`)
'''
import argparse
import os
import platform
import subprocess
import sys
DEFAULT_SYSROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..',
'..', 'third_party', 'rust-toolchain')
def RunCargo(rust_sysroot, home_dir, cargo_args):
if not os.path.exists(rust_sysroot):
print(f'WARNING: Rust sysroot missing at "{rust_sysroot}"')
abs_rust_sysroot = os.path.abspath(rust_sysroot)
bin_dir = os.path.join(abs_rust_sysroot, 'bin')
cargo_env = dict(os.environ)
if home_dir:
cargo_env['CARGO_HOME'] = home_dir
cargo_env['PATH'] = (f'{bin_dir}{os.pathsep}{cargo_env["PATH"]}'
if cargo_env["PATH"] else f'{bin_dir}')
return subprocess.run([
'cargo',
] + cargo_args, env=cargo_env).returncode
def main():
parser = argparse.ArgumentParser(description='run cargo')
parser.add_argument('--rust-sysroot',
default=DEFAULT_SYSROOT,
help='use cargo and rustc from here')
(args, cargo_args) = parser.parse_known_args()
if sys.platform == 'darwin' and platform.machine() == 'arm64':
if args.rust_sysroot == 'third_party/rust-toolchain':
args.rust_sysroot = os.path.expanduser(
'~/.rustup/toolchains/nightly-aarch64-apple-darwin')
print('No "cargo" provided in the Chromium toolchain on Mac-ARM. '
'Install cargo nightly to ~/.rustup or use --rust-sysroot:')
print("== To install: `rustup install nightly`")
return RunCargo(args.rust_sysroot, None, cargo_args)
if __name__ == '__main__':
sys.exit(main())
|