summaryrefslogtreecommitdiff
path: root/build/Android.bp
blob: 9cc44489c617a0765ac950bac90853fc0cc8e1c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
package {
    // See: http://go/android-license-faq
    // A large-scale-change added 'default_applicable_licenses' to import
    // all of the 'license_kinds' from "art_license"
    // to get the below license kinds:
    //   SPDX-license-identifier-Apache-2.0
    default_applicable_licenses: ["art_license"],
    default_team: "trendy_team_art_mainline",
}

bootstrap_go_package {
    name: "soong-art",
    pkgPath: "android/soong/art",
    deps: [
        "blueprint",
        "blueprint-pathtools",
        "blueprint-proptools",
        "soong",
        "soong-android",
        "soong-apex",
        "soong-cc",
    ],
    srcs: [
        "art.go",
        "codegen.go",
        "makevars.go",
    ],
    pluginFor: ["soong_build"],
}

art_clang_tidy_errors = [
    "android-cloexec-dup",
    "android-cloexec-fopen",
    "android-cloexec-open",
    "bugprone-argument-comment",
    "bugprone-lambda-function-name",
    "bugprone-macro-parentheses",
    "bugprone-macro-repeated-side-effects",
    "bugprone-unused-raii", // Protect scoped things like MutexLock.
    "bugprone-unused-return-value",
    "bugprone-use-after-move",
    "bugprone-virtual-near-miss",
    "misc-unused-using-decls",
    "modernize-use-bool-literals",
    "modernize-use-nullptr",
    "performance-faster-string-find",
    "performance-for-range-copy",
    "performance-implicit-conversion-in-loop",
    "performance-inefficient-string-concatenation",
    "performance-inefficient-vector-operation",
    "performance-no-automatic-move",
    "performance-noexcept-move-constructor",
    "performance-unnecessary-copy-initialization",
    "performance-unnecessary-value-param",
    "readability-duplicate-include",
    "readability-redundant-string-cstr",
]

art_clang_tidy_disabled = [
    "-google-default-arguments",
    // We have local stores that are only used for debug checks.
    "-clang-analyzer-deadcode.DeadStores",
    // We are OK with some static globals and that they can, in theory, throw.
    "-cert-err58-cpp",
    // We have lots of C-style variadic functions, and are OK with them. JNI ensures
    // that working around this warning would be extra-painful.
    "-cert-dcl50-cpp",
    "-misc-redundant-expression",
    // "Modernization" we don't agree with.
    "-modernize-use-auto",
    "-modernize-return-braced-init-list",
    "-modernize-use-default-member-init",
    "-modernize-pass-by-value",
    // The only two remaining offenders are art/openjdkjvmti/include/jvmti.h and
    // libcore/ojluni/src/main/native/jvm.h, which are both external files by Oracle
    "-modernize-use-using",
]

soong_config_module_type_import {
    from: "art/build/SoongConfig.bp",
    module_types: [
        "art_debug_defaults",
    ],
}

