• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2013 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import("//build/config/rust.gni")
6import("clang.gni")
7
8if (is_ios) {
9  import("//build/config/ios/config.gni")  # For `target_environment`
10}
11
12config("find_bad_constructs") {
13  if (clang_use_chrome_plugins) {
14    cflags = []
15
16    # The plugin is built directly into clang, so there's no need to load it
17    # dynamically.
18    cflags += [
19      "-Xclang",
20      "-add-plugin",
21      "-Xclang",
22      "find-bad-constructs",
23
24      "-Xclang",
25      "-plugin-arg-find-bad-constructs",
26      "-Xclang",
27      "raw-ref-template-as-trivial-member",
28
29      "-Xclang",
30      "-plugin-arg-find-bad-constructs",
31      "-Xclang",
32      "check-stack-allocated",
33    ]
34
35    if (is_linux || is_chromeos || is_android || is_fuchsia) {
36      cflags += [
37        "-Xclang",
38        "-plugin-arg-find-bad-constructs",
39        "-Xclang",
40        "check-ipc",
41      ]
42    }
43
44    if (enable_check_raw_ptr_fields) {
45      cflags += [
46        "-Xclang",
47        "-plugin-arg-find-bad-constructs",
48        "-Xclang",
49        "check-raw-ptr-fields",
50
51        # TODO(mikt): Remove this once crbug.com/1449812 is resolved.
52        "-Xclang",
53        "-plugin-arg-find-bad-constructs",
54        "-Xclang",
55        "raw-ptr-exclude-path=um/winnt.h",
56      ]
57    }
58
59    if (enable_check_raw_ref_fields) {
60      cflags += [
61        "-Xclang",
62        "-plugin-arg-find-bad-constructs",
63        "-Xclang",
64        "check-raw-ref-fields",
65      ]
66    }
67  }
68}
69
70# Enables some extra Clang-specific warnings. Some third-party code won't
71# compile with these so may want to remove this config.
72config("extra_warnings") {
73  cflags = [
74    "-Wheader-hygiene",
75
76    # Warns when a const char[] is converted to bool.
77    "-Wstring-conversion",
78
79    "-Wtautological-overlap-compare",
80  ]
81}
82
83group("llvm-symbolizer_data") {
84  if (is_win) {
85    data = [ "$clang_base_path/bin/llvm-symbolizer.exe" ]
86  } else {
87    data = [ "$clang_base_path/bin/llvm-symbolizer" ]
88  }
89}
90
91template("clang_lib") {
92  if (!defined(invoker.libname)) {
93    not_needed(invoker, "*")
94    config(target_name) {
95    }
96  } else {
97    config(target_name) {
98      _dir = ""
99      _libname = invoker.libname
100      _prefix = "lib"
101      _suffix = ""
102      _ext = "a"
103      if (is_win) {
104        _dir = "windows"
105        _prefix = ""
106        _ext = "lib"
107        if (current_cpu == "x64") {
108          _suffix = "-x86_64"
109        } else if (current_cpu == "x86") {
110          _suffix = "-i386"
111        } else if (current_cpu == "arm64") {
112          _suffix = "-aarch64"
113        } else {
114          assert(false)  # Unhandled cpu type
115        }
116      } else if (is_apple) {
117        _dir = "darwin"
118      } else if (is_linux || is_chromeos) {
119        if (current_cpu == "x64") {
120          _dir = "x86_64-unknown-linux-gnu"
121        } else if (current_cpu == "x86") {
122          _dir = "i386-unknown-linux-gnu"
123        } else if (current_cpu == "arm") {
124          _dir = "armv7-unknown-linux-gnueabihf"
125        } else if (current_cpu == "arm64") {
126          _dir = "aarch64-unknown-linux-gnu"
127        } else {
128          assert(false)  # Unhandled cpu type
129        }
130      } else if (is_fuchsia) {
131        if (current_cpu == "x64") {
132          _dir = "x86_64-unknown-fuchsia"
133        } else if (current_cpu == "arm64") {
134          _dir = "aarch64-unknown-fuchsia"
135        } else {
136          assert(false)  # Unhandled cpu type
137        }
138      } else if (is_android) {
139        _dir = "linux"
140        if (current_cpu == "x64") {
141          _suffix = "-x86_64-android"
142        } else if (current_cpu == "x86") {
143          _suffix = "-i686-android"
144        } else if (current_cpu == "arm") {
145          _suffix = "-arm-android"
146        } else if (current_cpu == "arm64") {
147          _suffix = "-aarch64-android"
148        } else if (current_cpu == "riscv64") {
149          _suffix = "-riscv64-android"
150        } else {
151          assert(false)  # Unhandled cpu type
152        }
153      } else {
154        assert(false)  # Unhandled target platform
155      }
156
157      _clang_lib_dir = "$clang_base_path/lib/clang/$clang_version/lib"
158      _lib_file = "${_prefix}clang_rt.${_libname}${_suffix}.${_ext}"
159      libs = [ "$_clang_lib_dir/$_dir/$_lib_file" ]
160    }
161  }
162}
163
164# Adds a dependency on the Clang runtime library clang_rt.builtins.
165clang_lib("compiler_builtins") {
166  if (!toolchain_has_rust) {
167    # Since there's no Rust in the toolchain, there's no concern that we'll use
168    # the Rust stdlib's intrinsics here.
169    #
170    # Don't define libname which makes this target do nothing.
171  } else if (is_mac) {
172    libname = "osx"
173  } else if (is_ios) {
174    if (target_environment == "simulator") {
175      libname = "iossim"
176    } else if (target_environment == "catalyst") {
177      libname = "osx"
178    } else {
179      libname = "ios"
180    }
181  } else {
182    libname = "builtins"
183  }
184}
185
186# Adds a dependency on the Clang runtime library clang_rt.profile.
187clang_lib("compiler_profile") {
188  if (!toolchain_has_rust) {
189    # This is only used when `toolchain_has_rust` to support Rust linking.
190    #
191    # Don't define libname which makes this target do nothing.
192  } else if (is_mac) {
193    libname = "profile_osx"
194  } else if (is_ios) {
195    if (target_environment == "simulator") {
196      libname = "profile_iossim"
197    } else if (target_environment == "catalyst") {
198      # We don't enable clang coverage on iOS device builds, and the library is
199      # not part of the Clang package tarball as a result.
200      #
201      # Don't define libname which makes this target do nothing.
202    } else {
203      # We don't enable clang coverage on iOS device builds, and the library is
204      # not part of the Clang package tarball as a result.
205      #
206      # Don't define libname which makes this target do nothing.
207    }
208  } else {
209    libname = "profile"
210  }
211}
212