blob: 4749390939346a081499fa28234520132994114d [file] [log] [blame]
Rob Mohrbe98ead2019-11-14 07:16:40 -08001# 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
Rob Mohraf7bd882019-11-19 09:48:23 -080015"""Pigweed build environment for bazel."""
16
Rob Mohrc70366e2019-11-18 11:09:39 -080017# Standard compiler flags to reduce output binary size.
18REDUCED_SIZE_COPTS = [
19 "-fno-common",
20 "-fno-exceptions",
21 "-ffunction-sections",
22 "-fdata-sections",
23 "-fno-rtti",
24]
Rob Mohrbe98ead2019-11-14 07:16:40 -080025
Rob Mohrc70366e2019-11-18 11:09:39 -080026STRICT_WARNINGS_COPTS = [
27 "-Wall",
28 "-Wextra",
Rob Mohre6cbdf82019-11-18 14:37:48 -080029 "-Wnon-virtual-dtor",
Rob Mohrc70366e2019-11-18 11:09:39 -080030 # Make all warnings errors, except for the exemptions below.
31 "-Werror",
32 "-Wno-error=cpp", # preprocessor #warning statement
33 "-Wno-error=deprecated-declarations", # [[deprecated]] attribute
34]
Rob Mohrbe98ead2019-11-14 07:16:40 -080035
Rob Mohrc70366e2019-11-18 11:09:39 -080036CPP17_COPTS = [
37 "-std=c++17",
38 # Allow uses of the register keyword, which may appear in C headers.
39 "-Wno-register",
40]
Rob Mohrbe98ead2019-11-14 07:16:40 -080041
Rob Mohrc70366e2019-11-18 11:09:39 -080042INCLUDES_COPTS = [
Rob Mohrea9a66b2019-11-26 13:56:36 -080043 "-Ipw_bloat/public",
Rob Mohr57211c22019-11-18 15:26:35 -080044 "-Ipw_dumb_io/public",
Rob Mohrc70366e2019-11-18 11:09:39 -080045 "-Ipw_preprocessor/public",
46 "-Ipw_span/public",
47 "-Ipw_status/public",
48 "-Ipw_string/public",
49 "-Ipw_unit_test/public",
Rob Mohr3895a122019-12-02 11:49:18 -080050 "-Ipw_varint/public",
Rob Mohrc70366e2019-11-18 11:09:39 -080051]
Rob Mohrbe98ead2019-11-14 07:16:40 -080052
Rob Mohrc70366e2019-11-18 11:09:39 -080053PW_DEFAULT_COPTS = (
54 REDUCED_SIZE_COPTS +
55 STRICT_WARNINGS_COPTS +
56 CPP17_COPTS +
57 INCLUDES_COPTS
58)
Rob Mohrbe98ead2019-11-14 07:16:40 -080059
Rob Mohrc70366e2019-11-18 11:09:39 -080060PW_DEFAULT_LINKOPTS = []
Rob Mohrbe98ead2019-11-14 07:16:40 -080061
Rob Mohrc70366e2019-11-18 11:09:39 -080062def _add_defaults(kwargs):
63 kwargs.setdefault("copts", [])
Rob Mohr05b0b112019-12-03 09:57:38 -080064 kwargs["copts"] = PW_DEFAULT_COPTS + kwargs["copts"]
Rob Mohrdf2b13b2019-11-18 14:04:25 -080065
Rob Mohrc70366e2019-11-18 11:09:39 -080066 kwargs.setdefault("linkopts", [])
Rob Mohr05b0b112019-12-03 09:57:38 -080067 kwargs["linkopts"] = PW_DEFAULT_LINKOPTS + kwargs["linkopts"]
Rob Mohrbe98ead2019-11-14 07:16:40 -080068
Rob Mohrdf2b13b2019-11-18 14:04:25 -080069 kwargs.setdefault("features", [])
70
71 # Crosstool--adding this line to features disables header modules, which
72 # don't work with -fno-rtti. Note: this is not a command-line argument,
73 # it's "minus use_header_modules".
74 kwargs["features"].append("-use_header_modules")
75
Rob Mohrc70366e2019-11-18 11:09:39 -080076def pw_cc_binary(**kwargs):
77 _add_defaults(kwargs)
78 native.cc_binary(**kwargs)
Rob Mohrbe98ead2019-11-14 07:16:40 -080079
Rob Mohrc70366e2019-11-18 11:09:39 -080080def pw_cc_library(**kwargs):
81 _add_defaults(kwargs)
82 native.cc_library(**kwargs)
Rob Mohrbe98ead2019-11-14 07:16:40 -080083
Rob Mohrc70366e2019-11-18 11:09:39 -080084def pw_cc_test(**kwargs):
85 _add_defaults(kwargs)
86 kwargs.setdefault("deps", [])
87 kwargs["deps"].append("//pw_unit_test:main")
88 native.cc_test(**kwargs)