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_cc_and_c_targets = "add_cc_and_c_targets", 19 _has_pw_assert_dep = "has_pw_assert_dep", 20) 21 22def pw_cc_binary(**kwargs): 23 kwargs["deps"] = kwargs.get("deps", []) 24 25 # TODO(pwbug/440): Remove this implicit dependency once we have a better 26 # way to handle the facades without introducing a circular dependency into 27 # the build. 28 if not _has_pw_assert_dep(kwargs["deps"]): 29 kwargs["deps"].append("@pigweed//pw_assert") 30 _add_cc_and_c_targets(native.cc_binary, kwargs) 31 32def pw_cc_library(**kwargs): 33 _add_cc_and_c_targets(native.cc_library, kwargs) 34 35def pw_cc_test(**kwargs): 36 kwargs["deps"] = kwargs.get("deps", []) + \ 37 ["//pw_unit_test:main"] 38 39 # TODO(pwbug/440): Remove this implicit dependency once we have a better 40 # way to handle the facades without introducing a circular dependency into 41 # the build. 42 if not _has_pw_assert_dep(kwargs["deps"]): 43 kwargs["deps"].append("@pigweed//pw_assert") 44 _add_cc_and_c_targets(native.cc_test, kwargs) 45 46def pw_cc_facade(**kwargs): 47 # Bazel facades should be source only cc_library's this is to simplify 48 # lazy header evaluation. Bazel headers are not 'precompiled' so the build 49 # system does not check to see if the build has the right dependant headers 50 # in the sandbox. If a source file is declared here and includes a header 51 # file the toolchain will compile as normal and complain about the missing 52 # backend headers. 53 if "srcs" in kwargs.keys(): 54 fail("'srcs' attribute does not exist in pw_cc_facade, please use \ 55 main implementing target.") 56 _add_cc_and_c_targets(native.cc_library, kwargs) 57