Skip to content

Commit 35e1db2

Browse files
committed
Fix #3256: ensure the library search path from cc_toolchain is preferred over whatever rustc finds in the Windows registry.
1 parent f57fe3d commit 35e1db2

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
@@ -481,6 +481,17 @@ def get_linker_and_args(ctx, crate_type, cc_toolchain, feature_configuration, rp
481481
feature_configuration = feature_configuration,
482482
action_name = action_name,
483483
)
484+
if 'LIB' in link_env:
485+
# Needed to ensure that link.exe will use msvcrt.lib from the cc_toolchain,
486+
# and not a non-hermetic system version.
487+
# https://github.com/bazelbuild/rules_rust/issues/3256
488+
# I don't see a good way to stop rustc from adding the non-hermetic library search path,
489+
# so put our cc_toolchain library search path on the command line where it has
490+
# precedence over the non-hermetic path injected by rustc.
491+
link_args = link_args + [
492+
"-LIBPATH:" + element
493+
for element in link_env['LIB'].split(';')
494+
]
484495

485496
return ld, link_args, link_env
486497

0 commit comments

Comments
 (0)