• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2020 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
15import("//build_overrides/pigweed.gni")
16
17import("$dir_pw_toolchain/clang_tools.gni")
18
19declare_args() {
20  # Sets the sanitizer to pass to clang. Valid values are "address", "memory",
21  # "thread", "undefined".
22  pw_toolchain_SANITIZERS = []
23
24  # Indicates if this build is a part of OSS-Fuzz, which needs to be able to
25  # provide its own compiler and flags. This violates the build hermeticisim and
26  # should only be used for OSS-Fuzz.
27  pw_toolchain_OSS_FUZZ_ENABLED = false
28}
29
30# Specifies the tools used by host Clang toolchains.
31_host_clang_toolchain = {
32  if (pw_toolchain_OSS_FUZZ_ENABLED) {
33    # Just use the "llvm-ar" on the system path.
34    ar = "llvm-ar"
35    cc = getenv("CC")
36    cxx = getenv("CXX")
37  } else {
38    forward_variables_from(pw_toolchain_clang_tools, "*")
39  }
40
41  is_host_toolchain = true
42
43  # Enable static analysis for host clang based toolchains,
44  # even with OSS-Fuzz enabled.
45  static_analysis = true
46}
47
48# Common default scope shared by all host Clang toolchains.
49_defaults = {
50  # TODO(pwbug/461) amend toolchain declaration process to
51  # remove this hack.
52  default_configs = []
53  default_configs = [
54    "$dir_pw_build:extra_debugging",
55    "$dir_pw_toolchain/host_clang:no_system_libcpp",
56    "$dir_pw_toolchain/host_clang:xcode_sysroot",
57  ]
58}
59
60pw_toolchain_host_clang = {
61  debug = {
62    name = "host_clang_debug"
63    forward_variables_from(_host_clang_toolchain, "*")
64    defaults = {
65      forward_variables_from(_defaults, "*")
66      default_configs += [ "$dir_pw_build:optimize_debugging" ]
67      foreach(sanitizer, pw_toolchain_SANITIZERS) {
68        default_configs +=
69            [ "$dir_pw_toolchain/host_clang:sanitize_$sanitizer" ]
70      }
71    }
72  }
73
74  speed_optimized = {
75    name = "host_clang_speed_optimized"
76    forward_variables_from(_host_clang_toolchain, "*")
77    defaults = {
78      forward_variables_from(_defaults, "*")
79      default_configs += [ "$dir_pw_build:optimize_speed" ]
80      foreach(sanitizer, pw_toolchain_SANITIZERS) {
81        default_configs +=
82            [ "$dir_pw_toolchain/host_clang:sanitize_$sanitizer" ]
83      }
84    }
85  }
86
87  size_optimized = {
88    name = "host_clang_size_optimized"
89    forward_variables_from(_host_clang_toolchain, "*")
90    defaults = {
91      forward_variables_from(_defaults, "*")
92      default_configs += [ "$dir_pw_build:optimize_size" ]
93      foreach(sanitizer, pw_toolchain_SANITIZERS) {
94        default_configs +=
95            [ "$dir_pw_toolchain/host_clang:sanitize_$sanitizer" ]
96      }
97    }
98  }
99
100  fuzz = {
101    name = "host_clang_fuzz"
102    forward_variables_from(_host_clang_toolchain, "*")
103    defaults = {
104      forward_variables_from(_defaults, "*")
105
106      # Fuzz faster.
107      default_configs += [ "$dir_pw_build:optimize_speed" ]
108
109      if (pw_toolchain_SANITIZERS == []) {
110        # Default to ASan for fuzzing, which is what we typically care about.
111        pw_toolchain_SANITIZERS = [ "address" ]
112      }
113      foreach(sanitizer, pw_toolchain_SANITIZERS) {
114        default_configs +=
115            [ "$dir_pw_toolchain/host_clang:sanitize_$sanitizer" ]
116      }
117
118      if (pw_toolchain_OSS_FUZZ_ENABLED) {
119        default_configs += [ "$dir_pw_fuzzer:oss_fuzz_extra" ]
120      }
121    }
122  }
123
124  asan = {
125    name = "host_clang_asan"
126    forward_variables_from(_host_clang_toolchain, "*")
127    defaults = {
128      forward_variables_from(_defaults, "*")
129
130      # Use debug mode to get proper debug information.
131      default_configs += [ "$dir_pw_build:optimize_debugging" ]
132      default_configs += [ "$dir_pw_toolchain/host_clang:sanitize_address" ]
133    }
134  }
135
136  ubsan = {
137    name = "host_clang_ubsan"
138    forward_variables_from(_host_clang_toolchain, "*")
139    defaults = {
140      forward_variables_from(_defaults, "*")
141
142      # Use debug mode to get proper debug information.
143      default_configs += [ "$dir_pw_build:optimize_debugging" ]
144      default_configs += [ "$dir_pw_toolchain/host_clang:sanitize_undefined" ]
145    }
146  }
147
148  ubsan_heuristic = {
149    name = "host_clang_ubsan_heuristic"
150    forward_variables_from(_host_clang_toolchain, "*")
151    defaults = {
152      forward_variables_from(_defaults, "*")
153
154      # Use debug mode to get proper debug information.
155      default_configs += [ "$dir_pw_build:optimize_debugging" ]
156      default_configs +=
157          [ "$dir_pw_toolchain/host_clang:sanitize_undefined_heuristic" ]
158    }
159  }
160
161  msan = {
162    name = "host_clang_msan"
163    forward_variables_from(_host_clang_toolchain, "*")
164    defaults = {
165      forward_variables_from(_defaults, "*")
166
167      # Use debug mode to get proper debug information.
168      default_configs += [ "$dir_pw_build:optimize_debugging" ]
169      default_configs += [ "$dir_pw_toolchain/host_clang:sanitize_memory" ]
170    }
171  }
172
173  tsan = {
174    name = "host_clang_tsan"
175    forward_variables_from(_host_clang_toolchain, "*")
176    defaults = {
177      forward_variables_from(_defaults, "*")
178
179      # Use debug mode to get proper debug information.
180      default_configs += [ "$dir_pw_build:optimize_debugging" ]
181      default_configs += [ "$dir_pw_toolchain/host_clang:sanitize_thread" ]
182    }
183  }
184}
185
186# Describes host clang toolchains.
187pw_toolchain_host_clang_list = [
188  pw_toolchain_host_clang.debug,
189  pw_toolchain_host_clang.speed_optimized,
190  pw_toolchain_host_clang.size_optimized,
191  pw_toolchain_host_clang.fuzz,
192  pw_toolchain_host_clang.asan,
193  pw_toolchain_host_clang.ubsan,
194  pw_toolchain_host_clang.ubsan_heuristic,
195  pw_toolchain_host_clang.msan,
196  pw_toolchain_host_clang.tsan,
197]
198