Skip to content

Commit bc7804b

Browse files
danakjcopybara-github
authored andcommitted
Improve the Rust Windows toolchain build on workstations
Pass the `--build` on the install step, as on Windows some machines may decide to target x86_64-pc-windows-gnu instead of x86_64-pc-windows-msvc when it's not specified. Add `.exe` suffix on the clang/llvm binary paths. Without it the bootstrap tool can run them but can't "find" them and this causes errors which then cause it to rebuild everything every time, even rebuilding things multiple times across the build_rust.py steps. This should also make the bot build faster. Warn if the sh.exe is coming from gnubby as that is a cygwin shell and it can't handle normalized unix-style paths like git bash can. The Rust install will fail if trying to use that shell. Since it needs to be first in the PATH for other things, let --sh specify the path to Git's shell and then insert that at the front of PATH for the duration of build_rust.py. Avoid dirtying files by downloading zlib when using --skip-checkout so that it's quicker to rebuild incrementally on Windows. Bug: 40212971 Change-Id: I192a05e1b977e5442e8a8ecc06617938994880ef Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5893972 Reviewed-by: Hans Wennborg <hans@chromium.org> Commit-Queue: danakj <danakj@chromium.org> Reviewed-by: Łukasz Anforowicz <lukasza@chromium.org> Cr-Commit-Position: refs/heads/main@{#1361873} NOKEYCHECK=True GitOrigin-RevId: 4aa05521467cf5025f516d46138554673976371c
1 parent 5acd939 commit bc7804b

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

build_rust.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,28 @@ def main():
680680
'running specified command, skipping all normal build steps. For '
681681
'debugging. Running x.py directly will not set the appropriate env '
682682
'variables nor update config.toml')
683+
if sys.platform == 'win32':
684+
parser.add_argument('--sh', help='path to the sh.exe to use')
683685
args, rest = parser.parse_known_args()
684686

687+
if sys.platform == 'win32':
688+
if args.sh:
689+
assert args.sh.endswith('sh.exe')
690+
p = os.environ['PATH']
691+
shdir = os.path.dirname(args.sh)
692+
os.environ['PATH'] = f'{shdir};{p}'
693+
where = subprocess.check_output(['where.exe', 'sh'], text=True)
694+
if '\\gnubby\\' in where.splitlines()[0]:
695+
print("WARNING: It looks like you have gnubby sh.exe in your ")
696+
print(" PATH, but it does not support normalized paths of the ")
697+
print(" form `/c/foo` and will fail at the install step. Put the ")
698+
print(" sh.exe from the Git installation into your PATH first ")
699+
print(" when running this script or use --sh to specify the path ")
700+
print(" to sh.exe.")
701+
print("where sh.exe:")
702+
print(where)
703+
return 1
704+
685705
debian_sysroot = None
686706
if sys.platform.startswith('linux') and not args.sync_for_gnrt:
687707
# Fetch sysroot we build rustc against. This ensures a minimum supported
@@ -691,7 +711,7 @@ def main():
691711

692712
# Require zlib compression.
693713
if sys.platform == 'win32':
694-
zlib_path = AddZlibToPath()
714+
zlib_path = AddZlibToPath(dry_run=args.skip_checkout)
695715
else:
696716
zlib_path = None
697717

@@ -701,9 +721,9 @@ def main():
701721
else:
702722
libxml2_dirs = None
703723

704-
# TODO(crbug.com/40205621): OpenSSL is somehow already present on the Windows
705-
# builder, but we should change to using a package from 3pp when it is
706-
# available.
724+
# TODO(crbug.com/40205621): OpenSSL is somehow already present on the
725+
# Windows builder, but we should change to using a package from 3pp when it
726+
# is available.
707727
if (sys.platform != 'win32' and not args.sync_for_gnrt):
708728
# Building cargo depends on OpenSSL.
709729
AddOpenSSLToEnv()
@@ -806,8 +826,8 @@ def main():
806826
if args.prepare_run_xpy:
807827
return 0
808828

809-
building_on_host_triple = RustTargetTriple()
810-
xpy_args = ['--build', building_on_host_triple]
829+
target_triple = RustTargetTriple()
830+
xpy_args = ['--build', target_triple]
811831

812832
# Delete the build directory.
813833
if not args.skip_clean:
@@ -834,7 +854,7 @@ def main():
834854
if os.path.exists(RUST_TOOLCHAIN_OUT_DIR):
835855
RmTree(RUST_TOOLCHAIN_OUT_DIR)
836856

837-
xpy.run('install', [])
857+
xpy.run('install', xpy_args + [])
838858

839859
# The Rust stdlib deps are vendored to rust-src/library/vendor, and later
840860
# the x.py install process copies all subdirs of rust-src/library to the

config.toml.template

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ prefix = "$INSTALL_DIR"
5252
sysconfdir = "etc"
5353

5454
[target.x86_64-pc-windows-msvc]
55-
llvm-config = "$LLVM_BIN/llvm-config"
55+
llvm-config = "$LLVM_BIN/llvm-config.exe"
5656
# TODO(danakj): We don't ship this in the clang toolchain package.
57-
# ranlib = "$LLVM_BIN/llvm-ranlib"
58-
ar = "$LLVM_BIN/llvm-lib"
59-
cc = "$LLVM_BIN/clang-cl"
60-
cxx = "$LLVM_BIN/clang-cl"
61-
linker = "$LLVM_BIN/lld-link"
57+
# ranlib = "$LLVM_BIN/llvm-ranlib.exe"
58+
ar = "$LLVM_BIN/llvm-lib.exe"
59+
cc = "$LLVM_BIN/clang-cl.exe"
60+
cxx = "$LLVM_BIN/clang-cl.exe"
61+
linker = "$LLVM_BIN/lld-link.exe"
6262

6363
[target.aarch64-apple-darwin]
6464
llvm-config = "$LLVM_BIN/llvm-config"

0 commit comments

Comments
 (0)