art_global_defaults {
    // Additional flags are computed by art.go

    name: "art_defaults",

    cpp_std: "gnu++17", // TODO(b/311052584): fix C++20 build and revert this line

    // This is the default visibility for the //art package, but we repeat it
    // here so that it gets merged with other visibility rules in modules
    // extending these defaults.
    visibility: ["//art:__subpackages__"],

    cflags: [
        // Base set of cflags used by all things ART.
        "-fno-rtti",
        "-ggdb3",
        "-Wall",
        "-Werror",
        "-Wextra",
        "-Wstrict-aliasing",
        "-fstrict-aliasing",
        "-Wunreachable-code",
        "-Wredundant-decls",
        "-Wshadow",
        "-Wunused",
        "-fvisibility=protected",

        // Warn about thread safety violations with clang.
        "-Wthread-safety",
        // TODO(b/144045034): turn on -Wthread-safety-negative
        //"-Wthread-safety-negative",

        // Warn if switch fallthroughs aren't annotated.
        "-Wimplicit-fallthrough",

        // Enable float equality warnings.
        "-Wfloat-equal",

        // Enable warning of converting ints to void*.
        "-Wint-to-void-pointer-cast",

        // Enable warning of wrong unused annotations.
        "-Wused-but-marked-unused",

        // Enable warning for deprecated language features.
        "-Wdeprecated",

        // Enable warning for unreachable break & return.
        "-Wunreachable-code-break",
        "-Wunreachable-code-return",

        // Disable warning for use of offsetof on non-standard layout type.
        // We use it to implement OFFSETOF_MEMBER - see macros.h.
        "-Wno-invalid-offsetof",

        // Enable inconsistent-missing-override warning. This warning is disabled by default in
        // Android.
        "-Winconsistent-missing-override",

        // Enable thread annotations for std::mutex, etc.
        "-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS",
    ],

    arch: {
        x86: {
            avx2: {
                cflags: [
                    "-mavx2",
                    "-mfma",
                ],
            },
        },
        x86_64: {
            avx2: {
                cflags: [
                    "-mavx2",
                    "-mfma",
                ],
            },
        },
    },

    target: {
        android: {
            cflags: [
                // To use oprofile_android --callgraph, uncomment this and recompile with
                //    mmma -j art
                // "-fno-omit-frame-pointer",
                // "-marm",
                // "-mapcs",
            ],
        },
        linux: {
            cflags: [
                // Enable missing-noreturn only on non-Mac. As lots of things are not implemented for
                // Apple, it's a pain.
                "-Wmissing-noreturn",
            ],
            // Don't export symbols of statically linked libziparchive.
            // Workaround to fix ODR violations (b/264235288) in gtests.
            // `--exclude-libs` flag is not supported on windows/darwin.
            ldflags: ["-Wl,--exclude-libs=libziparchive.a"],
        },
        linux_bionic: {
            strip: {
                // Do not strip art libs when building for linux-bionic.
                // Otherwise we can't get any symbols out of crashes.
                none: true,
            },
        },
        darwin: {
            enabled: false,
        },
        windows: {
            // When the module is enabled globally in the soong_config_variables
            // stanza above, it may get enabled on windows too for some module
            // types. Hence we need to disable it explicitly.
            // TODO(b/172480617): Clean up with that.
            enabled: false,
        },
        host: {
            cflags: [
                // Bug: 15446488. We don't omit the frame pointer to work around
                // clang/libunwind bugs that cause SEGVs in run-test-004-ThreadStress.
                "-fno-omit-frame-pointer",
            ],
        },
        // The build assumes that all our x86/x86_64 hosts (such as buildbots and developer
        // desktops) support at least sse4.2/popcount. This firstly implies that the ART
        // runtime binary itself may exploit these features. Secondly, this implies that
        // the ART runtime passes these feature flags to dex2oat and JIT by calling the
        // method InstructionSetFeatures::FromCppDefines(). Since invoking dex2oat directly
        // does not pick up these flags, cross-compiling from a x86/x86_64 host to a
        // x86/x86_64 target should not be affected.
        linux_x86: {
            cflags: [
                "-msse4.2",
                "-mpopcnt",
            ],
        },
        linux_x86_64: {
            cflags: [
                "-msse4.2",
                "-mpopcnt",
            ],
        },
    },

    codegen: {
        arm: {
            cflags: ["-DART_ENABLE_CODEGEN_arm"],
        },
        arm64: {
            cflags: ["-DART_ENABLE_CODEGEN_arm64"],
        },
        riscv64: {
            cflags: ["-DART_ENABLE_CODEGEN_riscv64"],
        },
        x86: {
            cflags: ["-DART_ENABLE_CODEGEN_x86"],
        },
        x86_64: {
            cflags: ["-DART_ENABLE_CODEGEN_x86_64"],
        },
    },

    tidy_checks: art_clang_tidy_errors + art_clang_tidy_disabled,

    tidy_checks_as_errors: art_clang_tidy_errors,

    tidy_flags: [
        // The static analyzer treats DCHECK as always enabled; we sometimes get
        // false positives when we use DCHECKs with code that relies on NDEBUG.
        "-extra-arg=-UNDEBUG",
        // clang-tidy complains about functions like:
        // void foo() { CHECK(kIsFooEnabled); /* do foo... */ }
        // not being marked noreturn if kIsFooEnabled is false.
        "-extra-arg=-Wno-missing-noreturn",
        // Because tidy doesn't like our flow checks for compile-time configuration and thinks that
        // the following code is dead (it is, but not for all configurations), disable unreachable
        // code detection in Clang for tidy builds. It is still on for regular build steps, so we
        // will still get the "real" errors.
        "-extra-arg=-Wno-unreachable-code",
    ],

    min_sdk_version: "31",
}

// Used to generate binaries that can be backed by transparent hugepages.
cc_defaults {
    name: "art_hugepage_defaults",
    arch: {
        arm64: {
            ldflags: ["-z max-page-size=0x200000"],
        },
        riscv64: {
            ldflags: ["-z max-page-size=0x200000"],
        },
        x86_64: {
            ldflags: ["-z max-page-size=0x200000"],
        },
    },
}

art_debug_defaults {
    name: "art_debug_defaults",
    defaults: ["art_defaults"],
    visibility: ["//art:__subpackages__"],
    cflags: [
        "-DDYNAMIC_ANNOTATIONS_ENABLED=1",
        "-DVIXL_DEBUG",
        "-UNDEBUG",
    ],
    asflags: [
        "-UNDEBUG",
    ],
    target: {
        // This has to be duplicated for android and host to make sure it
        // comes after the -Wframe-larger-than warnings inserted by art.go
        // target-specific properties
        android: {
            cflags: ["-Wno-frame-larger-than="],
        },
        host: {
            cflags: ["-Wno-frame-larger-than="],
        },
    },
    soong_config_variables: {
        art_debug_opt_flag: {
            cflags: ["%s"],
            conditions_default: {
                cflags: ["-Og"],
            },
        },
    },
}

// A version of conscrypt only for enabling the "-hostdex" version to test ART on host.
java_library {
    // We need our own name to not clash with the conscrypt library.
    name: "conscrypt-host",
    installable: true,
    hostdex: true,
    static_libs: ["conscrypt-for-host"],

    // Tests and build files rely on this file to be installed as "conscrypt-hostdex",
    // therefore set a stem. Without it, the file would be installed as
    // "conscrypt-host-hostdex".
    stem: "conscrypt",
    sdk_version: "core_platform",
    target: {
        hostdex: {
            required: ["libjavacrypto"],
        },
        darwin: {
            // required module "libjavacrypto" is disabled on darwin
            enabled: false,
        },
    },
}

// A version of core-icu4j only for enabling the "-hostdex" version to test ART on host.
java_library {
    // We need our own name to not clash with the core-icu4j library.
    name: "core-icu4j-host",
    installable: true,
    hostdex: true,
    static_libs: ["core-icu4j-for-host"],

    // Tests and build files rely on this file to be installed as "core-icu4j-hostdex",
    // therefore set a stem. Without it, the file would be installed as
    // "core-icu4j-host-hostdex".
    stem: "core-icu4j",
    sdk_version: "core_platform",
    target: {
        hostdex: {
            required: ["libicu_jni"],
        },
    },
}