1# Copyright 2019 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://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, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14"""Pigweed build environment for bazel.""" 15 16load( 17 "//pw_build/bazel_internal:pigweed_internal.bzl", 18 _add_defaults = "add_defaults", 19) 20 21def pw_cc_binary(**kwargs): 22 """Wrapper for cc_binary providing some defaults. 23 24 Specifically, this wrapper, 25 26 * Adds default copts. 27 * Adds a dep on the pw_assert backend. 28 * Sets "linkstatic" to True. 29 * Disables header modules (via the feature -use_header_modules). 30 31 Args: 32 **kwargs: Passed to cc_binary. 33 """ 34 kwargs["deps"] = kwargs.get("deps", []) 35 36 # TODO(b/234877642): Remove this implicit dependency once we have a better 37 # way to handle the facades without introducing a circular dependency into 38 # the build. 39 kwargs["deps"] = kwargs["deps"] + ["@pigweed_config//:pw_assert_backend"] 40 _add_defaults(kwargs) 41 native.cc_binary(**kwargs) 42 43def pw_cc_library(**kwargs): 44 """Wrapper for cc_library providing some defaults. 45 46 Specifically, this wrapper, 47 48 * Adds default copts. 49 * Sets "linkstatic" to True. 50 * Disables header modules (via the feature -use_header_modules). 51 52 Args: 53 **kwargs: Passed to cc_library. 54 """ 55 _add_defaults(kwargs) 56 native.cc_library(**kwargs) 57 58def pw_cc_test(**kwargs): 59 """Wrapper for cc_test providing some defaults. 60 61 Specifically, this wrapper, 62 63 * Adds default copts. 64 * Adds a dep on the pw_assert backend. 65 * Adds a dep on //pw_unit_test:simple_printing_main 66 * Sets "linkstatic" to True. 67 * Disables header modules (via the feature -use_header_modules). 68 69 Args: 70 **kwargs: Passed to cc_test. 71 """ 72 kwargs["deps"] = kwargs.get("deps", []) + \ 73 ["@pigweed//pw_unit_test:simple_printing_main"] 74 75 # TODO(b/234877642): Remove this implicit dependency once we have a better 76 # way to handle the facades without introducing a circular dependency into 77 # the build. 78 kwargs["deps"] = kwargs["deps"] + ["@pigweed_config//:pw_assert_backend"] 79 _add_defaults(kwargs) 80 native.cc_test(**kwargs) 81 82def pw_cc_perf_test(**kwargs): 83 """A Pigweed performance test. 84 85 This macro produces a cc_binary and, 86 87 * Adds default copts. 88 * Adds a dep on the pw_assert backend. 89 * Adds a dep on //pw_perf_test:logging_main 90 * Sets "linkstatic" to True. 91 * Disables header modules (via the feature -use_header_modules). 92 93 Args: 94 **kwargs: Passed to cc_binary. 95 """ 96 kwargs["deps"] = kwargs.get("deps", []) + \ 97 ["@pigweed//pw_perf_test:logging_main"] 98 kwargs["deps"] = kwargs["deps"] + ["@pigweed_config//:pw_assert_backend"] 99 _add_defaults(kwargs) 100 native.cc_binary(**kwargs) 101 102def pw_cc_facade(**kwargs): 103 # Bazel facades should be source only cc_library's this is to simplify 104 # lazy header evaluation. Bazel headers are not 'precompiled' so the build 105 # system does not check to see if the build has the right dependant headers 106 # in the sandbox. If a source file is declared here and includes a header 107 # file the toolchain will compile as normal and complain about the missing 108 # backend headers. 109 if "srcs" in kwargs.keys(): 110 fail("'srcs' attribute does not exist in pw_cc_facade, please use \ 111 main implementing target.") 112 _add_defaults(kwargs) 113 native.cc_library(**kwargs) 114