Add a script to generate stdlib GN rules from the Rust src tree
The tools/gnrt_stdlib.py script needs to be run when rolling Rust in order to generate updated BUILD.gn files whenever the Cargo.toml files change in the stdlib. Previously gnrt gen --for-std would generate rules from the Rust library found in //third_party/rust-toolchain, but that requires Rust to already be rolled, so this now uses the feature of specifying the Rust source tree root to --for-std. Bug: 1401042 Change-Id: Id7c9e9c67687ad53fd5e4e5b469f7c2c18163a1b Cq-Include-Trybots: luci.chromium.try:android-rust-arm32-rel,android-rust-arm64-rel,android-rust-arm64-dbg,linux-rust-x64-dbg,linux-rust-x64-rel,mac-rust-x64-dbg,win-rust-x64-dbg,win-rust-x64-rel Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4600126 Commit-Queue: danakj <danakj@chromium.org> Reviewed-by: Hans Wennborg <hans@chromium.org> Cr-Commit-Position: refs/heads/main@{#1155567}
This commit is contained in:
tools
@@ -10,11 +10,9 @@ a CL, triggers Clang Upload try bots, and tells what to do next"""
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import fnmatch
|
|
||||||
import itertools
|
import itertools
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import shutil
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import urllib.request
|
import urllib.request
|
||||||
@@ -303,7 +301,9 @@ def main():
|
|||||||
print('Cannot set both --skip-clang and --skip-rust.')
|
print('Cannot set both --skip-clang and --skip-rust.')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if not args.skip_clang:
|
if args.skip_clang:
|
||||||
|
clang_version = '-skipped-'
|
||||||
|
else:
|
||||||
if args.clang_git_hash:
|
if args.clang_git_hash:
|
||||||
clang_git_hash = args.clang_git_hash
|
clang_git_hash = args.clang_git_hash
|
||||||
else:
|
else:
|
||||||
@@ -315,10 +315,10 @@ def main():
|
|||||||
clang_version = ClangVersion(GetCommitDescription(clang_git_hash),
|
clang_version = ClangVersion(GetCommitDescription(clang_git_hash),
|
||||||
args.clang_sub_revision)
|
args.clang_sub_revision)
|
||||||
os.chdir(CHROMIUM_DIR)
|
os.chdir(CHROMIUM_DIR)
|
||||||
else:
|
|
||||||
clang_version = '-skipped-'
|
|
||||||
|
|
||||||
if not args.skip_rust:
|
if args.skip_rust:
|
||||||
|
rust_version = '-skipped-'
|
||||||
|
else:
|
||||||
if args.rust_git_hash:
|
if args.rust_git_hash:
|
||||||
rust_git_hash = args.rust_git_hash
|
rust_git_hash = args.rust_git_hash
|
||||||
else:
|
else:
|
||||||
@@ -326,8 +326,6 @@ def main():
|
|||||||
CheckoutGitRepo("Rust", RUST_GIT_URL, rust_git_hash, RUST_SRC_DIR)
|
CheckoutGitRepo("Rust", RUST_GIT_URL, rust_git_hash, RUST_SRC_DIR)
|
||||||
rust_version = RustVersion(rust_git_hash, args.rust_sub_revision)
|
rust_version = RustVersion(rust_git_hash, args.rust_sub_revision)
|
||||||
os.chdir(CHROMIUM_DIR)
|
os.chdir(CHROMIUM_DIR)
|
||||||
else:
|
|
||||||
rust_version = '-skipped-'
|
|
||||||
|
|
||||||
print(f'Making a patch for Clang {clang_version} and Rust {rust_version}')
|
print(f'Making a patch for Clang {clang_version} and Rust {rust_version}')
|
||||||
|
|
||||||
@@ -420,6 +418,12 @@ def main():
|
|||||||
|
|
||||||
print('Please, wait until the try bots succeeded '
|
print('Please, wait until the try bots succeeded '
|
||||||
'and then push the binaries to goma.')
|
'and then push the binaries to goma.')
|
||||||
|
print()
|
||||||
|
print('To regenerate BUILD.gn rules for Rust stdlib (needed if dep versions '
|
||||||
|
'in the stdlib change for example), run:\n tools/rust/gnrt_stdlib.py.')
|
||||||
|
print()
|
||||||
|
print('To update Abseil .def files, run:\n '
|
||||||
|
'third_party/abseil-cpp/generate_def_files.py')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@@ -106,6 +106,9 @@ fn generate_for_third_party(args: &clap::ArgMatches, paths: &paths::ChromiumPath
|
|||||||
if let Some(cargo_path) = args.get_one::<String>("cargo-path") {
|
if let Some(cargo_path) = args.get_one::<String>("cargo-path") {
|
||||||
command.cargo_path(cargo_path);
|
command.cargo_path(cargo_path);
|
||||||
}
|
}
|
||||||
|
if let Some(rustc_path) = args.get_one::<String>("rustc-path") {
|
||||||
|
command.env("RUSTC", rustc_path);
|
||||||
|
}
|
||||||
|
|
||||||
command.current_dir(&paths.third_party);
|
command.current_dir(&paths.third_party);
|
||||||
let dependencies = deps::collect_dependencies(&command.exec().unwrap(), None, None);
|
let dependencies = deps::collect_dependencies(&command.exec().unwrap(), None, None);
|
||||||
@@ -261,6 +264,9 @@ fn generate_for_std(args: &clap::ArgMatches, paths: &paths::ChromiumPaths) -> Re
|
|||||||
if let Some(cargo_path) = args.get_one::<String>("cargo-path") {
|
if let Some(cargo_path) = args.get_one::<String>("cargo-path") {
|
||||||
command.cargo_path(cargo_path);
|
command.cargo_path(cargo_path);
|
||||||
}
|
}
|
||||||
|
if let Some(rustc_path) = args.get_one::<String>("rustc-path") {
|
||||||
|
command.env("RUSTC", rustc_path);
|
||||||
|
}
|
||||||
|
|
||||||
command.current_dir(paths.std_fake_root);
|
command.current_dir(paths.std_fake_root);
|
||||||
|
|
||||||
|
@@ -37,8 +37,13 @@ impl ChromiumPaths {
|
|||||||
Ok(ChromiumPaths {
|
Ok(ChromiumPaths {
|
||||||
root: cur_dir.clone(),
|
root: cur_dir.clone(),
|
||||||
third_party: check_path(&cur_dir, RUST_THIRD_PARTY_DIR)?,
|
third_party: check_path(&cur_dir, RUST_THIRD_PARTY_DIR)?,
|
||||||
|
// We tolerate the Rust sources being missing, as they are only used to generate
|
||||||
|
// rules for the stdlib during Clang/Rust rolls, and they are not checked out for
|
||||||
|
// most machines.
|
||||||
rust_src_vendor_subdir: Path::new(RUST_SRC_VENDOR_SUBDIR),
|
rust_src_vendor_subdir: Path::new(RUST_SRC_VENDOR_SUBDIR),
|
||||||
rust_src_installed: check_path(&cur_dir, RUST_SRC_INSTALLED_DIR)?,
|
// We tolerate the toolchain package dir being missing, as it's not checked out
|
||||||
|
// on the bots that generate Clang/Rust rolls.
|
||||||
|
rust_src_installed: Path::new(RUST_SRC_INSTALLED_DIR),
|
||||||
std_config_file: check_path(&cur_dir, STD_CONFIG_FILE)?,
|
std_config_file: check_path(&cur_dir, STD_CONFIG_FILE)?,
|
||||||
std_build: check_path(&cur_dir, STD_BUILD_DIR)?,
|
std_build: check_path(&cur_dir, STD_BUILD_DIR)?,
|
||||||
std_fake_root: check_path(&cur_dir, STD_FAKE_ROOT)?,
|
std_fake_root: check_path(&cur_dir, STD_FAKE_ROOT)?,
|
||||||
|
@@ -36,6 +36,14 @@ fn main() -> Result<()> {
|
|||||||
.num_args(1)
|
.num_args(1)
|
||||||
.help("Path to the cargo executable"),
|
.help("Path to the cargo executable"),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("rustc-path")
|
||||||
|
.long("rustc-path")
|
||||||
|
.value_name("RUSTC_PATH")
|
||||||
|
.value_parser(clap::value_parser!(String))
|
||||||
|
.num_args(1)
|
||||||
|
.help("Path to the rustc executable"),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("for-std")
|
Arg::new("for-std")
|
||||||
.long("for-std")
|
.long("for-std")
|
||||||
|
@@ -58,7 +58,7 @@ def main():
|
|||||||
RunCommand([
|
RunCommand([
|
||||||
os.path.join(cargo_work_dir, 'release', f'gnrt{EXE}'), 'gen',
|
os.path.join(cargo_work_dir, 'release', f'gnrt{EXE}'), 'gen',
|
||||||
f'--for-std={os.path.relpath(args.rust_src_dir, CHROMIUM_DIR)}',
|
f'--for-std={os.path.relpath(args.rust_src_dir, CHROMIUM_DIR)}',
|
||||||
f'--cargo-path={cargo_bin}'
|
f'--cargo-path={cargo_bin}', f'--rustc-path={rustc_bin}'
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user