Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions mojo/private/mojo_binary_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ then be used in copts with the $(location) function.
"_mojo_copts": attr.label(
default = Label("//:mojo_copt"),
),
"_link_extra_lib": attr.label(
default = "@bazel_tools//tools/cpp:link_extra_lib",
providers = [CcInfo],
doc = """\
Pull in extra libraries passed with @bazel_tools//tools/cpp:link_extra_lib.
This is useful for shared sanitizer libraries which need to have rpaths added
by bazel.
""",
),
}

_TOOLCHAINS = use_cpp_toolchain() + [
Expand Down Expand Up @@ -95,7 +104,8 @@ def _mojo_binary_test_implementation(ctx, *, shared_library = False):
if not file.dirname.startswith(root_directory):
args.add("-I", file.dirname)

import_paths, transitive_mojopkgs = collect_mojoinfo(ctx.attr.deps + mojo_toolchain.implicit_deps)
all_deps = ctx.attr.deps + mojo_toolchain.implicit_deps + ([ctx.attr._link_extra_lib] if ctx.attr._link_extra_lib else [])
import_paths, transitive_mojopkgs = collect_mojoinfo(all_deps)
args.add_all(import_paths, before_each = "-I")

# NOTE: Argument order:
Expand Down Expand Up @@ -166,7 +176,7 @@ def _mojo_binary_test_implementation(ctx, *, shared_library = False):
actions = ctx.actions,
feature_configuration = feature_configuration,
cc_toolchain = cc_toolchain,
linking_contexts = [object_linking_context] + [dep[CcInfo].linking_context for dep in (ctx.attr.deps + mojo_toolchain.implicit_deps) if CcInfo in dep],
linking_contexts = [object_linking_context] + [dep[CcInfo].linking_context for dep in all_deps if CcInfo in dep],
name = ctx.label.name,
user_link_flags = ctx.attr.linkopts,
**link_kwargs
Expand All @@ -183,7 +193,7 @@ def _mojo_binary_test_implementation(ctx, *, shared_library = False):
# Collect transitive shared libraries that must exist at runtime
python_imports = []
transitive_libraries = []
for target in ctx.attr.deps + mojo_toolchain.implicit_deps:
for target in all_deps:
transitive_runfiles.append(target[DefaultInfo].default_runfiles)

if PyInfo in target:
Expand Down