blob: 5acc7f52cbf3729a4b0097b7fd15d8413faf9f93 [file] [log] [blame]
Colin Cross4d9c2d12016-07-29 12:48:20 -07001// 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 Crossb98c8b02016-07-29 13:44:28 -070015package config
Colin Cross4d9c2d12016-07-29 12:48:20 -070016
17import (
Colin Cross0c66bc62021-07-20 09:47:41 -070018 "runtime"
Colin Cross4d9c2d12016-07-29 12:48:20 -070019 "strings"
20
21 "android/soong/android"
Ramy Medhat9a90fe52020-04-13 13:21:23 -040022 "android/soong/remoteexec"
Colin Cross4d9c2d12016-07-29 12:48:20 -070023)
24
Colin Cross4d9c2d12016-07-29 12:48:20 -070025var (
Leo Li8756b372017-05-22 16:11:34 -070026 // 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 Cross4d9c2d12016-07-29 12:48:20 -070028 commonGlobalCflags = []string{
29 "-DANDROID",
30 "-fmessage-length=0",
31 "-W",
32 "-Wall",
33 "-Wno-unused",
34 "-Winit-self",
35 "-Wpointer-arith",
George Burgess IVfb81db22020-02-22 19:28:56 -080036 "-Wunreachable-code-loop-increment",
Colin Cross4d9c2d12016-07-29 12:48:20 -070037
Colin Cross7278afc2017-11-02 22:38:32 -070038 // Make paths in deps files relative
39 "-no-canonical-prefixes",
40
Colin Cross4d9c2d12016-07-29 12:48:20 -070041 "-DNDEBUG",
42 "-UDEBUG",
Colin Cross7278afc2017-11-02 22:38:32 -070043
44 "-fno-exceptions",
45 "-Wno-multichar",
46
47 "-O2",
48 "-g",
Stephen Hines8afd1752022-01-20 11:01:16 -080049 "-fdebug-default-version=5",
Colin Cross7278afc2017-11-02 22:38:32 -070050
51 "-fno-strict-aliasing",
Dan Willemsen5d980c82019-08-27 19:37:10 -070052
53 "-Werror=date-time",
Elliott Hughes2cdbdf12019-12-03 18:13:00 -080054 "-Werror=pragma-pack",
55 "-Werror=pragma-pack-suspicious-include",
Christopher Di Bella23a991c2020-11-11 22:41:32 +000056 "-Werror=string-plus-int",
George Burgess IVfb81db22020-02-22 19:28:56 -080057 "-Werror=unreachable-code-loop-increment",
Colin Cross9cc59c12021-07-14 17:59:54 -070058
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
Colin Cross9cc59c12021-07-14 17:59:54 -070080 // Force clang to always output color diagnostics. Ninja will strip the ANSI
81 // color codes if it is not running in a terminal.
82 "-fcolor-diagnostics",
83
84 // Warnings from clang-7.0
85 "-Wno-sign-compare",
86
87 // Warnings from clang-8.0
88 "-Wno-defaulted-function-deleted",
89
90 // Disable -Winconsistent-missing-override until we can clean up the existing
91 // codebase for it.
92 "-Wno-inconsistent-missing-override",
93
94 // Warnings from clang-10
95 // Nested and array designated initialization is nice to have.
96 "-Wno-c99-designator",
97
98 // Warnings from clang-12
99 "-Wno-gnu-folding-constant",
100
101 // Calls to the APIs that are newer than the min sdk version of the caller should be
102 // guarded with __builtin_available.
103 "-Wunguarded-availability",
104 // This macro allows the bionic versioning.h to indirectly determine whether the
105 // option -Wunguarded-availability is on or not.
106 "-D__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700107 }
108
Colin Cross6f6a4282016-10-17 14:19:06 -0700109 commonGlobalConlyflags = []string{}
Elliott Hughes5a0401a2016-10-07 13:12:58 -0700110
Colin Cross4d9c2d12016-07-29 12:48:20 -0700111 deviceGlobalCflags = []string{
Colin Cross133dbe72017-11-02 22:55:19 -0700112 "-ffunction-sections",
Colin Crossea3141d2017-11-06 14:02:02 -0800113 "-fdata-sections",
114 "-fno-short-enums",
Colin Cross133dbe72017-11-02 22:55:19 -0700115 "-funwind-tables",
116 "-fstack-protector-strong",
117 "-Wa,--noexecstack",
118 "-D_FORTIFY_SOURCE=2",
119
120 "-Wstrict-aliasing=2",
121
Colin Cross4d9c2d12016-07-29 12:48:20 -0700122 "-Werror=return-type",
123 "-Werror=non-virtual-dtor",
124 "-Werror=address",
125 "-Werror=sequence-point",
Colin Cross133dbe72017-11-02 22:55:19 -0700126 "-Werror=format-security",
Colin Crossc8bed312021-07-14 17:56:21 -0700127 "-nostdlibinc",
Yi Kong196b9262021-12-07 13:51:38 +0800128
129 // Emit additional debug info for AutoFDO
130 "-fdebug-info-for-profiling",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700131 }
132
Colin Cross26f14502017-11-06 13:59:48 -0800133 deviceGlobalCppflags = []string{
134 "-fvisibility-inlines-hidden",
135 }
136
Colin Cross324a4572017-11-02 23:09:41 -0700137 deviceGlobalLdflags = []string{
138 "-Wl,-z,noexecstack",
139 "-Wl,-z,relro",
140 "-Wl,-z,now",
141 "-Wl,--build-id=md5",
142 "-Wl,--warn-shared-textrel",
143 "-Wl,--fatal-warnings",
144 "-Wl,--no-undefined-version",
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800145 // TODO: Eventually we should link against a libunwind.a with hidden symbols, and then these
146 // --exclude-libs arguments can be removed.
Christopher Ferrisc3a1e222019-04-10 17:57:50 -0700147 "-Wl,--exclude-libs,libgcc.a",
Yi Kong3d8792f2019-05-06 16:18:33 -0700148 "-Wl,--exclude-libs,libgcc_stripped.a",
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800149 "-Wl,--exclude-libs,libunwind_llvm.a",
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800150 "-Wl,--exclude-libs,libunwind.a",
Ryo Hashimoto5818b932021-03-23 15:05:22 +0900151 "-Wl,--icf=safe",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700152 }
153
Colin Cross33bac242021-07-14 17:03:16 -0700154 deviceGlobalLldflags = append(deviceGlobalLdflags,
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700155 []string{
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700156 "-fuse-ld=lld",
157 }...)
158
Colin Cross4d9c2d12016-07-29 12:48:20 -0700159 hostGlobalCflags = []string{}
160
Colin Cross26f14502017-11-06 13:59:48 -0800161 hostGlobalCppflags = []string{}
162
Colin Cross324a4572017-11-02 23:09:41 -0700163 hostGlobalLdflags = []string{}
164
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700165 hostGlobalLldflags = []string{"-fuse-ld=lld"}
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700166
Colin Cross4d9c2d12016-07-29 12:48:20 -0700167 commonGlobalCppflags = []string{
168 "-Wsign-promo",
Colin Crossc8bed312021-07-14 17:56:21 -0700169
170 // -Wimplicit-fallthrough is not enabled by -Wall.
171 "-Wimplicit-fallthrough",
172
173 // Enable clang's thread-safety annotations in libcxx.
174 "-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS",
175
176 // libc++'s math.h has an #include_next outside of system_headers.
177 "-Wno-gnu-include-next",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700178 }
179
180 noOverrideGlobalCflags = []string{
Christopher Di Bella23a991c2020-11-11 22:41:32 +0000181 "-Werror=bool-operation",
182 "-Werror=implicit-int-float-conversion",
183 "-Werror=int-in-bool-context",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700184 "-Werror=int-to-pointer-cast",
185 "-Werror=pointer-to-int-cast",
Christopher Di Bella23a991c2020-11-11 22:41:32 +0000186 "-Werror=string-compare",
187 "-Werror=xor-used-as-pow",
Stephen Hines2210e722020-07-15 11:11:57 -0700188 // http://b/161386391 for -Wno-void-pointer-to-enum-cast
189 "-Wno-void-pointer-to-enum-cast",
190 // http://b/161386391 for -Wno-void-pointer-to-int-cast
191 "-Wno-void-pointer-to-int-cast",
192 // http://b/161386391 for -Wno-pointer-to-int-cast
193 "-Wno-pointer-to-int-cast",
George Burgess IV6c691642019-09-18 17:52:05 -0700194 "-Werror=fortify-source",
Colin Crossc8bed312021-07-14 17:56:21 -0700195
196 "-Werror=address-of-temporary",
197 // Bug: http://b/29823425 Disable -Wnull-dereference until the
198 // new cases detected by this warning in Clang r271374 are
199 // fixed.
200 //"-Werror=null-dereference",
201 "-Werror=return-type",
202
203 // http://b/72331526 Disable -Wtautological-* until the instances detected by these
204 // new warnings are fixed.
205 "-Wno-tautological-constant-compare",
206 "-Wno-tautological-type-limit-compare",
207 // http://b/145210666
208 "-Wno-reorder-init-list",
209 // http://b/145211066
210 "-Wno-implicit-int-float-conversion",
211 // New warnings to be fixed after clang-r377782.
212 "-Wno-int-in-bool-context", // http://b/148287349
213 "-Wno-sizeof-array-div", // http://b/148815709
214 "-Wno-tautological-overlap-compare", // http://b/148815696
215 // New warnings to be fixed after clang-r383902.
216 "-Wno-deprecated-copy", // http://b/153746672
217 "-Wno-range-loop-construct", // http://b/153747076
218 "-Wno-misleading-indentation", // http://b/153746954
219 "-Wno-zero-as-null-pointer-constant", // http://b/68236239
220 "-Wno-deprecated-anon-enum-enum-conversion", // http://b/153746485
221 "-Wno-deprecated-enum-enum-conversion", // http://b/153746563
222 "-Wno-string-compare", // http://b/153764102
223 "-Wno-enum-enum-conversion", // http://b/154138986
224 "-Wno-enum-float-conversion", // http://b/154255917
225 "-Wno-pessimizing-move", // http://b/154270751
226 // New warnings to be fixed after clang-r399163
227 "-Wno-non-c-typedef-for-linkage", // http://b/161304145
Yabin Cui10bf3b82021-08-10 15:42:10 +0000228 // New warnings to be fixed after clang-r428724
229 "-Wno-align-mismatch", // http://b/193679946
Yi Konge8273292021-08-31 14:04:18 +0800230 // New warnings to be fixed after clang-r433403
231 "-Wno-error=unused-but-set-variable", // http://b/197240255
232 "-Wno-error=unused-but-set-parameter", // http://b/197240255
Colin Crossc8bed312021-07-14 17:56:21 -0700233 }
234
Stephen Hinese24303f2021-12-14 15:07:08 -0800235 noOverrideExternalGlobalCflags = []string{
236 // http://b/197240255
237 "-Wno-unused-but-set-variable",
238 "-Wno-unused-but-set-parameter",
239 }
240
Colin Crossc8bed312021-07-14 17:56:21 -0700241 // Extra cflags for external third-party projects to disable warnings that
242 // are infeasible to fix in all the external projects and their upstream repos.
243 extraExternalCflags = []string{
244 "-Wno-enum-compare",
245 "-Wno-enum-compare-switch",
246
247 // http://b/72331524 Allow null pointer arithmetic until the instances detected by
248 // this new warning are fixed.
249 "-Wno-null-pointer-arithmetic",
250
251 // Bug: http://b/29823425 Disable -Wnull-dereference until the
252 // new instances detected by this warning are fixed.
253 "-Wno-null-dereference",
254
255 // http://b/145211477
256 "-Wno-pointer-compare",
257 // http://b/145211022
258 "-Wno-xor-used-as-pow",
259 // http://b/145211022
260 "-Wno-final-dtor-non-final-class",
261
262 // http://b/165945989
263 "-Wno-psabi",
Yi Konge8273292021-08-31 14:04:18 +0800264
265 // http://b/199369603
266 "-Wno-null-pointer-subtraction",
Yi Kong9feb0292021-12-15 13:20:27 +0800267
268 // http://b/175068488
269 "-Wno-string-concatenation",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700270 }
271
Colin Crossb98c8b02016-07-29 13:44:28 -0700272 IllegalFlags = []string{
Colin Cross4d9c2d12016-07-29 12:48:20 -0700273 "-w",
274 }
Colin Cross6f6a4282016-10-17 14:19:06 -0700275
Dan Albert043833c2017-02-03 16:13:38 -0800276 CStdVersion = "gnu99"
Elliott Hughes34e4e412018-11-30 16:03:06 +0000277 CppStdVersion = "gnu++17"
Dan Albert043833c2017-02-03 16:13:38 -0800278 ExperimentalCStdVersion = "gnu11"
Elliott Hughes37976122018-11-28 14:16:39 -0800279 ExperimentalCppStdVersion = "gnu++2a"
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -0700280
Leo Li8756b372017-05-22 16:11:34 -0700281 // prebuilts/clang default settings.
282 ClangDefaultBase = "prebuilts/clang/host"
Chih-Hung Hsieh66e8f722021-12-28 11:15:42 -0800283 ClangDefaultVersion = "clang-r437112b"
284 ClangDefaultShortVersion = "14.0.1"
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800285
Chih-Hung Hsieh775edde2017-12-24 22:24:47 -0800286 // Directories with warnings from Android.bp files.
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800287 WarningAllowedProjects = []string{
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800288 "device/",
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800289 "vendor/",
290 }
291
Chih-Hung Hsieh775edde2017-12-24 22:24:47 -0800292 // Directories with warnings from Android.mk files.
293 WarningAllowedOldProjects = []string{}
Colin Cross4d9c2d12016-07-29 12:48:20 -0700294)
295
Colin Crossb98c8b02016-07-29 13:44:28 -0700296var pctx = android.NewPackageContext("android/soong/cc/config")
297
Colin Cross4d9c2d12016-07-29 12:48:20 -0700298func init() {
Colin Cross0c66bc62021-07-20 09:47:41 -0700299 if runtime.GOOS == "linux" {
Kousik Kumard207cbe2020-10-20 05:52:49 +0000300 commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
301 }
302
Jingwen Chen51a1e1c2021-05-20 13:40:14 +0000303 exportStringListStaticVariable("CommonGlobalConlyflags", commonGlobalConlyflags)
304 exportStringListStaticVariable("DeviceGlobalCppflags", deviceGlobalCppflags)
305 exportStringListStaticVariable("DeviceGlobalLdflags", deviceGlobalLdflags)
306 exportStringListStaticVariable("DeviceGlobalLldflags", deviceGlobalLldflags)
307 exportStringListStaticVariable("HostGlobalCppflags", hostGlobalCppflags)
308 exportStringListStaticVariable("HostGlobalLdflags", hostGlobalLdflags)
309 exportStringListStaticVariable("HostGlobalLldflags", hostGlobalLldflags)
Jingwen Chenbf61afb2021-05-06 13:31:18 +0000310
Colin Cross0523ba22021-07-14 18:45:05 -0700311 // Export the static default CommonGlobalCflags to Bazel.
Jingwen Chenbf61afb2021-05-06 13:31:18 +0000312 // TODO(187086342): handle cflags that are set in VariableFuncs.
Colin Cross0523ba22021-07-14 18:45:05 -0700313 bazelCommonGlobalCflags := append(
Colin Cross33bac242021-07-14 17:03:16 -0700314 commonGlobalCflags,
Jingwen Chenbf61afb2021-05-06 13:31:18 +0000315 []string{
Jingwen Chenbf61afb2021-05-06 13:31:18 +0000316 // Default to zero initialization.
317 "-ftrivial-auto-var-init=zero",
318 "-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang",
319 }...)
Colin Cross0523ba22021-07-14 18:45:05 -0700320 exportedStringListVars.Set("CommonGlobalCflags", bazelCommonGlobalCflags)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700321
Colin Cross0523ba22021-07-14 18:45:05 -0700322 pctx.VariableFunc("CommonGlobalCflags", func(ctx android.PackageVarContext) string {
Colin Cross33bac242021-07-14 17:03:16 -0700323 flags := commonGlobalCflags
Stephen Hines66c8b442019-06-10 17:40:12 -0700324
325 // http://b/131390872
326 // Automatically initialize any uninitialized stack variables.
Stephen Hines5c873ac2020-05-14 00:59:09 +0000327 // Prefer zero-init if multiple options are set.
Stephen Hines66c8b442019-06-10 17:40:12 -0700328 if ctx.Config().IsEnvTrue("AUTO_ZERO_INITIALIZE") {
329 flags = append(flags, "-ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang")
330 } else if ctx.Config().IsEnvTrue("AUTO_PATTERN_INITIALIZE") {
331 flags = append(flags, "-ftrivial-auto-var-init=pattern")
Stephen Hines797e1952020-01-28 14:43:11 -0800332 } else if ctx.Config().IsEnvTrue("AUTO_UNINITIALIZE") {
333 flags = append(flags, "-ftrivial-auto-var-init=uninitialized")
Stephen Hines0e1d5d82020-01-30 15:06:00 -0800334 } else {
Stephen Hines5c873ac2020-05-14 00:59:09 +0000335 // Default to zero initialization.
336 flags = append(flags, "-ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang")
Stephen Hines66c8b442019-06-10 17:40:12 -0700337 }
Yi Kong62e75f52021-08-18 15:38:20 +0800338
339 // Workaround for ccache with clang.
340 // See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html.
341 if ctx.Config().IsEnvTrue("USE_CCACHE") {
342 flags = append(flags, "-Wno-unused-command-line-argument")
343 }
Stephen Hines66c8b442019-06-10 17:40:12 -0700344 return strings.Join(flags, " ")
345 })
346
Colin Cross0523ba22021-07-14 18:45:05 -0700347 // Export the static default DeviceGlobalCflags to Bazel.
Jingwen Chenbf61afb2021-05-06 13:31:18 +0000348 // TODO(187086342): handle cflags that are set in VariableFuncs.
Colin Cross0523ba22021-07-14 18:45:05 -0700349 exportedStringListVars.Set("DeviceGlobalCflags", deviceGlobalCflags)
Jingwen Chenbf61afb2021-05-06 13:31:18 +0000350
Colin Cross0523ba22021-07-14 18:45:05 -0700351 pctx.VariableFunc("DeviceGlobalCflags", func(ctx android.PackageVarContext) string {
Colin Crossc8bed312021-07-14 17:56:21 -0700352 return strings.Join(deviceGlobalCflags, " ")
Doug Hornc32c6b02019-01-17 14:44:05 -0800353 })
Colin Cross4d9c2d12016-07-29 12:48:20 -0700354
Colin Cross0523ba22021-07-14 18:45:05 -0700355 exportStringListStaticVariable("HostGlobalCflags", hostGlobalCflags)
356 exportStringListStaticVariable("NoOverrideGlobalCflags", noOverrideGlobalCflags)
Stephen Hinese24303f2021-12-14 15:07:08 -0800357 exportStringListStaticVariable("NoOverrideExternalGlobalCflags", noOverrideExternalGlobalCflags)
Colin Cross0523ba22021-07-14 18:45:05 -0700358 exportStringListStaticVariable("CommonGlobalCppflags", commonGlobalCppflags)
359 exportStringListStaticVariable("ExternalCflags", extraExternalCflags)
Yi Kongcc80f8d2018-06-06 14:42:44 -0700360
Colin Cross1cfd89a2016-09-15 09:30:46 -0700361 // Everything in these lists is a crime against abstraction and dependency tracking.
Colin Cross4d9c2d12016-07-29 12:48:20 -0700362 // Do not add anything to this list.
Jingwen Chen21999952021-05-19 05:53:51 +0000363 commonGlobalIncludes := []string{
364 "system/core/include",
365 "system/logging/liblog/include",
366 "system/media/audio/include",
367 "hardware/libhardware/include",
368 "hardware/libhardware_legacy/include",
369 "hardware/ril/include",
370 "frameworks/native/include",
371 "frameworks/native/opengl/include",
372 "frameworks/av/include",
373 }
Jingwen Chen51a1e1c2021-05-20 13:40:14 +0000374 exportedStringListVars.Set("CommonGlobalIncludes", commonGlobalIncludes)
Jingwen Chen21999952021-05-19 05:53:51 +0000375 pctx.PrefixedExistentPathsForSourcesVariable("CommonGlobalIncludes", "-I", commonGlobalIncludes)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700376
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa38e5182021-08-12 21:37:35 +0000377 exportStringStaticVariable("CLANG_DEFAULT_VERSION", ClangDefaultVersion)
378 exportStringStaticVariable("CLANG_DEFAULT_SHORT_VERSION", ClangDefaultShortVersion)
379
Dan Willemsen9fe14102021-07-13 21:52:04 -0700380 pctx.StaticVariableWithEnvOverride("ClangBase", "LLVM_PREBUILTS_BASE", ClangDefaultBase)
381 pctx.StaticVariableWithEnvOverride("ClangVersion", "LLVM_PREBUILTS_VERSION", ClangDefaultVersion)
Colin Crossb98c8b02016-07-29 13:44:28 -0700382 pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}")
383 pctx.StaticVariable("ClangBin", "${ClangPath}/bin")
384
Dan Willemsen9fe14102021-07-13 21:52:04 -0700385 pctx.StaticVariableWithEnvOverride("ClangShortVersion", "LLVM_RELEASE_VERSION", ClangDefaultShortVersion)
Stephen Hines755fe072018-01-24 19:58:36 -0800386 pctx.StaticVariable("ClangAsanLibDir", "${ClangBase}/linux-x86/${ClangVersion}/lib64/clang/${ClangShortVersion}/lib/linux")
Alistair Strachan777475c2016-08-26 12:55:49 -0700387
Jayant Chowdharye622d202017-02-01 19:19:52 -0800388 // These are tied to the version of LLVM directly in external/llvm, so they might trail the host prebuilts
389 // being used for the rest of the build process.
390 pctx.SourcePathVariable("RSClangBase", "prebuilts/clang/host")
391 pctx.SourcePathVariable("RSClangVersion", "clang-3289846")
392 pctx.SourcePathVariable("RSReleaseVersion", "3.8")
393 pctx.StaticVariable("RSLLVMPrebuiltsPath", "${RSClangBase}/${HostPrebuiltTag}/${RSClangVersion}/bin")
394 pctx.StaticVariable("RSIncludePath", "${RSLLVMPrebuiltsPath}/../lib64/clang/${RSReleaseVersion}/include")
395
Jeff Gaston734e3802017-04-10 15:47:24 -0700396 pctx.PrefixedExistentPathsForSourcesVariable("RsGlobalIncludes", "-I",
Colin Cross2a252be2017-05-01 17:37:24 -0700397 []string{
398 "external/clang/lib/Headers",
399 "frameworks/rs/script_api/include",
400 })
401
Dan Willemsen54daaf02018-03-12 13:24:09 -0700402 pctx.VariableFunc("CcWrapper", func(ctx android.PackageVarContext) string {
403 if override := ctx.Config().Getenv("CC_WRAPPER"); override != "" {
404 return override + " "
Alistair Strachan777475c2016-08-26 12:55:49 -0700405 }
Dan Willemsen54daaf02018-03-12 13:24:09 -0700406 return ""
Alistair Strachan777475c2016-08-26 12:55:49 -0700407 })
Ramy Medhat9a90fe52020-04-13 13:21:23 -0400408
Colin Cross77cdcfd2021-03-12 11:28:25 -0800409 pctx.StaticVariableWithEnvOverride("RECXXPool", "RBE_CXX_POOL", remoteexec.DefaultPool)
410 pctx.StaticVariableWithEnvOverride("RECXXLinksPool", "RBE_CXX_LINKS_POOL", remoteexec.DefaultPool)
411 pctx.StaticVariableWithEnvOverride("REClangTidyPool", "RBE_CLANG_TIDY_POOL", remoteexec.DefaultPool)
412 pctx.StaticVariableWithEnvOverride("RECXXLinksExecStrategy", "RBE_CXX_LINKS_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
413 pctx.StaticVariableWithEnvOverride("REClangTidyExecStrategy", "RBE_CLANG_TIDY_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
414 pctx.StaticVariableWithEnvOverride("REAbiDumperExecStrategy", "RBE_ABI_DUMPER_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
415 pctx.StaticVariableWithEnvOverride("REAbiLinkerExecStrategy", "RBE_ABI_LINKER_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700416}
417
Chris Parsons3b1f83d2021-10-14 14:08:38 -0400418var HostPrebuiltTag = exportVariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
Dan Willemsen9fe14102021-07-13 21:52:04 -0700419
420func ClangPath(ctx android.PathContext, file string) android.SourcePath {
421 type clangToolKey string
422
423 key := android.NewCustomOnceKey(clangToolKey(file))
424
425 return ctx.Config().OnceSourcePath(key, func() android.SourcePath {
426 return clangPath(ctx).Join(ctx, file)
427 })
428}
429
430var clangPathKey = android.NewOnceKey("clangPath")
431
432func clangPath(ctx android.PathContext) android.SourcePath {
433 return ctx.Config().OnceSourcePath(clangPathKey, func() android.SourcePath {
434 clangBase := ClangDefaultBase
435 if override := ctx.Config().Getenv("LLVM_PREBUILTS_BASE"); override != "" {
436 clangBase = override
437 }
438 clangVersion := ClangDefaultVersion
439 if override := ctx.Config().Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
440 clangVersion = override
441 }
442 return android.PathForSource(ctx, clangBase, ctx.Config().PrebuiltOS(), clangVersion)
443 })
444}