Skip to content

Commit

Permalink
tests: test that .dwp targets can be built
Browse files Browse the repository at this point in the history
This has some things we'll eventually want to remove; see bazel-contrib#109 for some context.
  • Loading branch information
rrbutani committed Sep 28, 2021
1 parent 7837555 commit 259a328
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load(":transitions.bzl", "dwp_file")

cc_library(
name = "stdlib",
Expand Down Expand Up @@ -46,6 +47,32 @@ build_test(
]
)

# We want to test that `llvm-dwp` (used when assembling a `.dwp` file from
# `.dwo` files) can be called.
#
# `--fission=yes` enables this for all compilation modes but we also need to
# enable the `per_object_debug_info` feature manually because
# `unix_cc_toolchain_config.bzl`'s` `cc_toolchain_config` does not (see #109).
#
# This is what `dwp_file` does using a transition.
#
# Unfortunately `per_object_debug_info` breaks on macOS which is why this
# target is marked as only being compatible with Linux (see #109).
dwp_file(
name = "stdlib.dwp",
src = ":stdlib_bin",
target_compatible_with = [
"@platforms//os:linux",
],
)

build_test(
name = "dwp_test",
targets = [
":stdlib.dwp",
],
)

cc_test(
name = "pthread_link_test",
srcs = ["pthread_link_test.cc"],
Expand Down
58 changes: 58 additions & 0 deletions tests/transitions.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""Helper transitions for tests."""

def _fission_transition_impl(settings, attr):
features = settings["//command_line_option:features"]
if "per_object_debug_info" in features:
features.remove("per_object_debug_info")

enable_per_object_debug_info = attr.per_object_debug_info
if enable_per_object_debug_info:
features.append("per_object_debug_info")

return {
"//command_line_option:fission": attr.fission,
"//command_line_option:features": features,
}

fission_transition = transition(
implementation = _fission_transition_impl,
inputs = ["//command_line_option:features"],
outputs = [
"//command_line_option:features",
"//command_line_option:fission",
],
)

def _dwp_file_impl(ctx):
file = ctx.attr.name
file = ctx.actions.declare_file(file)
ctx.actions.symlink(
output = file,
target_file = ctx.attr.src[0][DebugPackageInfo].dwp_file,
)

return [DefaultInfo(files = depset([file]))]

dwp_file = rule(
implementation = _dwp_file_impl,
attrs = {
"src": attr.label(
cfg = fission_transition,
mandatory = True,
doc = "The actual target to build and grab the .dwp file from.",
providers = [DebugPackageInfo],
),
# NOTE: we should eventually be able to remove this (see #109).
"per_object_debug_info": attr.bool(
default = True,
),
"fission": attr.string(
default = "yes",
values = ["yes", "no", "dbg", "fastbuild", "opt"],
),
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist"
),
},
incompatible_use_toolchain_transition = True,
)

0 comments on commit 259a328

Please sign in to comment.