1# Copyright 2024 The Bazel Authors. All rights reserved. 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"""cc_test rule""" 16 17# TODO(bazel-team): To avoid breaking changes, if the below are no longer 18# forwarding to native rules, flag @bazel_tools@bazel_tools//tools/cpp:link_extra_libs 19# should either: (a) alias the flag @rules_cc//:link_extra_libs, or (b) be 20# added as a dependency to @rules_cc//:link_extra_lib. The intermediate library 21# @bazel_tools@bazel_tools//tools/cpp:link_extra_lib should either be added as a dependency 22# to @rules_cc//:link_extra_lib, or removed entirely (if possible). 23_LINK_EXTRA_LIB = Label("//:link_extra_lib") 24 25def cc_test(**attrs): 26 """Bazel cc_test rule. 27 28 https://docs.bazel.build/versions/main/be/c-cpp.html#cc_test 29 30 Args: 31 **attrs: Rule attributes 32 """ 33 34 is_library = "linkshared" in attrs and attrs["linkshared"] 35 36 # Executable builds also include the "link_extra_lib" library. 37 if not is_library: 38 if "deps" in attrs and attrs["deps"] != None: 39 attrs["deps"] = attrs["deps"] + [_LINK_EXTRA_LIB] 40 else: 41 attrs["deps"] = [_LINK_EXTRA_LIB] 42 43 # buildifier: disable=native-cc 44 native.cc_test(**attrs) 45