• 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_build/defaults.gni")
18import("$dir_pw_toolchain/clang_tools.gni")
19
20declare_args() {
21  # Sets the sanitizer to pass to clang. Valid values are "address", "memory",
22  # "thread", "undefined", "undefined_heuristic".
23  pw_toolchain_SANITIZERS = []
24
25  # Indicates if this toolchain supports generating coverage reports from
26  # pw_test targets.
27  #
28  # For example, the static analysis toolchains that run `clang-tidy` instead
29  # of the test binary itself cannot generate coverage reports.
30  #
31  # This is typically set by individual toolchains and not by GN args.
32  pw_toolchain_COVERAGE_ENABLED = false
33
34  # List of source files to selectively collect coverage.
35  pw_toolchain_PROFILE_SOURCE_FILES = []
36
37  # Indicates if this toolchain supports building fuzzers. This is typically
38  # set by individual toolchains and not by GN args.
39  pw_toolchain_FUZZING_ENABLED = false
40
41  # Indicates if this build is a part of OSS-Fuzz, which needs to be able to
42  # provide its own compiler and flags. This violates the build hermeticisim and
43  # should only be used for OSS-Fuzz.
44  pw_toolchain_OSS_FUZZ_ENABLED = false
45}
46
47# Specifies the tools used by host Clang toolchains.
48_host_clang_toolchain = {
49  forward_variables_from(pw_toolchain_clang_tools, "*")
50  is_host_toolchain = true
51  static_analysis = {
52    # Enable static analysis for host clang based toolchains.
53    enabled = true
54  }
55}
56
57# Common default scope shared by all host Clang toolchains.
58_defaults = {
59  # TODO: b/234888755 - amend toolchain declaration process to
60  # remove this hack.
61  default_configs = []
62  default_configs = pigweed_default_configs + [
63                      "$dir_pw_build:extra_debugging",
64                      "$dir_pw_toolchain/host_clang:no_system_libcpp",
65                      "$dir_pw_toolchain/host_clang:xcode_sysroot",
66                      "$dir_pw_toolchain/host_clang:no_ms_compatibility",
67                    ]
68
69  # OSS-Fuzz uses -stdlib=libc++, which isn't included in the CIPD-provided
70  # Linux sysroot (it instead provides libstdc++).
71  if (!pw_toolchain_OSS_FUZZ_ENABLED) {
72    default_configs += [ "$dir_pw_toolchain/host_clang:linux_sysroot" ]
73  }
74
75  pw_build_LINK_DEPS = [ dir_pw_libc ]
76}
77
78pw_toolchain_host_clang = {
79  debug = {
80    name = "host_clang_debug"
81    forward_variables_from(_host_clang_toolchain, "*")
82    defaults = {
83      forward_variables_from(_defaults, "*")
84      default_configs += [ "$dir_pw_build:optimize_debugging" ]
85      foreach(sanitizer, pw_toolchain_SANITIZERS) {
86        default_configs +=
87            [ "$dir_pw_toolchain/host_clang:sanitize_$sanitizer" ]
88      }
89    }
90  }
91
92  speed_optimized = {
93    name = "host_clang_speed_optimized"
94    forward_variables_from(_host_clang_toolchain, "*")
95    defaults = {
96      forward_variables_from(_defaults, "*")
97      default_configs += [ "$dir_pw_build:optimize_speed" ]
98      foreach(sanitizer, pw_toolchain_SANITIZERS) {
99        default_configs +=
100            [ "$dir_pw_toolchain/host_clang:sanitize_$sanitizer" ]
101      }
102    }
103  }
104
105  size_optimized = {
106    name = "host_clang_size_optimized"
107    forward_variables_from(_host_clang_toolchain, "*")
108    defaults = {
109      forward_variables_from(_defaults, "*")
110      default_configs += [ "$dir_pw_build:optimize_size_clang" ]
111      foreach(sanitizer, pw_toolchain_SANITIZERS) {
112        default_configs +=
113            [ "$dir_pw_toolchain/host_clang:sanitize_$sanitizer" ]
114      }
115    }
116  }
117
118  fuzz = {
119    name = "host_clang_fuzz"
120    cc = ""
121    cxx = ""
122    forward_variables_from(_host_clang_toolchain,
123                           "*",
124                           [
125                             "cc",
126                             "cxx",
127                           ])
128
129    # OSS-Fuzz sets compiler paths. See
130    # google.github.io/oss-fuzz/getting-started/new-project-guide/#Requirements.
131    if (pw_toolchain_OSS_FUZZ_ENABLED) {
132      cc = getenv("CC")
133      cxx = getenv("CXX")
134    }
135    if (cc == "") {
136      cc = _host_clang_toolchain.cc
137    }
138    if (cxx == "") {
139      cxx = _host_clang_toolchain.cxx
140    }
141    defaults = {
142      forward_variables_from(_defaults, "*")
143
144      pw_toolchain_FUZZING_ENABLED = true
145      if (pw_toolchain_OSS_FUZZ_ENABLED) {
146        default_configs += [ "$dir_pw_fuzzer:oss_fuzz_instrumentation" ]
147      } else {
148        default_configs += [ "$dir_pw_fuzzer:instrumentation" ]
149      }
150
151      # Fuzz faster.
152      default_configs += [ "$dir_pw_build:optimize_speed" ]
153
154      # Default to ASan for fuzzing, which is what we typically care about.
155      if (pw_toolchain_SANITIZERS == []) {
156        pw_toolchain_SANITIZERS = [ "address" ]
157      }
158      foreach(sanitizer, pw_toolchain_SANITIZERS) {
159        default_configs +=
160            [ "$dir_pw_toolchain/host_clang:sanitize_$sanitizer" ]
161      }
162    }
163  }
164
165  asan = {
166    name = "host_clang_asan"
167    forward_variables_from(_host_clang_toolchain, "*")
168    defaults = {
169      forward_variables_from(_defaults, "*")
170
171      # Use debug mode to get proper debug information.
172      default_configs += [ "$dir_pw_build:optimize_debugging" ]
173      default_configs += [ "$dir_pw_toolchain/host_clang:sanitize_address" ]
174    }
175  }
176
177  ubsan = {
178    name = "host_clang_ubsan"
179    forward_variables_from(_host_clang_toolchain, "*")
180    defaults = {
181      forward_variables_from(_defaults, "*")
182
183      # Use debug mode to get proper debug information.
184      default_configs += [ "$dir_pw_build:optimize_debugging" ]
185      default_configs += [ "$dir_pw_toolchain/host_clang:sanitize_undefined" ]
186    }
187  }
188
189  ubsan_heuristic = {
190    name = "host_clang_ubsan_heuristic"
191    forward_variables_from(_host_clang_toolchain, "*")
192    defaults = {
193      forward_variables_from(_defaults, "*")
194
195      # Use debug mode to get proper debug information.
196      default_configs += [ "$dir_pw_build:optimize_debugging" ]
197      default_configs +=
198          [ "$dir_pw_toolchain/host_clang:sanitize_undefined_heuristic" ]
199    }
200  }
201
202  msan = {
203    name = "host_clang_msan"
204    forward_variables_from(_host_clang_toolchain, "*")
205    defaults = {
206      forward_variables_from(_defaults, "*")
207
208      # Use debug mode to get proper debug information.
209      default_configs += [ "$dir_pw_build:optimize_debugging" ]
210      default_configs += [ "$dir_pw_toolchain/host_clang:sanitize_memory" ]
211    }
212  }
213
214  tsan = {
215    name = "host_clang_tsan"
216    forward_variables_from(_host_clang_toolchain, "*")
217    defaults = {
218      forward_variables_from(_defaults, "*")
219
220      # Use debug mode to get proper debug information.
221      default_configs += [ "$dir_pw_build:optimize_debugging" ]
222      default_configs += [ "$dir_pw_toolchain/host_clang:sanitize_thread" ]
223    }
224  }
225
226  coverage = {
227    name = "host_clang_coverage"
228    forward_variables_from(_host_clang_toolchain, "*")
229    defaults = {
230      forward_variables_from(_defaults, "*")
231
232      # Use debug mode to get proper debug information.
233      default_configs += [ "$dir_pw_build:optimize_debugging" ]
234      default_configs += [ "$dir_pw_toolchain/host_clang:coverage" ]
235
236      # Enable PW toolchain arguments for coverage. This will only apply to
237      # binaries built using this toolchain.
238      pw_toolchain_COVERAGE_ENABLED = true
239    }
240  }
241}
242
243# Describes host clang toolchains.
244pw_toolchain_host_clang_list = [
245  pw_toolchain_host_clang.debug,
246  pw_toolchain_host_clang.speed_optimized,
247  pw_toolchain_host_clang.size_optimized,
248  pw_toolchain_host_clang.fuzz,
249  pw_toolchain_host_clang.asan,
250  pw_toolchain_host_clang.ubsan,
251  pw_toolchain_host_clang.ubsan_heuristic,
252  pw_toolchain_host_clang.msan,
253  pw_toolchain_host_clang.tsan,
254  pw_toolchain_host_clang.coverage,
255]
256