Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 1 | // Copyright 2016 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://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, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 15 | package config |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 16 | |
| 17 | import ( |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 18 | "runtime" |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 19 | "strings" |
| 20 | |
| 21 | "android/soong/android" |
Ramy Medhat | 9a90fe5 | 2020-04-13 13:21:23 -0400 | [diff] [blame] | 22 | "android/soong/remoteexec" |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 23 | ) |
| 24 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 25 | var ( |
Leo Li | 8756b37 | 2017-05-22 16:11:34 -0700 | [diff] [blame] | 26 | // Flags used by lots of devices. Putting them in package static variables |
| 27 | // will save bytes in build.ninja so they aren't repeated for every file |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 28 | commonGlobalCflags = []string{ |
| 29 | "-DANDROID", |
| 30 | "-fmessage-length=0", |
| 31 | "-W", |
| 32 | "-Wall", |
| 33 | "-Wno-unused", |
| 34 | "-Winit-self", |
| 35 | "-Wpointer-arith", |
George Burgess IV | fb81db2 | 2020-02-22 19:28:56 -0800 | [diff] [blame] | 36 | "-Wunreachable-code-loop-increment", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 37 | |
Colin Cross | 7278afc | 2017-11-02 22:38:32 -0700 | [diff] [blame] | 38 | // Make paths in deps files relative |
| 39 | "-no-canonical-prefixes", |
| 40 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 41 | "-DNDEBUG", |
| 42 | "-UDEBUG", |
Colin Cross | 7278afc | 2017-11-02 22:38:32 -0700 | [diff] [blame] | 43 | |
| 44 | "-fno-exceptions", |
| 45 | "-Wno-multichar", |
| 46 | |
| 47 | "-O2", |
| 48 | "-g", |
Yi Kong | 110cd5f | 2020-11-04 01:44:15 +0800 | [diff] [blame] | 49 | "-fdebug-info-for-profiling", |
Colin Cross | 7278afc | 2017-11-02 22:38:32 -0700 | [diff] [blame] | 50 | |
| 51 | "-fno-strict-aliasing", |
Dan Willemsen | 5d980c8 | 2019-08-27 19:37:10 -0700 | [diff] [blame] | 52 | |
| 53 | "-Werror=date-time", |
Elliott Hughes | 2cdbdf1 | 2019-12-03 18:13:00 -0800 | [diff] [blame] | 54 | "-Werror=pragma-pack", |
| 55 | "-Werror=pragma-pack-suspicious-include", |
Christopher Di Bella | 23a991c | 2020-11-11 22:41:32 +0000 | [diff] [blame] | 56 | "-Werror=string-plus-int", |
George Burgess IV | fb81db2 | 2020-02-22 19:28:56 -0800 | [diff] [blame] | 57 | "-Werror=unreachable-code-loop-increment", |
Colin Cross | 9cc59c1 | 2021-07-14 17:59:54 -0700 | [diff] [blame] | 58 | |
| 59 | "-D__compiler_offsetof=__builtin_offsetof", |
| 60 | |
| 61 | // Emit address-significance table which allows linker to perform safe ICF. Clang does |
| 62 | // not emit the table by default on Android since NDK still uses GNU binutils. |
| 63 | "-faddrsig", |
| 64 | |
| 65 | // Turn on -fcommon explicitly, since Clang now defaults to -fno-common. The cleanup bug |
| 66 | // tracking this is http://b/151457797. |
| 67 | "-fcommon", |
| 68 | |
| 69 | // Help catch common 32/64-bit errors. |
| 70 | "-Werror=int-conversion", |
| 71 | |
| 72 | // Enable the new pass manager. |
| 73 | "-fexperimental-new-pass-manager", |
| 74 | |
| 75 | // Disable overly aggressive warning for macros defined with a leading underscore |
| 76 | // This happens in AndroidConfig.h, which is included nearly everywhere. |
| 77 | // TODO: can we remove this now? |
| 78 | "-Wno-reserved-id-macro", |
| 79 | |
| 80 | // Workaround for ccache with clang. |
| 81 | // See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html. |
| 82 | "-Wno-unused-command-line-argument", |
| 83 | |
| 84 | // Force clang to always output color diagnostics. Ninja will strip the ANSI |
| 85 | // color codes if it is not running in a terminal. |
| 86 | "-fcolor-diagnostics", |
| 87 | |
| 88 | // Warnings from clang-7.0 |
| 89 | "-Wno-sign-compare", |
| 90 | |
| 91 | // Warnings from clang-8.0 |
| 92 | "-Wno-defaulted-function-deleted", |
| 93 | |
| 94 | // Disable -Winconsistent-missing-override until we can clean up the existing |
| 95 | // codebase for it. |
| 96 | "-Wno-inconsistent-missing-override", |
| 97 | |
| 98 | // Warnings from clang-10 |
| 99 | // Nested and array designated initialization is nice to have. |
| 100 | "-Wno-c99-designator", |
| 101 | |
| 102 | // Warnings from clang-12 |
| 103 | "-Wno-gnu-folding-constant", |
| 104 | |
| 105 | // Calls to the APIs that are newer than the min sdk version of the caller should be |
| 106 | // guarded with __builtin_available. |
| 107 | "-Wunguarded-availability", |
| 108 | // This macro allows the bionic versioning.h to indirectly determine whether the |
| 109 | // option -Wunguarded-availability is on or not. |
| 110 | "-D__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Colin Cross | 6f6a428 | 2016-10-17 14:19:06 -0700 | [diff] [blame] | 113 | commonGlobalConlyflags = []string{} |
Elliott Hughes | 5a0401a | 2016-10-07 13:12:58 -0700 | [diff] [blame] | 114 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 115 | deviceGlobalCflags = []string{ |
Colin Cross | 133dbe7 | 2017-11-02 22:55:19 -0700 | [diff] [blame] | 116 | "-ffunction-sections", |
Colin Cross | ea3141d | 2017-11-06 14:02:02 -0800 | [diff] [blame] | 117 | "-fdata-sections", |
| 118 | "-fno-short-enums", |
Colin Cross | 133dbe7 | 2017-11-02 22:55:19 -0700 | [diff] [blame] | 119 | "-funwind-tables", |
| 120 | "-fstack-protector-strong", |
| 121 | "-Wa,--noexecstack", |
| 122 | "-D_FORTIFY_SOURCE=2", |
| 123 | |
| 124 | "-Wstrict-aliasing=2", |
| 125 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 126 | "-Werror=return-type", |
| 127 | "-Werror=non-virtual-dtor", |
| 128 | "-Werror=address", |
| 129 | "-Werror=sequence-point", |
Colin Cross | 133dbe7 | 2017-11-02 22:55:19 -0700 | [diff] [blame] | 130 | "-Werror=format-security", |
Colin Cross | c8bed31 | 2021-07-14 17:56:21 -0700 | [diff] [blame] | 131 | "-nostdlibinc", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Colin Cross | 26f1450 | 2017-11-06 13:59:48 -0800 | [diff] [blame] | 134 | deviceGlobalCppflags = []string{ |
| 135 | "-fvisibility-inlines-hidden", |
| 136 | } |
| 137 | |
Colin Cross | 324a457 | 2017-11-02 23:09:41 -0700 | [diff] [blame] | 138 | deviceGlobalLdflags = []string{ |
| 139 | "-Wl,-z,noexecstack", |
| 140 | "-Wl,-z,relro", |
| 141 | "-Wl,-z,now", |
| 142 | "-Wl,--build-id=md5", |
| 143 | "-Wl,--warn-shared-textrel", |
| 144 | "-Wl,--fatal-warnings", |
| 145 | "-Wl,--no-undefined-version", |
Ryan Prichard | b35a85e | 2021-01-13 19:18:53 -0800 | [diff] [blame] | 146 | // TODO: Eventually we should link against a libunwind.a with hidden symbols, and then these |
| 147 | // --exclude-libs arguments can be removed. |
Christopher Ferris | c3a1e22 | 2019-04-10 17:57:50 -0700 | [diff] [blame] | 148 | "-Wl,--exclude-libs,libgcc.a", |
Yi Kong | 3d8792f | 2019-05-06 16:18:33 -0700 | [diff] [blame] | 149 | "-Wl,--exclude-libs,libgcc_stripped.a", |
Peter Collingbourne | e5ba286 | 2019-12-10 18:37:45 -0800 | [diff] [blame] | 150 | "-Wl,--exclude-libs,libunwind_llvm.a", |
Ryan Prichard | b35a85e | 2021-01-13 19:18:53 -0800 | [diff] [blame] | 151 | "-Wl,--exclude-libs,libunwind.a", |
Ryo Hashimoto | 5818b93 | 2021-03-23 15:05:22 +0900 | [diff] [blame] | 152 | "-Wl,--icf=safe", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 155 | deviceGlobalLldflags = append(deviceGlobalLdflags, |
Chih-Hung Hsieh | 02b4da5 | 2018-04-03 11:33:34 -0700 | [diff] [blame] | 156 | []string{ |
Chih-Hung Hsieh | 02b4da5 | 2018-04-03 11:33:34 -0700 | [diff] [blame] | 157 | "-fuse-ld=lld", |
| 158 | }...) |
| 159 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 160 | hostGlobalCflags = []string{} |
| 161 | |
Colin Cross | 26f1450 | 2017-11-06 13:59:48 -0800 | [diff] [blame] | 162 | hostGlobalCppflags = []string{} |
| 163 | |
Colin Cross | 324a457 | 2017-11-02 23:09:41 -0700 | [diff] [blame] | 164 | hostGlobalLdflags = []string{} |
| 165 | |
Chih-Hung Hsieh | 3101a96 | 2018-04-17 14:16:05 -0700 | [diff] [blame] | 166 | hostGlobalLldflags = []string{"-fuse-ld=lld"} |
Chih-Hung Hsieh | 02b4da5 | 2018-04-03 11:33:34 -0700 | [diff] [blame] | 167 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 168 | commonGlobalCppflags = []string{ |
| 169 | "-Wsign-promo", |
Colin Cross | c8bed31 | 2021-07-14 17:56:21 -0700 | [diff] [blame] | 170 | |
| 171 | // -Wimplicit-fallthrough is not enabled by -Wall. |
| 172 | "-Wimplicit-fallthrough", |
| 173 | |
| 174 | // Enable clang's thread-safety annotations in libcxx. |
| 175 | "-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS", |
| 176 | |
| 177 | // libc++'s math.h has an #include_next outside of system_headers. |
| 178 | "-Wno-gnu-include-next", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | noOverrideGlobalCflags = []string{ |
Christopher Di Bella | 23a991c | 2020-11-11 22:41:32 +0000 | [diff] [blame] | 182 | "-Werror=bool-operation", |
| 183 | "-Werror=implicit-int-float-conversion", |
| 184 | "-Werror=int-in-bool-context", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 185 | "-Werror=int-to-pointer-cast", |
| 186 | "-Werror=pointer-to-int-cast", |
Christopher Di Bella | 23a991c | 2020-11-11 22:41:32 +0000 | [diff] [blame] | 187 | "-Werror=string-compare", |
| 188 | "-Werror=xor-used-as-pow", |
Stephen Hines | 2210e72 | 2020-07-15 11:11:57 -0700 | [diff] [blame] | 189 | // http://b/161386391 for -Wno-void-pointer-to-enum-cast |
| 190 | "-Wno-void-pointer-to-enum-cast", |
| 191 | // http://b/161386391 for -Wno-void-pointer-to-int-cast |
| 192 | "-Wno-void-pointer-to-int-cast", |
| 193 | // http://b/161386391 for -Wno-pointer-to-int-cast |
| 194 | "-Wno-pointer-to-int-cast", |
George Burgess IV | 6c69164 | 2019-09-18 17:52:05 -0700 | [diff] [blame] | 195 | "-Werror=fortify-source", |
Colin Cross | c8bed31 | 2021-07-14 17:56:21 -0700 | [diff] [blame] | 196 | |
| 197 | "-Werror=address-of-temporary", |
| 198 | // Bug: http://b/29823425 Disable -Wnull-dereference until the |
| 199 | // new cases detected by this warning in Clang r271374 are |
| 200 | // fixed. |
| 201 | //"-Werror=null-dereference", |
| 202 | "-Werror=return-type", |
| 203 | |
| 204 | // http://b/72331526 Disable -Wtautological-* until the instances detected by these |
| 205 | // new warnings are fixed. |
| 206 | "-Wno-tautological-constant-compare", |
| 207 | "-Wno-tautological-type-limit-compare", |
| 208 | // http://b/145210666 |
| 209 | "-Wno-reorder-init-list", |
| 210 | // http://b/145211066 |
| 211 | "-Wno-implicit-int-float-conversion", |
| 212 | // New warnings to be fixed after clang-r377782. |
| 213 | "-Wno-int-in-bool-context", // http://b/148287349 |
| 214 | "-Wno-sizeof-array-div", // http://b/148815709 |
| 215 | "-Wno-tautological-overlap-compare", // http://b/148815696 |
| 216 | // New warnings to be fixed after clang-r383902. |
| 217 | "-Wno-deprecated-copy", // http://b/153746672 |
| 218 | "-Wno-range-loop-construct", // http://b/153747076 |
| 219 | "-Wno-misleading-indentation", // http://b/153746954 |
| 220 | "-Wno-zero-as-null-pointer-constant", // http://b/68236239 |
| 221 | "-Wno-deprecated-anon-enum-enum-conversion", // http://b/153746485 |
| 222 | "-Wno-deprecated-enum-enum-conversion", // http://b/153746563 |
| 223 | "-Wno-string-compare", // http://b/153764102 |
| 224 | "-Wno-enum-enum-conversion", // http://b/154138986 |
| 225 | "-Wno-enum-float-conversion", // http://b/154255917 |
| 226 | "-Wno-pessimizing-move", // http://b/154270751 |
| 227 | // New warnings to be fixed after clang-r399163 |
| 228 | "-Wno-non-c-typedef-for-linkage", // http://b/161304145 |
| 229 | // New warnings to be fixed after clang-r407598 |
| 230 | "-Wno-string-concatenation", // http://b/175068488 |
Yabin Cui | 10bf3b8 | 2021-08-10 15:42:10 +0000 | [diff] [blame] | 231 | // New warnings to be fixed after clang-r428724 |
| 232 | "-Wno-align-mismatch", // http://b/193679946 |
Colin Cross | c8bed31 | 2021-07-14 17:56:21 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | // Extra cflags for external third-party projects to disable warnings that |
| 236 | // are infeasible to fix in all the external projects and their upstream repos. |
| 237 | extraExternalCflags = []string{ |
| 238 | "-Wno-enum-compare", |
| 239 | "-Wno-enum-compare-switch", |
| 240 | |
| 241 | // http://b/72331524 Allow null pointer arithmetic until the instances detected by |
| 242 | // this new warning are fixed. |
| 243 | "-Wno-null-pointer-arithmetic", |
| 244 | |
| 245 | // Bug: http://b/29823425 Disable -Wnull-dereference until the |
| 246 | // new instances detected by this warning are fixed. |
| 247 | "-Wno-null-dereference", |
| 248 | |
| 249 | // http://b/145211477 |
| 250 | "-Wno-pointer-compare", |
| 251 | // http://b/145211022 |
| 252 | "-Wno-xor-used-as-pow", |
| 253 | // http://b/145211022 |
| 254 | "-Wno-final-dtor-non-final-class", |
| 255 | |
| 256 | // http://b/165945989 |
| 257 | "-Wno-psabi", |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 260 | IllegalFlags = []string{ |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 261 | "-w", |
| 262 | } |
Colin Cross | 6f6a428 | 2016-10-17 14:19:06 -0700 | [diff] [blame] | 263 | |
Dan Albert | 043833c | 2017-02-03 16:13:38 -0800 | [diff] [blame] | 264 | CStdVersion = "gnu99" |
Elliott Hughes | 34e4e41 | 2018-11-30 16:03:06 +0000 | [diff] [blame] | 265 | CppStdVersion = "gnu++17" |
Dan Albert | 043833c | 2017-02-03 16:13:38 -0800 | [diff] [blame] | 266 | ExperimentalCStdVersion = "gnu11" |
Elliott Hughes | 3797612 | 2018-11-28 14:16:39 -0800 | [diff] [blame] | 267 | ExperimentalCppStdVersion = "gnu++2a" |
Jayant Chowdhary | 6e8115a | 2017-05-09 10:21:52 -0700 | [diff] [blame] | 268 | |
Leo Li | 8756b37 | 2017-05-22 16:11:34 -0700 | [diff] [blame] | 269 | // prebuilts/clang default settings. |
| 270 | ClangDefaultBase = "prebuilts/clang/host" |
Yabin Cui | 10bf3b8 | 2021-08-10 15:42:10 +0000 | [diff] [blame] | 271 | ClangDefaultVersion = "clang-r428724" |
| 272 | ClangDefaultShortVersion = "13.0.1" |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 273 | |
Chih-Hung Hsieh | 775edde | 2017-12-24 22:24:47 -0800 | [diff] [blame] | 274 | // Directories with warnings from Android.bp files. |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 275 | WarningAllowedProjects = []string{ |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 276 | "device/", |
Chih-Hung Hsieh | 64a38dc | 2017-11-14 14:09:14 -0800 | [diff] [blame] | 277 | "vendor/", |
| 278 | } |
| 279 | |
Chih-Hung Hsieh | 775edde | 2017-12-24 22:24:47 -0800 | [diff] [blame] | 280 | // Directories with warnings from Android.mk files. |
| 281 | WarningAllowedOldProjects = []string{} |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 282 | ) |
| 283 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 284 | var pctx = android.NewPackageContext("android/soong/cc/config") |
| 285 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 286 | func init() { |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 287 | if runtime.GOOS == "linux" { |
Kousik Kumar | d207cbe | 2020-10-20 05:52:49 +0000 | [diff] [blame] | 288 | commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=") |
| 289 | } |
| 290 | |
Jingwen Chen | 51a1e1c | 2021-05-20 13:40:14 +0000 | [diff] [blame] | 291 | exportStringListStaticVariable("CommonGlobalConlyflags", commonGlobalConlyflags) |
| 292 | exportStringListStaticVariable("DeviceGlobalCppflags", deviceGlobalCppflags) |
| 293 | exportStringListStaticVariable("DeviceGlobalLdflags", deviceGlobalLdflags) |
| 294 | exportStringListStaticVariable("DeviceGlobalLldflags", deviceGlobalLldflags) |
| 295 | exportStringListStaticVariable("HostGlobalCppflags", hostGlobalCppflags) |
| 296 | exportStringListStaticVariable("HostGlobalLdflags", hostGlobalLdflags) |
| 297 | exportStringListStaticVariable("HostGlobalLldflags", hostGlobalLldflags) |
Jingwen Chen | bf61afb | 2021-05-06 13:31:18 +0000 | [diff] [blame] | 298 | |
Colin Cross | 0523ba2 | 2021-07-14 18:45:05 -0700 | [diff] [blame] | 299 | // Export the static default CommonGlobalCflags to Bazel. |
Jingwen Chen | bf61afb | 2021-05-06 13:31:18 +0000 | [diff] [blame] | 300 | // TODO(187086342): handle cflags that are set in VariableFuncs. |
Colin Cross | 0523ba2 | 2021-07-14 18:45:05 -0700 | [diff] [blame] | 301 | bazelCommonGlobalCflags := append( |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 302 | commonGlobalCflags, |
Jingwen Chen | bf61afb | 2021-05-06 13:31:18 +0000 | [diff] [blame] | 303 | []string{ |
Jingwen Chen | bf61afb | 2021-05-06 13:31:18 +0000 | [diff] [blame] | 304 | // Default to zero initialization. |
| 305 | "-ftrivial-auto-var-init=zero", |
| 306 | "-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang", |
| 307 | }...) |
Colin Cross | 0523ba2 | 2021-07-14 18:45:05 -0700 | [diff] [blame] | 308 | exportedStringListVars.Set("CommonGlobalCflags", bazelCommonGlobalCflags) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 309 | |
Colin Cross | 0523ba2 | 2021-07-14 18:45:05 -0700 | [diff] [blame] | 310 | pctx.VariableFunc("CommonGlobalCflags", func(ctx android.PackageVarContext) string { |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 311 | flags := commonGlobalCflags |
Stephen Hines | 66c8b44 | 2019-06-10 17:40:12 -0700 | [diff] [blame] | 312 | |
| 313 | // http://b/131390872 |
| 314 | // Automatically initialize any uninitialized stack variables. |
Stephen Hines | 5c873ac | 2020-05-14 00:59:09 +0000 | [diff] [blame] | 315 | // Prefer zero-init if multiple options are set. |
Stephen Hines | 66c8b44 | 2019-06-10 17:40:12 -0700 | [diff] [blame] | 316 | if ctx.Config().IsEnvTrue("AUTO_ZERO_INITIALIZE") { |
| 317 | flags = append(flags, "-ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang") |
| 318 | } else if ctx.Config().IsEnvTrue("AUTO_PATTERN_INITIALIZE") { |
| 319 | flags = append(flags, "-ftrivial-auto-var-init=pattern") |
Stephen Hines | 797e195 | 2020-01-28 14:43:11 -0800 | [diff] [blame] | 320 | } else if ctx.Config().IsEnvTrue("AUTO_UNINITIALIZE") { |
| 321 | flags = append(flags, "-ftrivial-auto-var-init=uninitialized") |
Stephen Hines | 0e1d5d8 | 2020-01-30 15:06:00 -0800 | [diff] [blame] | 322 | } else { |
Stephen Hines | 5c873ac | 2020-05-14 00:59:09 +0000 | [diff] [blame] | 323 | // Default to zero initialization. |
| 324 | flags = append(flags, "-ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang") |
Stephen Hines | 66c8b44 | 2019-06-10 17:40:12 -0700 | [diff] [blame] | 325 | } |
Stephen Hines | 66c8b44 | 2019-06-10 17:40:12 -0700 | [diff] [blame] | 326 | return strings.Join(flags, " ") |
| 327 | }) |
| 328 | |
Colin Cross | 0523ba2 | 2021-07-14 18:45:05 -0700 | [diff] [blame] | 329 | // Export the static default DeviceGlobalCflags to Bazel. |
Jingwen Chen | bf61afb | 2021-05-06 13:31:18 +0000 | [diff] [blame] | 330 | // TODO(187086342): handle cflags that are set in VariableFuncs. |
Colin Cross | 0523ba2 | 2021-07-14 18:45:05 -0700 | [diff] [blame] | 331 | exportedStringListVars.Set("DeviceGlobalCflags", deviceGlobalCflags) |
Jingwen Chen | bf61afb | 2021-05-06 13:31:18 +0000 | [diff] [blame] | 332 | |
Colin Cross | 0523ba2 | 2021-07-14 18:45:05 -0700 | [diff] [blame] | 333 | pctx.VariableFunc("DeviceGlobalCflags", func(ctx android.PackageVarContext) string { |
Colin Cross | c8bed31 | 2021-07-14 17:56:21 -0700 | [diff] [blame] | 334 | return strings.Join(deviceGlobalCflags, " ") |
Doug Horn | c32c6b0 | 2019-01-17 14:44:05 -0800 | [diff] [blame] | 335 | }) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 336 | |
Colin Cross | 0523ba2 | 2021-07-14 18:45:05 -0700 | [diff] [blame] | 337 | exportStringListStaticVariable("HostGlobalCflags", hostGlobalCflags) |
| 338 | exportStringListStaticVariable("NoOverrideGlobalCflags", noOverrideGlobalCflags) |
| 339 | exportStringListStaticVariable("CommonGlobalCppflags", commonGlobalCppflags) |
| 340 | exportStringListStaticVariable("ExternalCflags", extraExternalCflags) |
Yi Kong | cc80f8d | 2018-06-06 14:42:44 -0700 | [diff] [blame] | 341 | |
Colin Cross | 1cfd89a | 2016-09-15 09:30:46 -0700 | [diff] [blame] | 342 | // Everything in these lists is a crime against abstraction and dependency tracking. |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 343 | // Do not add anything to this list. |
Jingwen Chen | 2199995 | 2021-05-19 05:53:51 +0000 | [diff] [blame] | 344 | commonGlobalIncludes := []string{ |
| 345 | "system/core/include", |
| 346 | "system/logging/liblog/include", |
| 347 | "system/media/audio/include", |
| 348 | "hardware/libhardware/include", |
| 349 | "hardware/libhardware_legacy/include", |
| 350 | "hardware/ril/include", |
| 351 | "frameworks/native/include", |
| 352 | "frameworks/native/opengl/include", |
| 353 | "frameworks/av/include", |
| 354 | } |
Jingwen Chen | 51a1e1c | 2021-05-20 13:40:14 +0000 | [diff] [blame] | 355 | exportedStringListVars.Set("CommonGlobalIncludes", commonGlobalIncludes) |
Jingwen Chen | 2199995 | 2021-05-19 05:53:51 +0000 | [diff] [blame] | 356 | pctx.PrefixedExistentPathsForSourcesVariable("CommonGlobalIncludes", "-I", commonGlobalIncludes) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 357 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | a38e518 | 2021-08-12 21:37:35 +0000 | [diff] [blame^] | 358 | exportStringStaticVariable("CLANG_DEFAULT_VERSION", ClangDefaultVersion) |
| 359 | exportStringStaticVariable("CLANG_DEFAULT_SHORT_VERSION", ClangDefaultShortVersion) |
| 360 | |
Leo Li | 8756b37 | 2017-05-22 16:11:34 -0700 | [diff] [blame] | 361 | pctx.SourcePathVariable("ClangDefaultBase", ClangDefaultBase) |
Dan Willemsen | 54daaf0 | 2018-03-12 13:24:09 -0700 | [diff] [blame] | 362 | pctx.VariableFunc("ClangBase", func(ctx android.PackageVarContext) string { |
| 363 | if override := ctx.Config().Getenv("LLVM_PREBUILTS_BASE"); override != "" { |
| 364 | return override |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 365 | } |
Dan Willemsen | 54daaf0 | 2018-03-12 13:24:09 -0700 | [diff] [blame] | 366 | return "${ClangDefaultBase}" |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 367 | }) |
Dan Willemsen | 54daaf0 | 2018-03-12 13:24:09 -0700 | [diff] [blame] | 368 | pctx.VariableFunc("ClangVersion", func(ctx android.PackageVarContext) string { |
| 369 | if override := ctx.Config().Getenv("LLVM_PREBUILTS_VERSION"); override != "" { |
| 370 | return override |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 371 | } |
Dan Willemsen | 54daaf0 | 2018-03-12 13:24:09 -0700 | [diff] [blame] | 372 | return ClangDefaultVersion |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 373 | }) |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 374 | pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}") |
| 375 | pctx.StaticVariable("ClangBin", "${ClangPath}/bin") |
| 376 | |
Dan Willemsen | 54daaf0 | 2018-03-12 13:24:09 -0700 | [diff] [blame] | 377 | pctx.VariableFunc("ClangShortVersion", func(ctx android.PackageVarContext) string { |
| 378 | if override := ctx.Config().Getenv("LLVM_RELEASE_VERSION"); override != "" { |
| 379 | return override |
Stephen Hines | e55a4cc | 2016-11-18 17:12:38 -0800 | [diff] [blame] | 380 | } |
Dan Willemsen | 54daaf0 | 2018-03-12 13:24:09 -0700 | [diff] [blame] | 381 | return ClangDefaultShortVersion |
Stephen Hines | e55a4cc | 2016-11-18 17:12:38 -0800 | [diff] [blame] | 382 | }) |
Stephen Hines | 755fe07 | 2018-01-24 19:58:36 -0800 | [diff] [blame] | 383 | pctx.StaticVariable("ClangAsanLibDir", "${ClangBase}/linux-x86/${ClangVersion}/lib64/clang/${ClangShortVersion}/lib/linux") |
Alistair Strachan | 777475c | 2016-08-26 12:55:49 -0700 | [diff] [blame] | 384 | |
Jayant Chowdhary | e622d20 | 2017-02-01 19:19:52 -0800 | [diff] [blame] | 385 | // These are tied to the version of LLVM directly in external/llvm, so they might trail the host prebuilts |
| 386 | // being used for the rest of the build process. |
| 387 | pctx.SourcePathVariable("RSClangBase", "prebuilts/clang/host") |
| 388 | pctx.SourcePathVariable("RSClangVersion", "clang-3289846") |
| 389 | pctx.SourcePathVariable("RSReleaseVersion", "3.8") |
| 390 | pctx.StaticVariable("RSLLVMPrebuiltsPath", "${RSClangBase}/${HostPrebuiltTag}/${RSClangVersion}/bin") |
| 391 | pctx.StaticVariable("RSIncludePath", "${RSLLVMPrebuiltsPath}/../lib64/clang/${RSReleaseVersion}/include") |
| 392 | |
Jeff Gaston | 734e380 | 2017-04-10 15:47:24 -0700 | [diff] [blame] | 393 | pctx.PrefixedExistentPathsForSourcesVariable("RsGlobalIncludes", "-I", |
Colin Cross | 2a252be | 2017-05-01 17:37:24 -0700 | [diff] [blame] | 394 | []string{ |
| 395 | "external/clang/lib/Headers", |
| 396 | "frameworks/rs/script_api/include", |
| 397 | }) |
| 398 | |
Dan Willemsen | 54daaf0 | 2018-03-12 13:24:09 -0700 | [diff] [blame] | 399 | pctx.VariableFunc("CcWrapper", func(ctx android.PackageVarContext) string { |
| 400 | if override := ctx.Config().Getenv("CC_WRAPPER"); override != "" { |
| 401 | return override + " " |
Alistair Strachan | 777475c | 2016-08-26 12:55:49 -0700 | [diff] [blame] | 402 | } |
Dan Willemsen | 54daaf0 | 2018-03-12 13:24:09 -0700 | [diff] [blame] | 403 | return "" |
Alistair Strachan | 777475c | 2016-08-26 12:55:49 -0700 | [diff] [blame] | 404 | }) |
Ramy Medhat | 9a90fe5 | 2020-04-13 13:21:23 -0400 | [diff] [blame] | 405 | |
Colin Cross | 77cdcfd | 2021-03-12 11:28:25 -0800 | [diff] [blame] | 406 | pctx.StaticVariableWithEnvOverride("RECXXPool", "RBE_CXX_POOL", remoteexec.DefaultPool) |
| 407 | pctx.StaticVariableWithEnvOverride("RECXXLinksPool", "RBE_CXX_LINKS_POOL", remoteexec.DefaultPool) |
| 408 | pctx.StaticVariableWithEnvOverride("REClangTidyPool", "RBE_CLANG_TIDY_POOL", remoteexec.DefaultPool) |
| 409 | pctx.StaticVariableWithEnvOverride("RECXXLinksExecStrategy", "RBE_CXX_LINKS_EXEC_STRATEGY", remoteexec.LocalExecStrategy) |
| 410 | pctx.StaticVariableWithEnvOverride("REClangTidyExecStrategy", "RBE_CLANG_TIDY_EXEC_STRATEGY", remoteexec.LocalExecStrategy) |
| 411 | pctx.StaticVariableWithEnvOverride("REAbiDumperExecStrategy", "RBE_ABI_DUMPER_EXEC_STRATEGY", remoteexec.LocalExecStrategy) |
| 412 | pctx.StaticVariableWithEnvOverride("REAbiLinkerExecStrategy", "RBE_ABI_LINKER_EXEC_STRATEGY", remoteexec.LocalExecStrategy) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS) |