@@ -160,6 +160,21 @@ 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 = [env_entry(key = "LD_LIBRARY_PATH", value = compiler_library_search_paths)] if compiler_library_search_paths != "" else [],
174+ ),
175+ ],
176+ )
177+
163178 unfiltered_compile_flags_feature = feature(
164179 name = "unfiltered_compile_flags",
165180 enabled = True,
@@ -617,6 +632,7 @@ def _impl(ctx):
617632 # after a command line parameter from a feature at the beginning of the list.
618633
619634 features = [
635+ compiler_library_search_paths_feature,
620636 sanitizer_feature,
621637 asan_feature,
622638 lsan_feature,
@@ -657,26 +673,6 @@ def _impl(ctx):
657673 if ctx.attr.sysroot != None:
658674 sysroot = ctx.attr.sysroot[DefaultInfo].files.to_list()[0].path
659675
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-
680676 return cc_common.create_cc_toolchain_config_info(
681677 ctx = ctx,
682678 abi_version = "%{tc_abi_version}",
@@ -709,6 +705,5 @@ cc_toolchain_config = rule(
709705 "host_dir": attr.label(default = None),
710706 "target_dir": attr.label(default = None),
711707 "cxx_builtin_include_directories": attr.label(allow_files = True, default = None),
712- "ld_library_path_dirs": attr.label(allow_files = True, default = None),
713708 },
714709)
0 commit comments