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