@@ -41,6 +41,15 @@ then be used in copts with the $(location) function.
4141 "_mojo_copts" : attr .label (
4242 default = Label ("//:mojo_copt" ),
4343 ),
44+ "_link_extra_lib" : attr .label (
45+ default = "@bazel_tools//tools/cpp:link_extra_lib" ,
46+ providers = [CcInfo ],
47+ doc = """\
48+ Pull in extra libraries passed with @bazel_tools//tools/cpp:link_extra_lib.
49+ This is useful for shared sanitizer libraries which need to have rpaths added
50+ by bazel.
51+ """ ,
52+ ),
4453}
4554
4655_TOOLCHAINS = use_cpp_toolchain () + [
@@ -95,7 +104,8 @@ def _mojo_binary_test_implementation(ctx, *, shared_library = False):
95104 if not file .dirname .startswith (root_directory ):
96105 args .add ("-I" , file .dirname )
97106
98- import_paths , transitive_mojopkgs = collect_mojoinfo (ctx .attr .deps + mojo_toolchain .implicit_deps )
107+ all_deps = ctx .attr .deps + mojo_toolchain .implicit_deps + ([ctx .attr ._link_extra_lib ] if ctx .attr ._link_extra_lib else [])
108+ import_paths , transitive_mojopkgs = collect_mojoinfo (all_deps )
99109 args .add_all (import_paths , before_each = "-I" )
100110
101111 # NOTE: Argument order:
@@ -166,7 +176,7 @@ def _mojo_binary_test_implementation(ctx, *, shared_library = False):
166176 actions = ctx .actions ,
167177 feature_configuration = feature_configuration ,
168178 cc_toolchain = cc_toolchain ,
169- linking_contexts = [object_linking_context ] + [dep [CcInfo ].linking_context for dep in ( ctx . attr . deps + mojo_toolchain . implicit_deps ) if CcInfo in dep ],
179+ linking_contexts = [object_linking_context ] + [dep [CcInfo ].linking_context for dep in all_deps if CcInfo in dep ],
170180 name = ctx .label .name ,
171181 user_link_flags = ctx .attr .linkopts ,
172182 ** link_kwargs
@@ -183,7 +193,7 @@ def _mojo_binary_test_implementation(ctx, *, shared_library = False):
183193 # Collect transitive shared libraries that must exist at runtime
184194 python_imports = []
185195 transitive_libraries = []
186- for target in ctx . attr . deps + mojo_toolchain . implicit_deps :
196+ for target in all_deps :
187197 transitive_runfiles .append (target [DefaultInfo ].default_runfiles )
188198
189199 if PyInfo in target :
0 commit comments