@@ -160,6 +160,23 @@ def _impl(ctx):
160160 strip_action,
161161 ]
162162
163+ # Set LD_LIBRARY_PATH environment variable for all actions
164+ # This is needed by some toolchains since these libraries are not in `rpath` of compiler binary
165+ # which are needed to run it.
166+ compiler_library_search_paths = "%{compiler_library_search_paths}"
167+ compiler_library_search_paths_feature = feature(
168+ name = "compiler_library_search_paths",
169+ enabled = %{compiler_library_search_paths_switch},
170+ env_sets = [
171+ env_set(
172+ actions = all_actions,
173+ env_entries = [
174+ env_entry(key = "LD_LIBRARY_PATH", value = compiler_library_search_paths),
175+ ],
176+ ),
177+ ],
178+ )
179+
163180 unfiltered_compile_flags_feature = feature(
164181 name = "unfiltered_compile_flags",
165182 enabled = True,
@@ -617,6 +634,7 @@ def _impl(ctx):
617634 # after a command line parameter from a feature at the beginning of the list.
618635
619636 features = [
637+ compiler_library_search_paths_feature,
620638 sanitizer_feature,
621639 asan_feature,
622640 lsan_feature,
@@ -657,26 +675,6 @@ def _impl(ctx):
657675 if ctx.attr.sysroot != None:
658676 sysroot = ctx.attr.sysroot[DefaultInfo].files.to_list()[0].path
659677
660- # Get ld_library_paths from attribute if provided and set LD_LIBRARY_PATH environment variable for actions
661- if hasattr(ctx.attr, "ld_library_path_dirs") and ctx.attr.ld_library_path_dirs and ctx.attr.ld_library_path_dirs[DefaultInfo].files.to_list():
662- values = ["/proc/self/cwd/" + entry.path for entry in ctx.attr.ld_library_path_dirs[DefaultInfo].files.to_list()]
663- ld_library_path = ":".join(values)
664-
665- sdk_env_feature = feature(
666- name = "sdk_env",
667- enabled = True,
668- env_sets = [
669- env_set(
670- actions = all_actions,
671- env_entries = [
672- env_entry(key = "LD_LIBRARY_PATH", value = ld_library_path),
673- ],
674- ),
675- ],
676- )
677-
678- features.append(sdk_env_feature)
679-
680678 return cc_common.create_cc_toolchain_config_info(
681679 ctx = ctx,
682680 abi_version = "%{tc_abi_version}",
@@ -709,6 +707,5 @@ cc_toolchain_config = rule(
709707 "host_dir": attr.label(default = None),
710708 "target_dir": attr.label(default = None),
711709 "cxx_builtin_include_directories": attr.label(allow_files = True, default = None),
712- "ld_library_path_dirs": attr.label(allow_files = True, default = None),
713710 },
714711)
0 commit comments