Skip to content

Commit e29e413

Browse files
danakjAravind Vasudevan
authored andcommitted
Verify that the list of Cargo.tomls to vendor matches bootstrap/dist.rs
When these change upstream we need to change our build_rust.py script so that we don't get missing vendored dependencies (which can look like wrong versions and gets confusing). R=collinbaker@chromium.org Bug: 1441917 Change-Id: Ia8b70a206ef1c7c7de198161002655e7392fa9c9 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4508134 Commit-Queue: danakj <danakj@chromium.org> Reviewed-by: Collin Baker <collinbaker@chromium.org> Cr-Commit-Position: refs/heads/main@{#1140231} NOKEYCHECK=True GitOrigin-RevId: 12a7862a280dbb36a57c5e6f38c4a21f3c77ea6c
1 parent 4d0a866 commit e29e413

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

build_rust.py

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import json
4040
import platform
4141
import os
42+
import re
4243
import shutil
4344
import string
4445
import subprocess
@@ -97,6 +98,8 @@
9798
'github.com/rust-lang/rust')
9899

99100
RUST_SRC_DIR = os.path.join(THIRD_PARTY_DIR, 'rust_src', 'src')
101+
RUST_BOOTSTRAP_DIST_RS = os.path.join(RUST_SRC_DIR, 'src', 'bootstrap',
102+
'dist.rs')
100103
STAGE0_JSON_PATH = os.path.join(RUST_SRC_DIR, 'src', 'stage0.json')
101104
# Download crates.io dependencies to rust-src subdir (rather than $HOME/.cargo)
102105
CARGO_HOME_DIR = os.path.join(RUST_SRC_DIR, 'cargo-home')
@@ -256,6 +259,42 @@ def InstallBetaPackage(package_dir, install_dir):
256259

257260
def CargoVendor(cargo_bin):
258261
'''Runs `cargo vendor` to pull down dependencies.'''
262+
# From https://github.com/rust-lang/rust/blob/4a18324a4df6bc98bec0b54d35908d7a9cdc7c32/src/bootstrap/dist.rs#L1008-L1015:
263+
# The additional `--sync` Cargo.toml files are not part of the top level
264+
# workspace.
265+
SYNC_TARGETS = [
266+
'./src/tools/cargo/Cargo.toml',
267+
'./src/tools/rust-analyzer/Cargo.toml',
268+
'./compiler/rustc_codegen_cranelift/Cargo.toml',
269+
'./src/bootstrap/Cargo.toml',
270+
]
271+
272+
# Try to verify our sync targets match the upstream nightly tarball
273+
# builder's.
274+
BUILDER_REGEX = (r'(?:'
275+
r'\s*\.arg\("--sync"\)'
276+
r'\s*\.arg\(builder.src.join\("(?P<target>[^"]+)"\)\)'
277+
r')')
278+
content = ''
279+
with open(RUST_BOOTSTRAP_DIST_RS) as f:
280+
content = ''.join([line.strip() for line in f])
281+
upstream_sync_targets = re.compile(BUILDER_REGEX).findall(content)
282+
error = False
283+
for s in SYNC_TARGETS:
284+
if not s in upstream_sync_targets:
285+
print(f'Upstream bootstrap/dist.rs removed "--sync {s}", '
286+
'so it should be removed from SYNC_TARGETS in '
287+
'//tools/rust/build_rust.py.')
288+
error = True
289+
for s in upstream_sync_targets:
290+
if not s in SYNC_TARGETS:
291+
print(f'Upstream bootstrap/dist.rs added "--sync {s}", '
292+
'so it should be added to SYNC_TARGETS in '
293+
'//tools/rust/build_rust.py.')
294+
error = True
295+
if error:
296+
sys.exit(1)
297+
259298
os.chdir(RUST_SRC_DIR)
260299

261300
for i in range(0, 3):
@@ -273,23 +312,14 @@ def CargoVendor(cargo_bin):
273312
else:
274313
sys.exit(1)
275314

276-
# From https://github.com/rust-lang/rust/blob/master/src/bootstrap/dist.rs#L1003-L1013:
277-
# The additional `--sync` Cargo.toml files are not part of the top level
278-
# workspace.
279315
vendor_cmd = [
280316
cargo_bin,
281317
'vendor',
282318
'--locked',
283319
'--versioned-dirs',
284-
'--sync',
285-
'src/tools/cargo/Cargo.toml',
286-
'--sync',
287-
'src/tools/rust-analyzer/Cargo.toml',
288-
'--sync',
289-
'compiler/rustc_codegen_cranelift/Cargo.toml',
290-
'--sync',
291-
'src/bootstrap/Cargo.toml',
292320
]
321+
for s in SYNC_TARGETS:
322+
vendor_cmd.extend(['--sync', s])
293323
if RunCommand(vendor_cmd, fail_hard=False):
294324
break # Success, break out of the retry loop.
295325
elif i < 2:

update_rust.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ def main():
192192
shutil.rmtree(RUST_TOOLCHAIN_OUT_DIR)
193193

194194
try:
195-
platform_prefix = GetPlatformUrlPrefix(GetDefaultHostOs())
196195
DownloadAndUnpack(url, THIRD_PARTY_DIR)
197196
except urllib.error.HTTPError as e:
198197
print(f'error: Failed to download Rust package')

0 commit comments

Comments
 (0)