1package {
2    // See: http://go/android-license-faq
3    // A large-scale-change added 'default_applicable_licenses' to import
4    // all of the 'license_kinds' from "art_license"
5    // to get the below license kinds:
6    //   SPDX-license-identifier-Apache-2.0
7    default_applicable_licenses: ["art_license"],
8}
9
10bootstrap_go_package {
11    name: "soong-art",
12    pkgPath: "android/soong/art",
13    deps: [
14        "blueprint",
15        "blueprint-pathtools",
16        "blueprint-proptools",
17        "soong",
18        "soong-android",
19        "soong-apex",
20        "soong-cc",
21    ],
22    srcs: [
23        "art.go",
24        "codegen.go",
25        "makevars.go",
26    ],
27    pluginFor: ["soong_build"],
28}
29
30art_clang_tidy_errors = [
31    "android-cloexec-dup",
32    "android-cloexec-open",
33    "bugprone-argument-comment",
34    "bugprone-lambda-function-name",
35    "bugprone-unused-raii", // Protect scoped things like MutexLock.
36    "bugprone-unused-return-value",
37    "bugprone-virtual-near-miss",
38    "modernize-use-bool-literals",
39    "modernize-use-nullptr",
40    "modernize-use-using",
41    "performance-faster-string-find",
42    "performance-for-range-copy",
43    "performance-implicit-conversion-in-loop",
44    "performance-noexcept-move-constructor",
45    "performance-unnecessary-copy-initialization",
46    "performance-unnecessary-value-param",
47    "misc-unused-using-decls",
48]
49
50art_clang_tidy_disabled = [
51    "-google-default-arguments",
52    // We have local stores that are only used for debug checks.
53    "-clang-analyzer-deadcode.DeadStores",
54    // We are OK with some static globals and that they can, in theory, throw.
55    "-cert-err58-cpp",
56    // We have lots of C-style variadic functions, and are OK with them. JNI ensures
57    // that working around this warning would be extra-painful.
58    "-cert-dcl50-cpp",
59    // "Modernization" we don't agree with.
60    "-modernize-use-auto",
61    "-modernize-return-braced-init-list",
62    "-modernize-use-default-member-init",
63    "-modernize-pass-by-value",
64]
65
66soong_config_module_type_import {
67    from: "art/build/SoongConfig.bp",
68    module_types: [
69        "art_module_art_global_defaults",
70        "art_module_cc_defaults",
71        "art_module_java_defaults",
72    ],
73}
74
75art_module_art_global_defaults {
76    // Additional flags are computed by art.go
77
78    name: "art_defaults",
79
80    // Disable all ART Soong modules by default when ART prebuilts are in use.
81    // TODO(b/172480617): Clean up when sources are gone from the platform tree
82    // and we no longer need to support sources present when prebuilts are used.
83    enabled: false,
84    soong_config_variables: {
85        source_build: {
86            enabled: true,
87        },
88    },
89
90    // This is the default visibility for the //art package, but we repeat it
91    // here so that it gets merged with other visibility rules in modules
92    // extending these defaults.
93    visibility: ["//art:__subpackages__"],
94
95    cflags: [
96        // Base set of cflags used by all things ART.
97        "-fno-rtti",
98        "-ggdb3",
99        "-Wall",
100        "-Werror",
101        "-Wextra",
102        "-Wstrict-aliasing",
103        "-fstrict-aliasing",
104        "-Wunreachable-code",
105        "-Wredundant-decls",
106        "-Wshadow",
107        "-Wunused",
108        "-fvisibility=protected",
109
110        // Warn about thread safety violations with clang.
111        "-Wthread-safety",
112        // TODO(b/144045034): turn on -Wthread-safety-negative
113        //"-Wthread-safety-negative",
114
115        // Warn if switch fallthroughs aren't annotated.
116        "-Wimplicit-fallthrough",
117
118        // Enable float equality warnings.
119        "-Wfloat-equal",
120
121        // Enable warning of converting ints to void*.
122        "-Wint-to-void-pointer-cast",
123
124        // Enable warning of wrong unused annotations.
125        "-Wused-but-marked-unused",
126
127        // Enable warning for deprecated language features.
128        "-Wdeprecated",
129
130        // Enable warning for unreachable break & return.
131        "-Wunreachable-code-break",
132        "-Wunreachable-code-return",
133
134        // Disable warning for use of offsetof on non-standard layout type.
135        // We use it to implement OFFSETOF_MEMBER - see macros.h.
136        "-Wno-invalid-offsetof",
137
138        // Enable inconsistent-missing-override warning. This warning is disabled by default in
139        // Android.
140        "-Winconsistent-missing-override",
141
142        // Enable thread annotations for std::mutex, etc.
143        "-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS",
144    ],
145
146    arch: {
147        x86: {
148            avx2: {
149                cflags: [
150                    "-mavx2",
151                    "-mfma",
152                ],
153            },
154        },
155        x86_64: {
156            avx2: {
157                cflags: [
158                    "-mavx2",
159                    "-mfma",
160                ],
161            },
162        },
163    },
164
165    target: {
166        android: {
167            cflags: [
168                // To use oprofile_android --callgraph, uncomment this and recompile with
169                //    mmma -j art
170                // "-fno-omit-frame-pointer",
171                // "-marm",
172                // "-mapcs",
173            ],
174            header_libs: [
175                // We optimize Thread::Current() with a direct TLS access. This requires access to a
176                //  platform specific Bionic header.
177                "bionic_libc_platform_headers",
178            ],
179        },
180        linux: {
181            cflags: [
182                // Enable missing-noreturn only on non-Mac. As lots of things are not implemented for
183                // Apple, it's a pain.
184                "-Wmissing-noreturn",
185            ],
186        },
187        linux_bionic: {
188            header_libs: [
189                // We optimize Thread::Current() with a direct TLS access. This requires access to a
190                //  platform specific Bionic header.
191                "bionic_libc_platform_headers",
192            ],
193            strip: {
194                // Do not strip art libs when building for linux-bionic.
195                // Otherwise we can't get any symbols out of crashes.
196                none: true,
197            },
198        },
199        darwin: {
200            enabled: false,
201        },
202        windows: {
203            // When the module is enabled globally in the soong_config_variables
204            // stanza above, it may get enabled on windows too for some module
205            // types. Hence we need to disable it explicitly.
206            // TODO(b/172480617): Clean up with that.
207            enabled: false,
208        },
209        host: {
210            cflags: [
211                // Bug: 15446488. We don't omit the frame pointer to work around
212                // clang/libunwind bugs that cause SEGVs in run-test-004-ThreadStress.
213                "-fno-omit-frame-pointer",
214                // The build assumes that all our x86/x86_64 hosts (such as buildbots and developer
215                // desktops) support at least sse4.2/popcount. This firstly implies that the ART
216                // runtime binary itself may exploit these features. Secondly, this implies that
217                // the ART runtime passes these feature flags to dex2oat and JIT by calling the
218                // method InstructionSetFeatures::FromCppDefines(). Since invoking dex2oat directly
219                // does not pick up these flags, cross-compiling from a x86/x86_64 host to a
220                // x86/x86_64 target should not be affected.
221                "-msse4.2",
222                "-mpopcnt",
223            ],
224        },
225    },
226
227    codegen: {
228        arm: {
229            cflags: ["-DART_ENABLE_CODEGEN_arm"],
230        },
231        arm64: {
232            cflags: ["-DART_ENABLE_CODEGEN_arm64"],
233        },
234        x86: {
235            cflags: ["-DART_ENABLE_CODEGEN_x86"],
236        },
237        x86_64: {
238            cflags: ["-DART_ENABLE_CODEGEN_x86_64"],
239        },
240    },
241
242    tidy_checks: art_clang_tidy_errors + art_clang_tidy_disabled,
243    tidy_checks_as_errors: art_clang_tidy_errors,
244
245    tidy_flags: [
246        // The static analyzer treats DCHECK as always enabled; we sometimes get
247        // false positives when we use DCHECKs with code that relies on NDEBUG.
248        "-extra-arg=-UNDEBUG",
249        // clang-tidy complains about functions like:
250        // void foo() { CHECK(kIsFooEnabled); /* do foo... */ }
251        // not being marked noreturn if kIsFooEnabled is false.
252        "-extra-arg=-Wno-missing-noreturn",
253        // Because tidy doesn't like our flow checks for compile-time configuration and thinks that
254        // the following code is dead (it is, but not for all configurations), disable unreachable
255        // code detection in Clang for tidy builds. It is still on for regular build steps, so we
256        // will still get the "real" errors.
257        "-extra-arg=-Wno-unreachable-code",
258    ],
259
260    min_sdk_version: "S",
261}
262
263// Used to generate binaries that can be backed by transparent hugepages.
264cc_defaults {
265    name: "art_hugepage_defaults",
266    arch: {
267        arm64: {
268            ldflags: ["-z max-page-size=0x200000"],
269        },
270        x86_64: {
271            ldflags: ["-z max-page-size=0x200000"],
272        },
273    },
274}
275
276cc_defaults {
277    name: "art_pgo_defaults",
278    visibility: ["//art:__subpackages__"],
279    pgo: {
280        sampling: true,
281    },
282    target: {
283        android_arm64: {
284            pgo: {
285                profile_file: "art/art_arm_arm64.profdata",
286            },
287        },
288        android_arm: {
289            pgo: {
290                profile_file: "art/art_arm_arm64.profdata",
291            },
292        },
293        android_x86_64: {
294            pgo: {
295                profile_file: "art/art_x86_x86_64.profdata",
296            },
297        },
298        android_x86: {
299            pgo: {
300                profile_file: "art/art_x86_x86_64.profdata",
301            },
302        },
303    },
304}
305
306art_debug_defaults {
307    name: "art_debug_defaults",
308    visibility: ["//art:__subpackages__"],
309    cflags: [
310        "-DDYNAMIC_ANNOTATIONS_ENABLED=1",
311        "-DVIXL_DEBUG",
312        "-UNDEBUG",
313    ],
314    asflags: [
315        "-UNDEBUG",
316    ],
317    target: {
318        // This has to be duplicated for android and host to make sure it
319        // comes after the -Wframe-larger-than warnings inserted by art.go
320        // target-specific properties
321        android: {
322            cflags: ["-Wno-frame-larger-than="],
323        },
324        host: {
325            cflags: ["-Wno-frame-larger-than="],
326        },
327    },
328
329    min_sdk_version: "S",
330}
331
332// Use this to enable a cc_* module only when building ART from sources.
333// TODO(b/172480617): Clean up when sources are gone from the platform tree and
334// we no longer need to support sources present when prebuilts are used.
335art_module_cc_defaults {
336    name: "art_module_source_build_defaults",
337    defaults_visibility: [
338        "//art:__subpackages__",
339        "//libcore:__subpackages__",
340        "//libnativehelper:__subpackages__",
341    ],
342
343    enabled: false,
344    soong_config_variables: {
345        source_build: {
346            enabled: true,
347        },
348    },
349    target: {
350        windows: {
351            // Windows is disabled by default, but if we set enabled:true
352            // globally above we need to disable it explicitly.
353            enabled: false,
354        },
355    },
356}
357
358// Use this to enable a java_* module only when building ART from sources.
359// TODO(b/172480617): Clean up when sources are gone from the platform tree and
360// we no longer need to support sources present when prebuilts are used.
361art_module_java_defaults {
362    name: "art_module_source_build_java_defaults",
363    defaults_visibility: [
364        "//art:__subpackages__",
365        "//libcore:__subpackages__",
366        "//libnativehelper:__subpackages__",
367    ],
368
369    enabled: false,
370    soong_config_variables: {
371        source_build: {
372            enabled: true,
373        },
374    },
375    target: {
376        windows: {
377            // Windows is disabled by default, but if we set enabled:true
378            // globally above we need to disable it explicitly.
379            enabled: false,
380        },
381    },
382}
383
384// A version of conscrypt only for enabling the "-hostdex" version to test ART on host.
385java_library {
386    // We need our own name to not clash with the conscrypt library.
387    name: "conscrypt-host",
388    installable: true,
389    hostdex: true,
390    static_libs: ["conscrypt-for-host"],
391
392    // Tests and build files rely on this file to be installed as "conscrypt-hostdex",
393    // therefore set a stem. Without it, the file would be installed as
394    // "conscrypt-host-hostdex".
395    stem: "conscrypt",
396    sdk_version: "core_platform",
397    target: {
398        hostdex: {
399            required: ["libjavacrypto"],
400        },
401        darwin: {
402            // required module "libjavacrypto" is disabled on darwin
403            enabled: false,
404        },
405    },
406}
407
408// A version of core-icu4j only for enabling the "-hostdex" version to test ART on host.
409java_library {
410    // We need our own name to not clash with the core-icu4j library.
411    name: "core-icu4j-host",
412    installable: true,
413    hostdex: true,
414    static_libs: ["core-icu4j-for-host"],
415
416    // Tests and build files rely on this file to be installed as "core-icu4j-hostdex",
417    // therefore set a stem. Without it, the file would be installed as
418    // "core-icu4j-host-hostdex".
419    stem: "core-icu4j",
420    sdk_version: "core_platform",
421    target: {
422        hostdex: {
423            required: ["libicu_jni"],
424        },
425    },
426}
427