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 "-Xclang", 35 "-plugin-arg-find-bad-constructs", 36 "-Xclang", 37 "check-raw-ptr-to-stack-allocated", 38 39 # TODO(https://crbug.com/1449812): This option should be removed after 40 # next clang roll. 41 "-Xclang", 42 "-plugin-arg-find-bad-constructs", 43 "-Xclang", 44 "raw-ptr-fix-crbug-1449812", 45 46 # TODO(https://crbug.com/1504043): Remove when raw_ptr check has been enabled for the dawn repo. 47 "-Xclang", 48 "-plugin-arg-find-bad-constructs", 49 "-Xclang", 50 "raw-ptr-exclude-path=/third_party/dawn/", 51 ] 52 53 if (is_linux || is_chromeos || is_android || is_fuchsia) { 54 cflags += [ 55 "-Xclang", 56 "-plugin-arg-find-bad-constructs", 57 "-Xclang", 58 "check-ipc", 59 ] 60 } 61 62 if (enable_check_raw_ptr_fields) { 63 cflags += [ 64 "-Xclang", 65 "-plugin-arg-find-bad-constructs", 66 "-Xclang", 67 "check-raw-ptr-fields", 68 ] 69 } 70 71 if (enable_check_raw_ref_fields) { 72 cflags += [ 73 "-Xclang", 74 "-plugin-arg-find-bad-constructs", 75 "-Xclang", 76 "check-raw-ref-fields", 77 ] 78 } 79 } 80} 81 82# Enables some extra Clang-specific warnings. Some third-party code won't 83# compile with these so may want to remove this config. 84config("extra_warnings") { 85 cflags = [ 86 "-Wheader-hygiene", 87 88 # Warns when a const char[] is converted to bool. 89 "-Wstring-conversion", 90 91 "-Wtautological-overlap-compare", 92 ] 93} 94 95group("llvm-symbolizer_data") { 96 if (is_win) { 97 data = [ "$clang_base_path/bin/llvm-symbolizer.exe" ] 98 } else { 99 data = [ "$clang_base_path/bin/llvm-symbolizer" ] 100 } 101} 102 103template("clang_lib") { 104 if (!defined(invoker.libname)) { 105 not_needed(invoker, "*") 106 config(target_name) { 107 } 108 } else { 109 config(target_name) { 110 _dir = "" 111 _libname = invoker.libname 112 _prefix = "lib" 113 _suffix = "" 114 _ext = "a" 115 if (is_win) { 116 _dir = "windows" 117 _prefix = "" 118 _ext = "lib" 119 if (current_cpu == "x64") { 120 _suffix = "-x86_64" 121 } else if (current_cpu == "x86") { 122 _suffix = "-i386" 123 } else if (current_cpu == "arm64") { 124 _suffix = "-aarch64" 125 } else { 126 assert(false) # Unhandled cpu type 127 } 128 } else if (is_apple) { 129 _dir = "darwin" 130 } else if (is_linux || is_chromeos) { 131 if (current_cpu == "x64") { 132 _dir = "x86_64-unknown-linux-gnu" 133 } else if (current_cpu == "x86") { 134 _dir = "i386-unknown-linux-gnu" 135 } else if (current_cpu == "arm") { 136 _dir = "armv7-unknown-linux-gnueabihf" 137 } else if (current_cpu == "arm64") { 138 _dir = "aarch64-unknown-linux-gnu" 139 } else { 140 assert(false) # Unhandled cpu type 141 } 142 } else if (is_fuchsia) { 143 if (current_cpu == "x64") { 144 _dir = "x86_64-unknown-fuchsia" 145 } else if (current_cpu == "arm64") { 146 _dir = "aarch64-unknown-fuchsia" 147 } else { 148 assert(false) # Unhandled cpu type 149 } 150 } else if (is_android) { 151 _dir = "linux" 152 if (current_cpu == "x64") { 153 _suffix = "-x86_64-android" 154 } else if (current_cpu == "x86") { 155 _suffix = "-i686-android" 156 } else if (current_cpu == "arm") { 157 _suffix = "-arm-android" 158 } else if (current_cpu == "arm64") { 159 _suffix = "-aarch64-android" 160 } else if (current_cpu == "riscv64") { 161 _suffix = "-riscv64-android" 162 } else { 163 assert(false) # Unhandled cpu type 164 } 165 } else { 166 assert(false) # Unhandled target platform 167 } 168 169 _clang_lib_dir = "$clang_base_path/lib/clang/$clang_version/lib" 170 _lib_file = "${_prefix}clang_rt.${_libname}${_suffix}.${_ext}" 171 libs = [ "$_clang_lib_dir/$_dir/$_lib_file" ] 172 } 173 } 174} 175 176# Adds a dependency on the Clang runtime library clang_rt.builtins. 177clang_lib("compiler_builtins") { 178 if (!toolchain_has_rust) { 179 # Since there's no Rust in the toolchain, there's no concern that we'll use 180 # the Rust stdlib's intrinsics here. 181 # 182 # Don't define libname which makes this target do nothing. 183 } else if (is_mac) { 184 libname = "osx" 185 } else if (is_ios) { 186 if (target_environment == "simulator") { 187 libname = "iossim" 188 } else if (target_environment == "catalyst") { 189 libname = "osx" 190 } else { 191 libname = "ios" 192 } 193 } else { 194 libname = "builtins" 195 } 196} 197 198# Adds a dependency on the Clang runtime library clang_rt.profile. 199clang_lib("compiler_profile") { 200 if (!toolchain_has_rust) { 201 # This is only used when `toolchain_has_rust` to support Rust linking. 202 # 203 # Don't define libname which makes this target do nothing. 204 } else if (is_mac) { 205 libname = "profile_osx" 206 } else if (is_ios) { 207 if (target_environment == "simulator") { 208 libname = "profile_iossim" 209 } else if (target_environment == "catalyst") { 210 # We don't enable clang coverage on iOS device builds, and the library is 211 # not part of the Clang package tarball as a result. 212 # 213 # Don't define libname which makes this target do nothing. 214 } else { 215 # We don't enable clang coverage on iOS device builds, and the library is 216 # not part of the Clang package tarball as a result. 217 # 218 # Don't define libname which makes this target do nothing. 219 } 220 } else { 221 libname = "profile" 222 } 223} 224