Skip to content

Commit ceb9086

Browse files
chbaker0Aravind Vasudevan
authored andcommitted
Update Rust and fix build by vendoring sources
x.py was failing due to the use of sudo on builders (see rust-lang/rust#93344). Enabling vendoring bypasses this check and prepares us for future vendoring of dependency sources, which we will likely want to do. The build still touches $HOME/.cargo which is undesirable but a fix will be in a later change. Bug: 1245714 Change-Id: Ic6d2027289ebdbcf82a03b6bc571167245acb398 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3417957 Reviewed-by: Adrian Taylor <[email protected]> Commit-Queue: Collin Baker <[email protected]> Cr-Commit-Position: refs/heads/main@{#964667} NOKEYCHECK=True GitOrigin-RevId: 7888dedb890c571f16a2d8111f2fd47f0a783e60
1 parent c3a68d0 commit ceb9086

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

build.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
from update import (CHROMIUM_DIR, CLANG_REVISION, CLANG_SUB_REVISION,
4747
LLVM_BUILD_DIR, RmTree)
4848

49-
# Trunk on 1/6/2021
50-
RUST_REVISION = '2e2c86eba21a08cf505cd67073736d03ff3887ad'
49+
# Trunk on 1/26/2021
50+
RUST_REVISION = 'a7f3757'
5151
RUST_SUB_REVISION = 1
5252

5353
PACKAGE_VERSION = '%s-%s-%s-%s' % (RUST_REVISION, RUST_SUB_REVISION,
@@ -61,6 +61,11 @@
6161
RUST_CONFIG_TEMPLATE_PATH = os.path.join(
6262
os.path.dirname(os.path.abspath(__file__)), 'config.toml.template')
6363

64+
# Desired tools and libraries in our Rust toolchain.
65+
DISTRIBUTION_ARTIFACTS = [
66+
'cargo', 'clippy', 'library/std', 'rust-analyzer', 'rustfmt', 'src/librustc'
67+
]
68+
6469

6570
def RunCommand(command, env=None, fail_hard=True):
6671
print('Running', command)
@@ -74,16 +79,25 @@ def RunCommand(command, env=None, fail_hard=True):
7479

7580

7681
def CheckoutRust(commit, dir):
82+
# Submodules we must update early since bootstrap wants them before it starts
83+
# managing them.
84+
force_update_submodules = [
85+
'src/tools/rust-analyzer', 'compiler/rustc_codegen_cranelift'
86+
]
87+
88+
# Shared between first checkout and subsequent updates.
89+
def UpdateSubmodules():
90+
return RunCommand(['git', 'submodule', 'update', '--init', '--recursive'] +
91+
force_update_submodules,
92+
fail_hard=False)
93+
7794
# Try updating the current repo if it exists and has no local diff.
7895
if os.path.isdir(dir):
7996
os.chdir(dir)
8097
# git diff-index --quiet returns success when there is no diff.
8198
# Also check that the first commit is reachable.
8299
if (RunCommand(['git', 'diff-index', '--quiet', 'HEAD'], fail_hard=False)
83-
and RunCommand(['git', 'fetch'], fail_hard=False)
84-
and RunCommand(['git', 'checkout', commit], fail_hard=False)
85-
and RunCommand(['git', 'submodule', 'update', '--recursive'],
86-
fail_hard=False)):
100+
and UpdateSubmodules()):
87101
return
88102

89103
# If we can't use the current repo, delete it.
@@ -95,7 +109,8 @@ def CheckoutRust(commit, dir):
95109

96110
if RunCommand(clone_cmd, fail_hard=False):
97111
os.chdir(dir)
98-
if RunCommand(['git', 'checkout', commit], fail_hard=False):
112+
if (RunCommand(['git', 'checkout', commit], fail_hard=False)
113+
and UpdateSubmodules()):
99114
return
100115

101116
print('CheckoutRust failed.')
@@ -157,6 +172,9 @@ def main():
157172
parser.add_argument('--skip-test',
158173
action='store_true',
159174
help='skip running rustc and libstd tests')
175+
parser.add_argument('--skip-install',
176+
action='store_true',
177+
help='do not install to RUST_TOOLCHAIN_OUT_DIR')
160178
args = parser.parse_args()
161179

162180
if not args.skip_checkout:
@@ -184,11 +202,9 @@ def main():
184202
],
185203
verbose=args.verbose)
186204

187-
artifacts = [
188-
'cargo', 'clippy', 'library/std', 'rust-analyzer', 'rustfmt',
189-
'src/librustc'
190-
]
191-
RunXPy('install', ['--stage', '1', '--keep-stage', '1'] + artifacts)
205+
if not args.skip_install:
206+
RunXPy('install',
207+
['--stage', '1', '--keep-stage', '1'] + DISTRIBUTION_ARTIFACTS)
192208

193209

194210
if __name__ == '__main__':

config.toml.template

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ channel = "dev"
1414
description = "chromium"
1515

1616
[build]
17+
# Vendor crates.io dependencies to rust-src/vendor and check they match root
18+
# Cargo.lock. In the future we will probably want to vendor these ourself like
19+
# we do with third_party/rust dependencies. For now, the Rust build script auto
20+
# fetches the dependencies.
21+
#
22+
# This is added now to work around a permissions bug in Rust's bootstrap:
23+
# it fails to run under sudo even if the sudo user is not root, unless sources
24+
# are vendored in tree.
25+
locked-deps = true
26+
vendor = true
27+
1728
target = ["x86_64-unknown-linux-gnu"]
1829

1930
[install]

0 commit comments

Comments
 (0)