Skip to content

Commit 1241b83

Browse files
committed
Fix _symlink_sysroot_tree and linker sysroot path
- Use target_files parameter instead of target.files in loop - Place linker at lib/rustlib/{triple}/bin/ so rustc's PATH includes it Fixes wasm-component-ld failing to find rust-lld on Windows.
1 parent 1755e79 commit 1241b83

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

rust/toolchain.bzl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def _symlink_sysroot_tree(ctx, name, target, target_files = None):
152152
tree_files = []
153153
if target_files == None:
154154
target_files = target.files
155-
for file in target.files.to_list():
155+
for file in target_files.to_list():
156156
# Parse the path to the file relative to the workspace root so a
157157
# symlink matching this path can be created within the sysroot.
158158

@@ -284,11 +284,14 @@ def _generate_sysroot(
284284
linker.label,
285285
))
286286
linker_bin = linker_files[0]
287+
288+
# Extract lib/rustlib/{triple}/bin from linker source path.
289+
# rustc adds {sysroot}/lib/rustlib/{host}/bin/ to PATH when invoking
290+
# linkers, so tools like wasm-component-ld can find rust-lld there.
287291
dest = "bin"
288-
if "/bin/" in linker_bin.path:
289-
_, _, subdir = linker_bin.path.partition("/bin/")
290-
if subdir:
291-
dest = "bin/{}".format(subdir[:-len("/" + linker_bin.basename)]).rstrip("/")
292+
if "/lib/rustlib/" in linker_bin.dirname:
293+
idx = linker_bin.dirname.find("/lib/rustlib/")
294+
dest = linker_bin.dirname[idx + 1:]
292295

293296
sysroot_linker = _symlink_sysroot_bin(ctx, name, dest, linker_bin)
294297
sysroot_linker_files = _symlink_sysroot_tree(ctx, name, linker, linker[DefaultInfo].default_runfiles.files)

0 commit comments

Comments
 (0)