From 259a328a45ee7b431ed5e2fe20b935456fa52285 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Mon, 27 Sep 2021 23:10:24 -0500 Subject: [PATCH] tests: test that `.dwp` targets can be built This has some things we'll eventually want to remove; see #109 for some context. --- tests/BUILD.bazel | 27 ++++++++++++++++++++ tests/transitions.bzl | 58 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 tests/transitions.bzl diff --git a/tests/BUILD.bazel b/tests/BUILD.bazel index c5e133ad..5940f777 100644 --- a/tests/BUILD.bazel +++ b/tests/BUILD.bazel @@ -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", @@ -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"], diff --git a/tests/transitions.bzl b/tests/transitions.bzl new file mode 100644 index 00000000..e1b34109 --- /dev/null +++ b/tests/transitions.bzl @@ -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, +)