blob: 7f2c23e4a29735382eab35d232bfd9fb48a17bd9 [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",
49
50 "-fno-strict-aliasing",
Dan Willemsen5d980c82019-08-27 19:37:10 -070051
52 "-Werror=date-time",
Elliott Hughes2cdbdf12019-12-03 18:13:00 -080053 "-Werror=pragma-pack",
54 "-Werror=pragma-pack-suspicious-include",
Christopher Di Bella23a991c2020-11-11 22:41:32 +000055 "-Werror=string-plus-int",
George Burgess IVfb81db22020-02-22 19:28:56 -080056 "-Werror=unreachable-code-loop-increment",
Colin Cross9cc59c12021-07-14 17:59:54 -070057
58 "-D__compiler_offsetof=__builtin_offsetof",
59
60 // Emit address-significance table which allows linker to perform safe ICF. Clang does
61 // not emit the table by default on Android since NDK still uses GNU binutils.
62 "-faddrsig",
63
64 // Turn on -fcommon explicitly, since Clang now defaults to -fno-common. The cleanup bug
65 // tracking this is http://b/151457797.
66 "-fcommon",
67
68 // Help catch common 32/64-bit errors.
69 "-Werror=int-conversion",
70
71 // Enable the new pass manager.
72 "-fexperimental-new-pass-manager",
73
74 // Disable overly aggressive warning for macros defined with a leading underscore
75 // This happens in AndroidConfig.h, which is included nearly everywhere.
76 // TODO: can we remove this now?
77 "-Wno-reserved-id-macro",
78
Colin Cross9cc59c12021-07-14 17:59:54 -070079 // Force clang to always output color diagnostics. Ninja will strip the ANSI
80 // color codes if it is not running in a terminal.
81 "-fcolor-diagnostics",
82
83 // Warnings from clang-7.0
84 "-Wno-sign-compare",
85
86 // Warnings from clang-8.0
87 "-Wno-defaulted-function-deleted",
88
89 // Disable -Winconsistent-missing-override until we can clean up the existing
90 // codebase for it.
91 "-Wno-inconsistent-missing-override",
92
93 // Warnings from clang-10
94 // Nested and array designated initialization is nice to have.
95 "-Wno-c99-designator",
96
97 // Warnings from clang-12
98 "-Wno-gnu-folding-constant",
99
100 // Calls to the APIs that are newer than the min sdk version of the caller should be
101 // guarded with __builtin_available.
102 "-Wunguarded-availability",
103 // This macro allows the bionic versioning.h to indirectly determine whether the
104 // option -Wunguarded-availability is on or not.
105 "-D__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700106 }
107
Colin Cross6f6a4282016-10-17 14:19:06 -0700108 commonGlobalConlyflags = []string{}
Elliott Hughes5a0401a2016-10-07 13:12:58 -0700109
Colin Cross4d9c2d12016-07-29 12:48:20 -0700110 deviceGlobalCflags = []string{
Colin Cross133dbe72017-11-02 22:55:19 -0700111 "-ffunction-sections",
Colin Crossea3141d2017-11-06 14:02:02 -0800112 "-fdata-sections",
113 "-fno-short-enums",
Colin Cross133dbe72017-11-02 22:55:19 -0700114 "-funwind-tables",
115 "-fstack-protector-strong",
116 "-Wa,--noexecstack",
117 "-D_FORTIFY_SOURCE=2",
118
119 "-Wstrict-aliasing=2",
120
Colin Cross4d9c2d12016-07-29 12:48:20 -0700121 "-Werror=return-type",
122 "-Werror=non-virtual-dtor",
123 "-Werror=address",
124 "-Werror=sequence-point",
Colin Cross133dbe72017-11-02 22:55:19 -0700125 "-Werror=format-security",
Colin Crossc8bed312021-07-14 17:56:21 -0700126 "-nostdlibinc",
Yi Kong196b9262021-12-07 13:51:38 +0800127
128 // Emit additional debug info for AutoFDO
129 "-fdebug-info-for-profiling",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700130 }
131
Colin Cross26f14502017-11-06 13:59:48 -0800132 deviceGlobalCppflags = []string{
133 "-fvisibility-inlines-hidden",
134 }
135
Colin Cross324a4572017-11-02 23:09:41 -0700136 deviceGlobalLdflags = []string{
137 "-Wl,-z,noexecstack",
138 "-Wl,-z,relro",
139 "-Wl,-z,now",
140 "-Wl,--build-id=md5",
141 "-Wl,--warn-shared-textrel",
142 "-Wl,--fatal-warnings",
143 "-Wl,--no-undefined-version",
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800144 // TODO: Eventually we should link against a libunwind.a with hidden symbols, and then these
145 // --exclude-libs arguments can be removed.
Christopher Ferrisc3a1e222019-04-10 17:57:50 -0700146 "-Wl,--exclude-libs,libgcc.a",
Yi Kong3d8792f2019-05-06 16:18:33 -0700147 "-Wl,--exclude-libs,libgcc_stripped.a",
Peter Collingbournee5ba2862019-12-10 18:37:45 -0800148 "-Wl,--exclude-libs,libunwind_llvm.a",
Ryan Prichardb35a85e2021-01-13 19:18:53 -0800149 "-Wl,--exclude-libs,libunwind.a",
Ryo Hashimoto5818b932021-03-23 15:05:22 +0900150 "-Wl,--icf=safe",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700151 }
152
Colin Cross33bac242021-07-14 17:03:16 -0700153 deviceGlobalLldflags = append(deviceGlobalLdflags,
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700154 []string{
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700155 "-fuse-ld=lld",
156 }...)
157
Colin Cross4d9c2d12016-07-29 12:48:20 -0700158 hostGlobalCflags = []string{}
159
Colin Cross26f14502017-11-06 13:59:48 -0800160 hostGlobalCppflags = []string{}
161
Colin Cross324a4572017-11-02 23:09:41 -0700162 hostGlobalLdflags = []string{}
163
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700164 hostGlobalLldflags = []string{"-fuse-ld=lld"}
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700165
Colin Cross4d9c2d12016-07-29 12:48:20 -0700166 commonGlobalCppflags = []string{
167 "-Wsign-promo",
Colin Crossc8bed312021-07-14 17:56:21 -0700168
169 // -Wimplicit-fallthrough is not enabled by -Wall.
170 "-Wimplicit-fallthrough",
171
172 // Enable clang's thread-safety annotations in libcxx.
173 "-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS",
174
175 // libc++'s math.h has an #include_next outside of system_headers.
176 "-Wno-gnu-include-next",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700177 }
178
179 noOverrideGlobalCflags = []string{
Christopher Di Bella23a991c2020-11-11 22:41:32 +0000180 "-Werror=bool-operation",
181 "-Werror=implicit-int-float-conversion",
182 "-Werror=int-in-bool-context",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700183 "-Werror=int-to-pointer-cast",
184 "-Werror=pointer-to-int-cast",
Christopher Di Bella23a991c2020-11-11 22:41:32 +0000185 "-Werror=string-compare",
186 "-Werror=xor-used-as-pow",
Stephen Hines2210e722020-07-15 11:11:57 -0700187 // http://b/161386391 for -Wno-void-pointer-to-enum-cast
188 "-Wno-void-pointer-to-enum-cast",
189 // http://b/161386391 for -Wno-void-pointer-to-int-cast
190 "-Wno-void-pointer-to-int-cast",
191 // http://b/161386391 for -Wno-pointer-to-int-cast
192 "-Wno-pointer-to-int-cast",
George Burgess IV6c691642019-09-18 17:52:05 -0700193 "-Werror=fortify-source",
Colin Crossc8bed312021-07-14 17:56:21 -0700194
195 "-Werror=address-of-temporary",
196 // Bug: http://b/29823425 Disable -Wnull-dereference until the
197 // new cases detected by this warning in Clang r271374 are
198 // fixed.
199 //"-Werror=null-dereference",
200 "-Werror=return-type",
201
202 // http://b/72331526 Disable -Wtautological-* until the instances detected by these
203 // new warnings are fixed.
204 "-Wno-tautological-constant-compare",
205 "-Wno-tautological-type-limit-compare",
206 // http://b/145210666
207 "-Wno-reorder-init-list",
208 // http://b/145211066
209 "-Wno-implicit-int-float-conversion",
210 // New warnings to be fixed after clang-r377782.
211 "-Wno-int-in-bool-context", // http://b/148287349
212 "-Wno-sizeof-array-div", // http://b/148815709
213 "-Wno-tautological-overlap-compare", // http://b/148815696
214 // New warnings to be fixed after clang-r383902.
215 "-Wno-deprecated-copy", // http://b/153746672
216 "-Wno-range-loop-construct", // http://b/153747076
217 "-Wno-misleading-indentation", // http://b/153746954
218 "-Wno-zero-as-null-pointer-constant", // http://b/68236239
219 "-Wno-deprecated-anon-enum-enum-conversion", // http://b/153746485
220 "-Wno-deprecated-enum-enum-conversion", // http://b/153746563
221 "-Wno-string-compare", // http://b/153764102
222 "-Wno-enum-enum-conversion", // http://b/154138986
223 "-Wno-enum-float-conversion", // http://b/154255917
224 "-Wno-pessimizing-move", // http://b/154270751
225 // New warnings to be fixed after clang-r399163
226 "-Wno-non-c-typedef-for-linkage", // http://b/161304145
Yabin Cui10bf3b82021-08-10 15:42:10 +0000227 // New warnings to be fixed after clang-r428724
228 "-Wno-align-mismatch", // http://b/193679946
Yi Konge8273292021-08-31 14:04:18 +0800229 // New warnings to be fixed after clang-r433403
230 "-Wno-error=unused-but-set-variable", // http://b/197240255
231 "-Wno-error=unused-but-set-parameter", // http://b/197240255
Colin Crossc8bed312021-07-14 17:56:21 -0700232 }
233
Stephen Hinese24303f2021-12-14 15:07:08 -0800234 noOverrideExternalGlobalCflags = []string{
235 // http://b/197240255
236 "-Wno-unused-but-set-variable",
237 "-Wno-unused-but-set-parameter",
238 }
239
Colin Crossc8bed312021-07-14 17:56:21 -0700240 // Extra cflags for external third-party projects to disable warnings that
241 // are infeasible to fix in all the external projects and their upstream repos.
242 extraExternalCflags = []string{
243 "-Wno-enum-compare",
244 "-Wno-enum-compare-switch",
245
246 // http://b/72331524 Allow null pointer arithmetic until the instances detected by
247 // this new warning are fixed.
248 "-Wno-null-pointer-arithmetic",
249
250 // Bug: http://b/29823425 Disable -Wnull-dereference until the
251 // new instances detected by this warning are fixed.
252 "-Wno-null-dereference",
253
254 // http://b/145211477
255 "-Wno-pointer-compare",
256 // http://b/145211022
257 "-Wno-xor-used-as-pow",
258 // http://b/145211022
259 "-Wno-final-dtor-non-final-class",
260
261 // http://b/165945989
262 "-Wno-psabi",
Yi Konge8273292021-08-31 14:04:18 +0800263
264 // http://b/199369603
265 "-Wno-null-pointer-subtraction",
Yi Kong9feb0292021-12-15 13:20:27 +0800266
267 // http://b/175068488
268 "-Wno-string-concatenation",
Colin Cross4d9c2d12016-07-29 12:48:20 -0700269 }
270
Colin Crossb98c8b02016-07-29 13:44:28 -0700271 IllegalFlags = []string{
Colin Cross4d9c2d12016-07-29 12:48:20 -0700272 "-w",
273 }
Colin Cross6f6a4282016-10-17 14:19:06 -0700274
Dan Albert043833c2017-02-03 16:13:38 -0800275 CStdVersion = "gnu99"
Elliott Hughes34e4e412018-11-30 16:03:06 +0000276 CppStdVersion = "gnu++17"
Dan Albert043833c2017-02-03 16:13:38 -0800277 ExperimentalCStdVersion = "gnu11"
Elliott Hughes37976122018-11-28 14:16:39 -0800278 ExperimentalCppStdVersion = "gnu++2a"
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -0700279
Leo Li8756b372017-05-22 16:11:34 -0700280 // prebuilts/clang default settings.
281 ClangDefaultBase = "prebuilts/clang/host"
Chih-hung Hsieh933e7012021-11-17 22:52:12 +0000282 ClangDefaultVersion = "clang-r437112"
283 ClangDefaultShortVersion = "14.0.0"
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800284
Chih-Hung Hsieh775edde2017-12-24 22:24:47 -0800285 // Directories with warnings from Android.bp files.
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800286 WarningAllowedProjects = []string{
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800287 "device/",
Chih-Hung Hsieh64a38dc2017-11-14 14:09:14 -0800288 "vendor/",
289 }
290
Chih-Hung Hsieh775edde2017-12-24 22:24:47 -0800291 // Directories with warnings from Android.mk files.
292 WarningAllowedOldProjects = []string{}
Colin Cross4d9c2d12016-07-29 12:48:20 -0700293)
294
Colin Crossb98c8b02016-07-29 13:44:28 -0700295var pctx = android.NewPackageContext("android/soong/cc/config")
296
Colin Cross4d9c2d12016-07-29 12:48:20 -0700297func init() {
Colin Cross0c66bc62021-07-20 09:47:41 -0700298 if runtime.GOOS == "linux" {
Kousik Kumard207cbe2020-10-20 05:52:49 +0000299 commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
300 }
301
Jingwen Chen51a1e1c2021-05-20 13:40:14 +0000302 exportStringListStaticVariable("CommonGlobalConlyflags", commonGlobalConlyflags)
303 exportStringListStaticVariable("DeviceGlobalCppflags", deviceGlobalCppflags)
304 exportStringListStaticVariable("DeviceGlobalLdflags", deviceGlobalLdflags)
305 exportStringListStaticVariable("DeviceGlobalLldflags", deviceGlobalLldflags)
306 exportStringListStaticVariable("HostGlobalCppflags", hostGlobalCppflags)
307 exportStringListStaticVariable("HostGlobalLdflags", hostGlobalLdflags)
308 exportStringListStaticVariable("HostGlobalLldflags", hostGlobalLldflags)
Jingwen Chenbf61afb2021-05-06 13:31:18 +0000309
Colin Cross0523ba22021-07-14 18:45:05 -0700310 // Export the static default CommonGlobalCflags to Bazel.
Jingwen Chenbf61afb2021-05-06 13:31:18 +0000311 // TODO(187086342): handle cflags that are set in VariableFuncs.
Colin Cross0523ba22021-07-14 18:45:05 -0700312 bazelCommonGlobalCflags := append(
Colin Cross33bac242021-07-14 17:03:16 -0700313 commonGlobalCflags,
Jingwen Chenbf61afb2021-05-06 13:31:18 +0000314 []string{
Jingwen Chenbf61afb2021-05-06 13:31:18 +0000315 // Default to zero initialization.
316 "-ftrivial-auto-var-init=zero",
317 "-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang",
318 }...)
Colin Cross0523ba22021-07-14 18:45:05 -0700319 exportedStringListVars.Set("CommonGlobalCflags", bazelCommonGlobalCflags)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700320
Colin Cross0523ba22021-07-14 18:45:05 -0700321 pctx.VariableFunc("CommonGlobalCflags", func(ctx android.PackageVarContext) string {
Colin Cross33bac242021-07-14 17:03:16 -0700322 flags := commonGlobalCflags
Stephen Hines66c8b442019-06-10 17:40:12 -0700323
324 // http://b/131390872
325 // Automatically initialize any uninitialized stack variables.
Stephen Hines5c873ac2020-05-14 00:59:09 +0000326 // Prefer zero-init if multiple options are set.
Stephen Hines66c8b442019-06-10 17:40:12 -0700327 if ctx.Config().IsEnvTrue("AUTO_ZERO_INITIALIZE") {
328 flags = append(flags, "-ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang")
329 } else if ctx.Config().IsEnvTrue("AUTO_PATTERN_INITIALIZE") {
330 flags = append(flags, "-ftrivial-auto-var-init=pattern")
Stephen Hines797e1952020-01-28 14:43:11 -0800331 } else if ctx.Config().IsEnvTrue("AUTO_UNINITIALIZE") {
332 flags = append(flags, "-ftrivial-auto-var-init=uninitialized")
Stephen Hines0e1d5d82020-01-30 15:06:00 -0800333 } else {
Stephen Hines5c873ac2020-05-14 00:59:09 +0000334 // Default to zero initialization.
335 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 -0700336 }
Yi Kong62e75f52021-08-18 15:38:20 +0800337
338 // Workaround for ccache with clang.
339 // See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html.
340 if ctx.Config().IsEnvTrue("USE_CCACHE") {
341 flags = append(flags, "-Wno-unused-command-line-argument")
342 }
Stephen Hines66c8b442019-06-10 17:40:12 -0700343 return strings.Join(flags, " ")
344 })
345
Colin Cross0523ba22021-07-14 18:45:05 -0700346 // Export the static default DeviceGlobalCflags to Bazel.
Jingwen Chenbf61afb2021-05-06 13:31:18 +0000347 // TODO(187086342): handle cflags that are set in VariableFuncs.
Colin Cross0523ba22021-07-14 18:45:05 -0700348 exportedStringListVars.Set("DeviceGlobalCflags", deviceGlobalCflags)
Jingwen Chenbf61afb2021-05-06 13:31:18 +0000349
Colin Cross0523ba22021-07-14 18:45:05 -0700350 pctx.VariableFunc("DeviceGlobalCflags", func(ctx android.PackageVarContext) string {
Colin Crossc8bed312021-07-14 17:56:21 -0700351 return strings.Join(deviceGlobalCflags, " ")
Doug Hornc32c6b02019-01-17 14:44:05 -0800352 })
Colin Cross4d9c2d12016-07-29 12:48:20 -0700353
Colin Cross0523ba22021-07-14 18:45:05 -0700354 exportStringListStaticVariable("HostGlobalCflags", hostGlobalCflags)
355 exportStringListStaticVariable("NoOverrideGlobalCflags", noOverrideGlobalCflags)
Stephen Hinese24303f2021-12-14 15:07:08 -0800356 exportStringListStaticVariable("NoOverrideExternalGlobalCflags", noOverrideExternalGlobalCflags)
Colin Cross0523ba22021-07-14 18:45:05 -0700357 exportStringListStaticVariable("CommonGlobalCppflags", commonGlobalCppflags)
358 exportStringListStaticVariable("ExternalCflags", extraExternalCflags)
Yi Kongcc80f8d2018-06-06 14:42:44 -0700359
Colin Cross1cfd89a2016-09-15 09:30:46 -0700360 // Everything in these lists is a crime against abstraction and dependency tracking.
Colin Cross4d9c2d12016-07-29 12:48:20 -0700361 // Do not add anything to this list.
Jingwen Chen21999952021-05-19 05:53:51 +0000362 commonGlobalIncludes := []string{
363 "system/core/include",
364 "system/logging/liblog/include",
365 "system/media/audio/include",
366 "hardware/libhardware/include",
367 "hardware/libhardware_legacy/include",
368 "hardware/ril/include",
369 "frameworks/native/include",
370 "frameworks/native/opengl/include",
371 "frameworks/av/include",
372 }
Jingwen Chen51a1e1c2021-05-20 13:40:14 +0000373 exportedStringListVars.Set("CommonGlobalIncludes", commonGlobalIncludes)
Jingwen Chen21999952021-05-19 05:53:51 +0000374 pctx.PrefixedExistentPathsForSourcesVariable("CommonGlobalIncludes", "-I", commonGlobalIncludes)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700375
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxa38e5182021-08-12 21:37:35 +0000376 exportStringStaticVariable("CLANG_DEFAULT_VERSION", ClangDefaultVersion)
377 exportStringStaticVariable("CLANG_DEFAULT_SHORT_VERSION", ClangDefaultShortVersion)
378
Dan Willemsen9fe14102021-07-13 21:52:04 -0700379 pctx.StaticVariableWithEnvOverride("ClangBase", "LLVM_PREBUILTS_BASE", ClangDefaultBase)
380 pctx.StaticVariableWithEnvOverride("ClangVersion", "LLVM_PREBUILTS_VERSION", ClangDefaultVersion)
Colin Crossb98c8b02016-07-29 13:44:28 -0700381 pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}")
382 pctx.StaticVariable("ClangBin", "${ClangPath}/bin")
383
Dan Willemsen9fe14102021-07-13 21:52:04 -0700384 pctx.StaticVariableWithEnvOverride("ClangShortVersion", "LLVM_RELEASE_VERSION", ClangDefaultShortVersion)
Stephen Hines755fe072018-01-24 19:58:36 -0800385 pctx.StaticVariable("ClangAsanLibDir", "${ClangBase}/linux-x86/${ClangVersion}/lib64/clang/${ClangShortVersion}/lib/linux")
Alistair Strachan777475c2016-08-26 12:55:49 -0700386
Jayant Chowdharye622d202017-02-01 19:19:52 -0800387 // These are tied to the version of LLVM directly in external/llvm, so they might trail the host prebuilts
388 // being used for the rest of the build process.
389 pctx.SourcePathVariable("RSClangBase", "prebuilts/clang/host")
390 pctx.SourcePathVariable("RSClangVersion", "clang-3289846")
391 pctx.SourcePathVariable("RSReleaseVersion", "3.8")
392 pctx.StaticVariable("RSLLVMPrebuiltsPath", "${RSClangBase}/${HostPrebuiltTag}/${RSClangVersion}/bin")
393 pctx.StaticVariable("RSIncludePath", "${RSLLVMPrebuiltsPath}/../lib64/clang/${RSReleaseVersion}/include")
394
Jeff Gaston734e3802017-04-10 15:47:24 -0700395 pctx.PrefixedExistentPathsForSourcesVariable("RsGlobalIncludes", "-I",
Colin Cross2a252be2017-05-01 17:37:24 -0700396 []string{
397 "external/clang/lib/Headers",
398 "frameworks/rs/script_api/include",
399 })
400
Dan Willemsen54daaf02018-03-12 13:24:09 -0700401 pctx.VariableFunc("CcWrapper", func(ctx android.PackageVarContext) string {
402 if override := ctx.Config().Getenv("CC_WRAPPER"); override != "" {
403 return override + " "
Alistair Strachan777475c2016-08-26 12:55:49 -0700404 }
Dan Willemsen54daaf02018-03-12 13:24:09 -0700405 return ""
Alistair Strachan777475c2016-08-26 12:55:49 -0700406 })
Ramy Medhat9a90fe52020-04-13 13:21:23 -0400407
Colin Cross77cdcfd2021-03-12 11:28:25 -0800408 pctx.StaticVariableWithEnvOverride("RECXXPool", "RBE_CXX_POOL", remoteexec.DefaultPool)
409 pctx.StaticVariableWithEnvOverride("RECXXLinksPool", "RBE_CXX_LINKS_POOL", remoteexec.DefaultPool)
410 pctx.StaticVariableWithEnvOverride("REClangTidyPool", "RBE_CLANG_TIDY_POOL", remoteexec.DefaultPool)
411 pctx.StaticVariableWithEnvOverride("RECXXLinksExecStrategy", "RBE_CXX_LINKS_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
412 pctx.StaticVariableWithEnvOverride("REClangTidyExecStrategy", "RBE_CLANG_TIDY_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
413 pctx.StaticVariableWithEnvOverride("REAbiDumperExecStrategy", "RBE_ABI_DUMPER_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
414 pctx.StaticVariableWithEnvOverride("REAbiLinkerExecStrategy", "RBE_ABI_LINKER_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700415}
416
Chris Parsons3b1f83d2021-10-14 14:08:38 -0400417var HostPrebuiltTag = exportVariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
Dan Willemsen9fe14102021-07-13 21:52:04 -0700418
419func ClangPath(ctx android.PathContext, file string) android.SourcePath {
420 type clangToolKey string
421
422 key := android.NewCustomOnceKey(clangToolKey(file))
423
424 return ctx.Config().OnceSourcePath(key, func() android.SourcePath {
425 return clangPath(ctx).Join(ctx, file)
426 })
427}
428
429var clangPathKey = android.NewOnceKey("clangPath")
430
431func clangPath(ctx android.PathContext) android.SourcePath {
432 return ctx.Config().OnceSourcePath(clangPathKey, func() android.SourcePath {
433 clangBase := ClangDefaultBase
434 if override := ctx.Config().Getenv("LLVM_PREBUILTS_BASE"); override != "" {
435 clangBase = override
436 }
437 clangVersion := ClangDefaultVersion
438 if override := ctx.Config().Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
439 clangVersion = override
440 }
441 return android.PathForSource(ctx, clangBase, ctx.Config().PrebuiltOS(), clangVersion)
442 })
443}