• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2023 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
15load(
16    "//cc_toolchain:defs.bzl",
17    "pw_cc_flag_set",
18)
19
20package(default_visibility = ["//visibility:public"])
21
22licenses(["notice"])
23
24# Optimization level option
25pw_cc_flag_set(
26    name = "o2",
27    actions = [
28        "@pw_toolchain//actions:all_c_compiler_actions",
29        "@pw_toolchain//actions:all_cpp_compiler_actions",
30        "@pw_toolchain//actions:all_link_actions",
31    ],
32    flags = ["-O2"],
33)
34
35# Prevent relative paths from being converted to absolute paths.
36pw_cc_flag_set(
37    name = "no_canonical_prefixes",
38    actions = [
39        "@pw_toolchain//actions:all_c_compiler_actions",
40        "@pw_toolchain//actions:all_cpp_compiler_actions",
41    ],
42    flags = ["-no-canonical-prefixes"],
43)
44
45# Compile without runtime type information (RTTI). This produces smaller binaries.
46pw_cc_flag_set(
47    name = "no_rtti",
48    actions = ["@pw_toolchain//actions:all_cpp_compiler_actions"],
49    flags = ["-fno-rtti"],
50)
51
52# Allow uses of the register keyword, which may appear in C headers.
53pw_cc_flag_set(
54    name = "wno_register",
55    actions = ["@pw_toolchain//actions:all_cpp_compiler_actions"],
56    flags = ["-Wno-register"],
57)
58
59# Compile for the C++17 standard.
60pw_cc_flag_set(
61    name = "c++17",
62    actions = [
63        "@pw_toolchain//actions:all_cpp_compiler_actions",
64        "@pw_toolchain//actions:all_link_actions",
65    ],
66    flags = ["-std=c++17"],
67)
68
69# Issue a warning when a class appears to be polymorphic, yet it declares a
70# non-virtual destructor
71pw_cc_flag_set(
72    name = "wnon_virtual_dtor",
73    actions = ["@pw_toolchain//actions:all_cpp_compiler_actions"],
74    flags = ["-Wnon-virtual-dtor"],
75)
76
77# Standard compiler flags to reduce output binary size.
78pw_cc_flag_set(
79    name = "reduced_size",
80    actions = [
81        "@pw_toolchain//actions:all_c_compiler_actions",
82        "@pw_toolchain//actions:all_cpp_compiler_actions",
83    ],
84    flags = [
85        "-fno-common",
86        "-fno-exceptions",
87        "-ffunction-sections",
88        "-fdata-sections",
89    ],
90)
91
92pw_cc_flag_set(
93    name = "debugging",
94    actions = [
95        "@pw_toolchain//actions:all_c_compiler_actions",
96        "@pw_toolchain//actions:all_cpp_compiler_actions",
97    ],
98    flags = ["-g"],
99)
100
101pw_cc_flag_set(
102    name = "asan",
103    actions = [
104        "@pw_toolchain//actions:all_compiler_actions",
105        "@pw_toolchain//actions:all_link_actions",
106    ],
107    flags = [
108        "-fsanitize=address",
109        "-DADDRESS_SANITIZER",
110    ],
111)
112