0

Convert clang & rust exec_script()s to read_files()

Seems to shaves about 100ms off of "gn gen" for me locally, although GN
runtimes have pretty high variance, so it might even be less than that.

gn gen --time shows these as:

Script execute times: (total time in ms, # executions, name)
   824.36  6  //tools/clang/scripts/update.py
   807.49  6  //tools/rust/update_rust.py

Bug: 397998718
Change-Id: Ic99b459c958bced9b97c4d81e34a65d1b64a808b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6488528
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1452750}
This commit is contained in:
Andrew Grieve
2025-04-28 10:58:22 -07:00
committed by Chromium LUCI CQ
parent a5715996e2
commit 2f27c611aa
5 changed files with 79 additions and 23 deletions
build
tools
clang
scripts
rust

@ -1636,22 +1636,74 @@ config("compiler_deterministic") {
config("clang_revision") {
if (is_clang && clang_base_path == default_clang_base_path &&
current_os != "zos") {
update_args = [
"--print-revision",
"--verify-version=$clang_version",
]
_perform_consistency_checks = current_toolchain == default_toolchain
if (llvm_force_head_revision) {
update_args += [ "--llvm-force-head-revision" ]
_head_revision_stamp_path = "//third_party/llvm-build/force_head_revision"
_head_revision = ""
if (path_exists(_head_revision_stamp_path)) {
_head_revision = read_file(_head_revision_stamp_path, "trim string")
}
assert(
_head_revision != "",
"llvm_force_head_revision=true, but no locally built version was detected.")
_clang_revision = _head_revision
} else {
_clang_revision = read_file(
"//third_party/llvm-build/Release+Asserts/cr_build_revision",
"trim string")
# Ensure that the synced clang version matches what's in git.
if (_perform_consistency_checks) {
# Parse the clang version from the Python script.
_clang_version_lines = filter_include(
read_file("//tools/clang/scripts/update.py", "list lines"),
[ "CLANG_*REVISION = *" ])
_py_revision =
string_replace(_clang_version_lines[0], "CLANG_REVISION = '", "")
_py_revision = string_replace(_py_revision, "'", "")
_py_subrevision =
string_replace(_clang_version_lines[1], "CLANG_SUB_REVISION = ", "")
_expected_clang_revision = "$_py_revision-$_py_subrevision"
assert(
_clang_revision == _expected_clang_revision,
"clang_revision=\"$_clang_revision\" but update.py expected \"$_expected_clang_revision\". Did you forget to gclient sync?")
}
}
if (_perform_consistency_checks) {
# Ensure that the revision matches the version major expected by GN.
_versions_match = filter_include([ _clang_revision ],
[ "llvmorg-$clang_version-*" ]) != []
assert(
_versions_match,
"clang_revision=\"$_clang_revision\" but clang_version=\"$clang_version\". clang_version in build/toolchain/toolchain.gni is likely outdated.")
}
if (toolchain_has_rust && _perform_consistency_checks) {
# Ensure that the synced rust version matches what's in git.
_rust_revision_lines =
filter_include(read_file("//tools/rust/update_rust.py", "list lines"),
[ "RUST_*REVISION = *" ])
_py_revision =
string_replace(_rust_revision_lines[0], "RUST_REVISION = '", "")
_py_revision = string_replace(_py_revision, "'", "")
_py_subrevision =
string_replace(_rust_revision_lines[1], "RUST_SUB_REVISION = ", "")
_expected_rust_revision = "$_py_revision-$_py_subrevision"
# Ensure the rust version matches the clang version.
assert(
filter_include([ rustc_revision ],
[ "*-$_expected_rust_revision-*" ]) != [],
"rustc_revision=\"$rustc_revision\" but update_rust.py expected \"$_expected_rust_revision\". Run \"gclient sync\"?")
}
clang_revision = exec_script("//tools/clang/scripts/update.py",
update_args,
"trim string")
# This is here so that all files get recompiled after a clang roll and
# when turning clang on or off. (defines are passed via the command line,
# and build system rebuild things when their commandline changes). Nothing
# should ever read this define.
defines = [ "CR_CLANG_REVISION=\"$clang_revision\"" ]
defines = [ "CR_CLANG_REVISION=\"$_clang_revision\"" ]
}
}

@ -125,10 +125,20 @@ if (enable_rust) {
if (use_chromium_rust_toolchain) {
toolchain_has_rust = chromium_toolchain_supports_platform
if (toolchain_has_rust) {
update_rust_args = [ "--print-package-version" ]
rustc_revision = exec_script("//tools/rust/update_rust.py",
update_rust_args,
"trim string")
rustc_revision =
read_file("//third_party/rust-toolchain/VERSION", "trim string")
# Example:
# rustc 1.88.0 c8f94230282a8e8c1148f3e657f0199aad909228 (c8f94230282a8e8c1148f3e657f0199aad909228-1-llvmorg-21-init-9266-g09006611 chromium)
# Trim it down as much as we can using GN.
rustc_revision = string_replace(rustc_revision, "rustc ", "")
rustc_revision = string_replace(rustc_revision, " chromium", "")
rustc_revision = string_replace(rustc_revision, "init-", "")
rustc_revision = string_replace(rustc_revision, "llvmorg-", "")
rustc_revision = string_replace(rustc_revision, " ", "")
rustc_revision = string_replace(rustc_revision, ".", "")
rustc_revision = string_replace(rustc_revision, "(", "-")
rustc_revision = string_replace(rustc_revision, ")", "")
}
# The same as written in `config.toml.template`.

@ -11,7 +11,6 @@ build_dotfile_settings = {
"//build/config/apple/mobile_config.gni",
"//build/config/chromeos/rules.gni",
"//build/config/clang/BUILD.gn",
"//build/config/compiler/BUILD.gn",
"//build/config/compiler/pgo/BUILD.gn",
"//build/config/gcc/gcc_version.gni",
"//build/config/host_byteorder.gni",
@ -25,7 +24,6 @@ build_dotfile_settings = {
"//build/config/mac/mac_sdk.gni",
"//build/config/mac/rules.gni",
"//build/config/posix/BUILD.gn",
"//build/config/rust.gni",
"//build/config/win/BUILD.gn",
"//build/config/win/visual_studio_version.gni",
"//build/rust/analyze.gni",

@ -36,6 +36,9 @@ import zlib
# https://chromium.googlesource.com/chromium/src/+/main/docs/updating_clang.md
# Reverting problematic clang rolls is safe, though.
# This is the output of `git describe` and is usable as a commit-ish.
# These fields are written by //tools/clang/scripts/upload_revision.py, and
# should not be changed manually.
# They are also read by build/config/compiler/BUILD.gn.
CLANG_REVISION = 'llvmorg-21-init-9266-g09006611'
CLANG_SUB_REVISION = 1
@ -328,16 +331,8 @@ def main():
parser.add_argument('--print-clang-version', action='store_true',
help=('Print current clang release version (e.g. 9.0.0) '
'and exit.'))
parser.add_argument('--verify-version',
help='Verify that clang has the passed-in version.')
args = parser.parse_args()
if args.verify_version and args.verify_version != RELEASE_VERSION:
print('RELEASE_VERSION is %s but --verify-version argument was %s.' % (
RELEASE_VERSION, args.verify_version))
print('clang_version in build/toolchain/toolchain.gni is likely outdated.')
return 1
if args.print_clang_version:
print(RELEASE_VERSION)
return 0

@ -31,6 +31,7 @@ sys.path.append(
# These fields are written by //tools/clang/scripts/upload_revision.py, and
# should not be changed manually.
# They are also read by build/config/compiler/BUILD.gn.
RUST_REVISION = 'c8f94230282a8e8c1148f3e657f0199aad909228'
RUST_SUB_REVISION = 1