Skip to content

Commit 5900faa

Browse files
Ensure the library search path from cc_toolchain is preferred over whatever rustc finds in the Windows registry (#3608)
I don't see a good way to stop rustc from adding the non-hermetic library search path, so put our cc_toolchain library search path on the command line where it has precedence over the non-hermetic path injected by rustc. See https://rust-lang.zulipchat.com/#narrow/channel/242869-t-compiler.2Fwindows/topic/rust.20LIB.20path for discussion of the rustc behavior. Closes #3256. Co-authored-by: Daniel Wagner-Hall <[email protected]>
1 parent 98e494e commit 5900faa

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

rust/private/rustc.bzl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,17 @@ def get_linker_and_args(ctx, crate_type, cc_toolchain, feature_configuration, rp
482482
feature_configuration = feature_configuration,
483483
action_name = action_name,
484484
)
485+
if "LIB" in link_env:
486+
# Needed to ensure that link.exe will use msvcrt.lib from the cc_toolchain,
487+
# and not a non-hermetic system version.
488+
# https://github.com/bazelbuild/rules_rust/issues/3256
489+
# I don't see a good way to stop rustc from adding the non-hermetic library search path,
490+
# so put our cc_toolchain library search path on the command line where it has
491+
# precedence over the non-hermetic path injected by rustc.
492+
link_args = link_args + [
493+
"-LIBPATH:" + element
494+
for element in link_env["LIB"].split(";")
495+
]
485496

486497
return ld, link_args, link_env
487498

0 commit comments

Comments
 (0)