Brian Silverman | 7d89e28 | 2021-11-17 17:36:54 -0800 | [diff] [blame] | 1 | # Copyright 2018 The Bazel Authors. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | load("@bazel_skylib//rules:build_test.bzl", "build_test") |
| 16 | load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") |
| 17 | load(":transitions.bzl", "dwp_file") |
| 18 | |
| 19 | cc_library( |
| 20 | name = "stdlib", |
| 21 | srcs = ["stdlib.cc"], |
| 22 | hdrs = ["stdlib.h"], |
| 23 | ) |
| 24 | |
| 25 | # We want to emulate the behavior of cc_binary but be able to run the target as |
| 26 | # a test, so we use a cc_test target with linkstatic. |
| 27 | cc_test( |
| 28 | name = "stdlib_test", |
| 29 | srcs = ["stdlib_test.cc"], |
| 30 | linkstatic = True, |
| 31 | deps = [":stdlib"], |
| 32 | ) |
| 33 | |
| 34 | # We want to test a `.stripped` target to make sure `llvm-strip` can be called. |
| 35 | # |
| 36 | # For this we need `cc_binary`; `cc_test` does not create `.stripped` targets. |
| 37 | cc_binary( |
| 38 | name = "stdlib_bin", |
| 39 | srcs = ["stdlib_test.cc"], |
| 40 | deps = [":stdlib"], |
| 41 | ) |
| 42 | |
| 43 | build_test( |
| 44 | name = "stripped_binary_test", |
| 45 | targets = [ |
| 46 | ":stdlib_bin.stripped", |
| 47 | ], |
| 48 | ) |
| 49 | |
| 50 | # We want to test that `llvm-dwp` (used when assembling a `.dwp` file from |
| 51 | # `.dwo` files) can be called. |
| 52 | # |
| 53 | # `--fission=yes` enables this for all compilation modes but we also need to |
| 54 | # enable the `per_object_debug_info` feature manually because |
| 55 | # `unix_cc_toolchain_config.bzl`'s` `cc_toolchain_config` does not (see #109). |
| 56 | # |
| 57 | # Additionally, newer versions of clang (12+) require a non-zero `-g` setting to |
| 58 | # actually produce the `.dwo` files in addition to the `-gsplit-dwarf` flag. The |
| 59 | # feature in `unix_cc_toolchain_config.bzl` should be updated to reflect this |
| 60 | # and pass in an appropriate `-g` flag. |
| 61 | # |
| 62 | # bazelbuild/rules_cc#115 is a patch that does this |
| 63 | # (https://github.com/bazelbuild/rules_cc/pull/115). |
| 64 | # |
| 65 | # bazelbuild/bazel#14028 tracks this |
| 66 | # (https://github.com/bazelbuild/bazel/issues/14038). |
| 67 | # |
| 68 | # #109 in this repo and this comment |
| 69 | # (https://github.com/grailbio/bazel-toolchain/pull/108#issuecomment-928839768) |
| 70 | # have some additional details. |
| 71 | # |
| 72 | # For now, we'll specify `-c dbg` when building `.dwo` and `.dwp` files. |
| 73 | # |
| 74 | # This (setting the fission flag, enabling the `per_object_debug_info` feature, |
| 75 | # and setting the compilation mode to `dbg`) is what `dwp_file` does using a |
| 76 | # transition. |
| 77 | # |
| 78 | # Unfortunately `per_object_debug_info` breaks on macOS which is why this target |
| 79 | # is marked as only being compatible with Linux (see #109). |
| 80 | dwp_file( |
| 81 | name = "stdlib.dwp", |
| 82 | src = ":stdlib_bin", |
| 83 | # NOTE: we should eventually we able to drop this; see #109. |
| 84 | override_compilation_mode = "dbg", |
| 85 | target_compatible_with = [ |
| 86 | "@platforms//os:linux", |
| 87 | ], |
| 88 | ) |
| 89 | |
| 90 | build_test( |
| 91 | name = "dwp_test", |
| 92 | targets = [ |
| 93 | ":stdlib.dwp", |
| 94 | ], |
| 95 | ) |
| 96 | |
| 97 | cc_test( |
| 98 | name = "pthread_link_test", |
| 99 | srcs = ["pthread_link_test.cc"], |
| 100 | linkstatic = False, |
| 101 | ) |
| 102 | |
| 103 | sh_test( |
| 104 | name = "file_dependency_test", |
| 105 | srcs = ["file_dependency_test.sh"], |
| 106 | data = [ |
| 107 | "@llvm_toolchain_llvm//:bin/clang-format", |
| 108 | "@llvm_toolchain_llvm//:lib/libc++.a", |
| 109 | ], |
| 110 | ) |