File: BUILD.gn

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (335 lines) | stat: -rw-r--r-- 10,271 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# Copyright 2013 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/pch.gni")
import("//build/config/rust.gni")
import("clang.gni")

declare_args() {
  # Whether to use Clang runtime libraries from the ChromeOS chroot.
  # This should be true iff using the compiler from the chroot.
  use_cros_sysroot_libs =
      is_chromeos_device && current_toolchain == default_toolchain
}

if (is_ios) {
  # For `target_environment` and `target_platform`.
  import("//build/config/apple/mobile_config.gni")
}

if (use_cros_sysroot_libs) {
  import("//build/toolchain/cros_toolchain.gni")  # For `cros_target_cc`
}

# Helper function for adding cflags to use a clang plugin.
# - `plugin` is the name of the plugin.
# - `plugin_arguments` is a list of arguments to pass to the plugin.
template("clang_plugin") {
  config(target_name) {
    forward_variables_from(invoker,
                           [
                             "cflags",
                             "configs",
                           ])
    if (!defined(cflags)) {
      cflags = []
    }

    if (defined(invoker.plugin)) {
      cflags += [
        "-Xclang",
        "-add-plugin",
        "-Xclang",
        invoker.plugin,
      ]
    }

    if (defined(invoker.plugin_arguments)) {
      foreach(flag, invoker.plugin_arguments) {
        cflags += [
          "-Xclang",
          "-plugin-arg-${invoker.plugin}",
          "-Xclang",
          flag,
        ]
      }
    }
  }
}

clang_plugin("raw_ptr_check") {
  if (clang_use_chrome_plugins || clang_use_raw_ptr_plugin) {
    # The plugin is built directly into clang, so there's no need to load it
    # dynamically.
    plugin = "raw-ptr-plugin"
    plugin_arguments = [
      "check-raw-ptr-to-stack-allocated",
      "disable-check-raw-ptr-to-stack-allocated-error",

      # TODO(crbug.com/40944547): Remove when raw_ptr check has been enabled
      # for the dawn repo.
      "raw-ptr-exclude-path=" +
          rebase_path("//third_party/dawn/", root_build_dir),

      # TODO(crbug.com/417356903): RawRefFieldMatcher causes OOM while
      # building webidl_in_process_fuzzer.
      "raw-ptr-exclude-path=" +
          rebase_path("chrome/test/fuzzing/webidl_fuzzing/", root_build_dir),
    ]

    if (enable_check_raw_ptr_fields) {
      plugin_arguments += [
        "check-raw-ptr-fields",
        "check-span-fields",
      ]
    }

    if (enable_check_raw_ref_fields) {
      plugin_arguments += [ "check-raw-ref-fields" ]
    }
  }
}

clang_plugin("find_bad_constructs") {
  if (clang_use_chrome_plugins) {
    # The plugin is built directly into clang, so there's no need to load it
    # dynamically.
    plugin = "find-bad-constructs"
    plugin_arguments = [
      "span-ctor-from-string-literal",
      "raw-ref-template-as-trivial-member",
      "raw-span-template-as-trivial-member",
      "check-stack-allocated",
    ]

    if (is_linux || is_chromeos || is_android || is_fuchsia) {
      plugin_arguments += [ "check-ipc" ]
    }

    configs = [ ":raw_ptr_check" ]
  }
}

# A plugin for incrementally applying the -Wunsafe-buffer-usage warning.
#
# To use the plugin, the project must specify a path as
# `clang_unsafe_buffers_paths` in the `//.gn` file. This path points to a text
# file that controls where the warning is checked.
#
# See //build/config/unsafe_buffers_paths.txt for an example file, this it the
# file used by Chromium.
#
# This build configuration is not supported when `enable_precompiled_headers`
# is on because the pragmas that enable and disable unsafe-buffers warnings are
# not serialized to precompiled header files, and thus we get warnings that we
# should not.
clang_plugin("unsafe_buffers") {
  if (clang_use_chrome_plugins && clang_unsafe_buffers_paths != "" &&
      !enable_precompiled_headers) {
    cflags = [ "-DUNSAFE_BUFFERS_BUILD" ]
    plugin = "unsafe-buffers"
    plugin_arguments =
        [ rebase_path(clang_unsafe_buffers_paths, root_build_dir) ]
  }
}

# Enables some extra Clang-specific warnings. Some third-party code won't
# compile with these so may want to remove this config.
config("extra_warnings") {
  cflags = [
    "-Wheader-hygiene",

    # Warns when a const char[] is converted to bool.
    "-Wstring-conversion",

    "-Wtautological-overlap-compare",
  ]
}

group("llvm-symbolizer_data") {
  if (is_win) {
    data = [ "$clang_base_path/bin/llvm-symbolizer.exe" ]
  } else {
    data = [ "$clang_base_path/bin/llvm-symbolizer" ]
  }
}

_cros_resource_dir = ""
if (use_cros_sysroot_libs) {
  _cros_resource_dir =
      exec_script(rebase_path("../../toolchain/cros/get_resource_dir.py"),
                  [ cros_target_cc ],
                  "trim string",
                  [])
}

template("clang_lib") {
  if (!defined(invoker.libname) || is_wasm) {
    not_needed(invoker, "*")
    config(target_name) {
    }
  } else {
    config(target_name) {
      _dir = ""
      _libname = invoker.libname
      _prefix = "lib"
      _suffix = ""
      _ext = "a"

      _clang_lib_dir = "$clang_base_path/lib/clang/$clang_version/lib"
      if (is_win) {
        _dir = "windows"
        _prefix = ""
        _ext = "lib"
        if (current_cpu == "x64") {
          _suffix = "-x86_64"
        } else if (current_cpu == "x86") {
          _suffix = "-i386"
        } else if (current_cpu == "arm64") {
          _suffix = "-aarch64"
        } else {
          assert(false)  # Unhandled cpu type
        }
      } else if (is_apple) {
        _dir = "darwin"
      } else if (use_cros_sysroot_libs) {
        _clang_lib_dir = _cros_resource_dir
        _dir = "lib/linux"
        if (current_cpu == "x64") {
          _suffix = "-x86_64"
        } else if (current_cpu == "x86") {
          _suffix = "-i386"
        } else if (current_cpu == "arm") {
          _suffix = "-armhf"
        } else if (current_cpu == "arm64") {
          _suffix = "-aarch64"
        } else {
          assert(false)  # Unhandled cpu type
        }
      } else if (is_linux) {
        _dir = "linux"
        if (current_cpu == "x64") {
          _suffix = "-x86_64"
        } else if (current_cpu == "x86") {
          _suffix = "-i386"
        } else if (current_cpu == "arm64") {
          _suffix = "-aarch64"
        } else if (current_cpu == "arm") {
          _suffix = "-armhf"
        } else if (current_cpu == "ppc64") {
          _suffix = "-powerpc64le"
        } else {
          assert(false)  # Unhandled cpu type
        }
      } else if (is_chromeos) {
        if (current_cpu == "x64") {
          _dir = "x86_64-unknown-linux-gnu"
        } else if (current_cpu == "x86") {
          _dir = "i386-unknown-linux-gnu"
        } else if (current_cpu == "arm") {
          _dir = "armv7-unknown-linux-gnueabihf"
        } else if (current_cpu == "arm64") {
          _dir = "aarch64-unknown-linux-gnu"
        } else if (current_cpu == "loong64") {
          _dir = "loongarch64-unknown-linux-gnu"
        } else {
          assert(false)  # Unhandled cpu type
        }
      } else if (is_fuchsia) {
        if (current_cpu == "x64") {
          _dir = "x86_64-unknown-fuchsia"
        } else if (current_cpu == "arm64") {
          _dir = "aarch64-unknown-fuchsia"
        } else {
          assert(false)  # Unhandled cpu type
        }
      } else if (is_android) {
        _dir = "linux"
        if (current_cpu == "x64") {
          _suffix = "-x86_64-android"
        } else if (current_cpu == "x86") {
          _suffix = "-i686-android"
        } else if (current_cpu == "arm") {
          _suffix = "-arm-android"
        } else if (current_cpu == "arm64") {
          _suffix = "-aarch64-android"
        } else if (current_cpu == "riscv64") {
          _suffix = "-riscv64-android"
        } else {
          assert(false)  # Unhandled cpu type
        }
      } else {
        assert(false)  # Unhandled target platform
      }

      _lib_file = "${_prefix}clang_rt.${_libname}${_suffix}.${_ext}"
      libs = [ "$_clang_lib_dir/$_dir/$_lib_file" ]

      # HACK: using ChromeOS' compiler-rt results in DSOs exporting
      # compiler-rt symbols; figure out why it's (presumably) not using hidden
      # visibility for most symbols.
      if (use_cros_sysroot_libs) {
        ldflags = [ "-Wl,--exclude-libs=$_lib_file" ]
      }
    }
  }
}

# Adds a dependency on the Clang runtime library clang_rt.builtins.
clang_lib("compiler_builtins") {
  if (is_mac) {
    libname = "osx"
  } else if (is_ios) {
    if (target_platform == "iphoneos") {
      if (target_environment == "simulator") {
        libname = "iossim"
      } else if (target_environment == "device") {
        libname = "ios"
      } else if (target_environment == "catalyst") {
        libname = "osx"
      } else {
        assert(false, "unsupported target_environment=$target_environment")
      }
    } else if (target_platform == "tvos") {
      if (target_environment == "simulator") {
        libname = "tvossim"
      } else if (target_environment == "device") {
        libname = "tvos"
      } else {
        assert(false, "unsupported target_environment=$target_environment")
      }
    } else {
      assert(false, "unsupported target_platform=$target_platform")
    }
  } else {
    libname = "builtins"
  }
}

# Adds a dependency on the Clang runtime library clang_rt.profile.
clang_lib("compiler_profile") {
  if (!toolchain_has_rust) {
    # This is only used when `toolchain_has_rust` to support Rust linking.
    #
    # Don't define libname which makes this target do nothing.
  } else if (is_mac) {
    libname = "profile_osx"
  } else if (is_ios) {
    if (target_environment == "simulator") {
      libname = "profile_iossim"
    } else if (target_environment == "catalyst") {
      # We don't enable clang coverage on iOS device builds, and the library is
      # not part of the Clang package tarball as a result.
      #
      # Don't define libname which makes this target do nothing.
    } else {
      # We don't enable clang coverage on iOS device builds, and the library is
      # not part of the Clang package tarball as a result.
      #
      # Don't define libname which makes this target do nothing.
    }
  } else {
    libname = "profile"
  }
}