1//
2// Copyright (C) 2011 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8//      http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17package {
18    // See: http://go/android-license-faq
19    // A large-scale-change added 'default_applicable_licenses' to import
20    // all of the 'license_kinds' from "art_license"
21    // to get the below license kinds:
22    //   SPDX-license-identifier-Apache-2.0
23    default_applicable_licenses: ["art_license"],
24    default_team: "trendy_team_art_performance",
25}
26
27cc_defaults {
28    name: "libdexfile_defaults",
29    defaults: ["art_defaults"],
30    host_supported: true,
31    tidy_timeout_srcs: [
32        "dex/dex_file_verifier.cc",
33    ],
34    srcs: [
35        "dex/art_dex_file_loader.cc",
36        "dex/compact_dex_file.cc",
37        "dex/compact_offset_table.cc",
38        "dex/descriptors_names.cc",
39        "dex/dex_file.cc",
40        "dex/dex_file_exception_helpers.cc",
41        "dex/dex_file_layout.cc",
42        "dex/dex_file_loader.cc",
43        "dex/dex_file_tracking_registrar.cc",
44        "dex/dex_file_verifier.cc",
45        "dex/dex_instruction.cc",
46        "dex/modifiers.cc",
47        "dex/primitive.cc",
48        "dex/signature.cc",
49        "dex/standard_dex_file.cc",
50        "dex/type_lookup_table.cc",
51        "dex/utf.cc",
52    ],
53    header_libs: [
54        "jni_headers",
55        "libdexfile_external_headers",
56    ],
57    export_header_lib_headers: [
58        "jni_headers",
59        "libdexfile_external_headers",
60    ],
61    static: {
62        cflags: ["-DSTATIC_LIB"],
63    },
64    target: {
65        android: {
66            srcs: [
67                "external/dex_file_ext.cc",
68            ],
69            static_libs: [
70                "libziparchive",
71            ],
72            shared_libs: [
73                // libz provides a stub from platform, shouldn't be statically linked
74                "libz",
75                // For MemMap.
76                "libartpalette",
77                "liblog",
78                // For common macros.
79                "libbase",
80            ],
81            export_shared_lib_headers: [
82                "libbase",
83            ],
84        },
85        not_windows: {
86            srcs: [
87                "external/dex_file_ext.cc",
88            ],
89            shared_libs: [
90                "libziparchive",
91                "libz",
92                // For MemMap.
93                "libartpalette",
94                "liblog",
95                // For common macros.
96                "libbase",
97            ],
98            export_shared_lib_headers: [
99                "libbase",
100            ],
101        },
102        windows: {
103            static_libs: [
104                "libziparchive",
105                "libz",
106                // For MemMap.
107                "libartpalette",
108                "liblog",
109                // For common macros.
110                "libbase",
111            ],
112            export_static_lib_headers: [
113                "libbase",
114            ],
115            cflags: ["-Wno-thread-safety"],
116        },
117        darwin: {
118            enabled: true,
119        },
120    },
121    generated_sources: ["dexfile_operator_srcs"],
122    export_include_dirs: ["."],
123}
124
125cc_defaults {
126    name: "libdexfile_static_base_defaults",
127    whole_static_libs: [
128        "libbase",
129        "liblog",
130        "libz",
131        "libziparchive",
132    ],
133}
134
135cc_defaults {
136    name: "libdexfile_static_defaults",
137    defaults: [
138        "libartbase_static_defaults",
139        "libdexfile_static_base_defaults",
140    ],
141    defaults_visibility: [
142        "//art:__subpackages__",
143    ],
144    whole_static_libs: ["libdexfile"],
145}
146
147cc_defaults {
148    name: "libdexfiled_static_defaults",
149    defaults: [
150        "libartbased_static_defaults",
151        "libdexfile_static_base_defaults",
152    ],
153    whole_static_libs: ["libdexfiled"],
154}
155
156gensrcs {
157    name: "dexfile_operator_srcs",
158    cmd: "$(location generate_operator_out) art/libdexfile $(in) > $(out)",
159    tools: ["generate_operator_out"],
160    srcs: [
161        "dex/dex_file.h",
162        "dex/dex_file_layout.h",
163        "dex/dex_instruction.h",
164        "dex/dex_instruction_utils.h",
165        "dex/invoke_type.h",
166    ],
167    output_extension: "operator_out.cc",
168}
169
170art_cc_library {
171    name: "libdexfile",
172    visibility: [
173        // Allow libdexfile_support users to list this as a runtime_libs
174        // dependency - see comment for libdexfile_support. It shouldn't be used
175        // for any other purpose.
176        "//external/perfetto",
177        "//frameworks/base/services/core/jni",
178        "//system/core/debuggerd",
179        "//system/extras/simpleperf",
180        "//system/unwinding/libunwindstack",
181    ],
182    defaults: [
183        "libdexfile_defaults",
184        "libart_nativeunwind_defaults",
185    ],
186    target: {
187        android: {
188            shared_libs: [
189                "libartbase",
190            ],
191            export_shared_lib_headers: [
192                "libartbase",
193            ],
194        },
195        not_windows: {
196            shared_libs: [
197                "libartbase",
198            ],
199            export_shared_lib_headers: [
200                "libartbase",
201            ],
202        },
203        windows: {
204            enabled: true,
205            shared: {
206                enabled: false,
207            },
208            static_libs: [
209                "libartbase",
210            ],
211            export_static_lib_headers: [
212                "libartbase",
213            ],
214        },
215    },
216    apex_available: [
217        "com.android.art",
218        "com.android.art.debug",
219        "test_broken_com.android.art",
220    ],
221
222    // This library is exported in stub form by art-module-sdk, and it brings
223    // with it all the exported headers from libartbase and libbase, many of
224    // which are transitive dependencies outside ART. Those may conflict with
225    // other versions of the headers that the caller is using in their build,
226    // but in this case it's fine since external users only depend on this
227    // through runtime_libs (see comment for libdexfile_support), which doesn't
228    // propagate include dirs.
229    stubs: {
230        symbol_file: "libdexfile.map.txt",
231        versions: ["1"],
232    },
233}
234
235art_cc_library {
236    name: "libdexfiled",
237    defaults: [
238        "art_debug_defaults",
239        "libdexfile_defaults",
240    ],
241    target: {
242        android: {
243            shared_libs: [
244                "libartbased",
245            ],
246            export_shared_lib_headers: [
247                "libartbased",
248            ],
249        },
250        not_windows: {
251            shared_libs: [
252                "libartbased",
253            ],
254            export_shared_lib_headers: [
255                "libartbased",
256            ],
257        },
258        windows: {
259            enabled: true,
260            shared: {
261                enabled: false,
262            },
263            static_libs: [
264                "libartbased",
265            ],
266            export_static_lib_headers: [
267                "libartbased",
268            ],
269        },
270    },
271    apex_available: [
272        "com.android.art.debug",
273        // TODO(b/183882457): This lib doesn't go into com.android.art, but
274        // apex_available lists need to be the same for internal libs to avoid
275        // stubs, and libartd depends on this.
276        "com.android.art",
277    ],
278}
279
280art_cc_defaults {
281    name: "art_libdexfile_tests_defaults",
282    defaults: [
283        "art_libunwindstack_static_defaults", // Must be statically linked in standalone tests
284    ],
285    tidy_timeout_srcs: [
286        "dex/dex_file_verifier_test.cc",
287    ],
288    srcs: [
289        "dex/art_dex_file_loader_test.cc",
290        "dex/class_accessor_test.cc",
291        "dex/code_item_accessors_test.cc",
292        "dex/compact_dex_file_test.cc",
293        "dex/compact_offset_table_test.cc",
294        "dex/descriptors_names_test.cc",
295        "dex/dex_file_loader_test.cc",
296        "dex/dex_file_verifier_test.cc",
297        "dex/dex_instruction_test.cc",
298        "dex/fuzzer_corpus_test.cc",
299        "dex/primitive_test.cc",
300        "dex/proto_reference_test.cc",
301        "dex/string_reference_test.cc",
302        "dex/test_dex_file_builder_test.cc",
303        "dex/type_lookup_table_test.cc",
304        "dex/utf_test.cc",
305    ],
306    data: [
307        ":art-gtest-jars-GetMethodSignature",
308        ":art-gtest-jars-Lookup",
309        ":art-gtest-jars-DexFuzzerFolder",
310        ":art-gtest-jars-Main",
311        ":art-gtest-jars-MainEmptyUncompressed",
312        ":art-gtest-jars-MultiDex",
313        ":art-gtest-jars-Nested",
314        ":art-gtest-jars-VerifierDeps",
315    ],
316    header_libs: ["jni_headers"],
317}
318
319// Version of ART gtest `art_libdexfile_tests` bundled with the ART APEX on target.
320// TODO(b/192274705): Remove this module when the migration to standalone ART gtests is complete.
321art_cc_test {
322    name: "art_libdexfile_tests",
323    defaults: [
324        "art_gtest_defaults",
325        "art_libdexfile_tests_defaults",
326    ],
327}
328
329// Standalone version of ART gtest `art_libdexfile_tests`, not bundled with the ART APEX on target.
330art_cc_test {
331    name: "art_standalone_libdexfile_tests",
332    defaults: [
333        "art_standalone_gtest_defaults",
334        "art_libdexfile_tests_defaults",
335    ],
336    test_config: "art_standalone_libdexfile_tests.xml",
337}
338
339cc_library_headers {
340    name: "libdexfile_external_headers",
341    defaults: ["art_defaults"],
342    visibility: ["//visibility:public"],
343    host_supported: true,
344    export_include_dirs: ["external/include"],
345
346    target: {
347        windows: {
348            enabled: true,
349        },
350        darwin: {
351            enabled: true,
352        },
353    },
354
355    apex_available: [
356        "//apex_available:platform",
357        "com.android.art",
358        "com.android.art.debug",
359        "com.android.media",
360        "com.android.runtime",
361    ],
362}
363
364// Make dex_instruction_list.h available for tools/jvmti-agents/titrace
365cc_library_headers {
366    name: "libdexfile_all_headers",
367    defaults: ["art_defaults"],
368    visibility: ["//art:__subpackages__"],
369    host_supported: true,
370    export_include_dirs: ["."],
371
372    apex_available: [
373        "com.android.art",
374        "com.android.art.debug",
375    ],
376}
377
378art_cc_defaults {
379    name: "art_libdexfile_external_tests_defaults",
380    test_suites: ["general-tests"],
381    srcs: [
382        "external/dex_file_ext_c_test.c",
383        "external/dex_file_ext_test.cc",
384    ],
385    shared_libs: [
386        "libdexfile",
387    ],
388    header_libs: [
389        "jni_headers",
390        "libdexfile_external_headers",
391    ],
392}
393
394// Version of ART gtest `art_libdexfile_external_tests` bundled with the ART APEX on target.
395// TODO(b/192274705): Remove this module when the migration to standalone ART gtests is complete.
396art_cc_test {
397    name: "art_libdexfile_external_tests",
398    defaults: [
399        "art_test_defaults",
400        "art_libdexfile_external_tests_defaults",
401    ],
402}
403
404// Standalone version of ART gtest `art_libdexfile_external_tests`, not bundled with the ART APEX on
405// target.
406art_cc_test {
407    name: "art_standalone_libdexfile_external_tests",
408    defaults: [
409        "art_standalone_test_defaults",
410        "art_libdexfile_external_tests_defaults",
411    ],
412
413    test_config_template: ":art-gtests-target-standalone-cts-template",
414    test_suites: ["cts"], // For backed-by API coverage.
415}
416
417// Support library with a C++ API for accessing the libdexfile API for external
418// (non-ART) users.
419//
420// This library dlopens libdexfile(d).so on first use, so there is no build time
421// dependency on dex file logic. It is therefore safe to use from binaries
422// compiled without dex file support, given they won't encounter any dex file
423// stack frames.
424//
425// IMPORTANT: When adding a static_libs dependency on this library, please
426// remember to also add a corresponding
427//
428//     runtime_libs: ["libdexfile"],
429//
430// That is necessary since Soong doesn't propagate dependencies transitively for
431// static libraries (b/169779783).
432art_cc_library_static {
433    name: "libdexfile_support",
434    defaults: ["art_defaults"],
435    visibility: ["//visibility:public"],
436    host_supported: true,
437    srcs: [
438        "external/dex_file_supp.cc",
439    ],
440    runtime_libs: ["libdexfile"],
441    // Only NDK libs may be dynamic, because this becomes a prebuilt that must work on S+.
442    shared_libs: ["liblog"],
443    header_libs: ["libdexfile_external_headers"],
444    // Do not export any headers outside the ART module - they get included in
445    // the prebuilt SDK and may conflict with different versions of themselves
446    // in the build that the SDK user is using.
447    export_header_lib_headers: ["libdexfile_external_headers"],
448
449    apex_available: [
450        "//apex_available:platform",
451        "com.android.art",
452        "com.android.art.debug",
453        "com.android.runtime",
454    ],
455}
456
457art_cc_defaults {
458    name: "art_libdexfile_support_tests_defaults",
459    test_suites: ["general-tests"],
460    srcs: [
461        "external/dex_file_supp_test.cc",
462    ],
463    shared_libs: [
464        "libdexfile",
465        "liblog",
466    ],
467    static_libs: [
468        "libbase", // Must be statically linked in standalone tests
469        "libdexfile_support",
470    ],
471}
472
473// Version of ART gtest `art_libdexfile_support_tests` bundled with the ART APEX on target.
474// TODO(b/192274705): Remove this module when the migration to standalone ART gtests is complete.
475art_cc_test {
476    name: "art_libdexfile_support_tests",
477    host_supported: true,
478    defaults: [
479        "art_test_defaults",
480        "art_libdexfile_support_tests_defaults",
481    ],
482}
483
484// Standalone version of ART gtest `art_libdexfile_support_tests`, not bundled with the ART APEX on
485// target.
486art_cc_test {
487    name: "art_standalone_libdexfile_support_tests",
488    defaults: [
489        "art_standalone_test_defaults",
490        "art_libdexfile_support_tests_defaults",
491    ],
492    test_suites: [
493        "mts-art",
494    ],
495}
496
497cc_library_static {
498    name: "libdexfile_support_static",
499    defaults: ["art_defaults"],
500    host_supported: true,
501    srcs: [
502        "external/dex_file_supp.cc",
503    ],
504    cflags: ["-DSTATIC_LIB"],
505    header_libs: ["libdexfile_external_headers"],
506    export_header_lib_headers: ["libdexfile_external_headers"],
507}
508
509cc_defaults {
510    name: "libdexfile_support_static_defaults",
511    defaults: [
512        "libdexfile_static_defaults",
513    ],
514    whole_static_libs: [
515        "libdexfile",
516        "libdexfile_support_static",
517    ],
518}
519
520cc_defaults {
521    name: "libdexfiled_support_static_defaults",
522    defaults: [
523        "libdexfiled_static_defaults",
524    ],
525    whole_static_libs: [
526        "libdexfiled",
527        "libdexfile_support_static",
528    ],
529}
530
531art_cc_test {
532    name: "art_libdexfile_support_static_tests",
533    test_suites: ["general-tests"],
534    defaults: [
535        "art_test_defaults",
536        "libdexfile_support_static_defaults",
537    ],
538    srcs: [
539        "external/dex_file_supp_test.cc",
540    ],
541}
542
543// For use by external packages allowed to link in static libdexfile_support.
544// This is not allowed in any module that may end up in an APEX or platform
545// image, so visibility is restrictive.
546//
547// TODO(b/169885605): This library brings with it all the exported headers from
548// libdexfile_support_static_defaults into the prebuilt SDK created by
549// art-module-sdk, many of which are transitive dependencies outside ART. Those
550// may conflict with other versions that the caller is using in their build. One
551// way to deal with that is to provide minimal headers without any transitive
552// dependencies on other headers.
553cc_library_static {
554    name: "libdexfile_static",
555    host_supported: true,
556    visibility: [
557        // Required for simpleperf, libsimpleperf_record, and libsimpleperf_report
558        // in the NDK.
559        "//system/extras/simpleperf",
560        "//cts/tests/tests/simpleperf",
561    ],
562    // Using libdexfile_support_static_defaults will link in external libs like
563    // libbase and libz statically as well, which are likely to cause duplicate
564    // copies in the depending module.
565    // TODO(b/169885605): Avoid exposing symbols from those libs.
566    defaults: [
567        "art_defaults",
568        "libdexfile_support_static_defaults",
569    ],
570}
571
572art_cc_test {
573    name: "art_libdexfile_static_tests",
574    defaults: ["art_test_defaults"],
575    test_suites: ["general-tests"],
576    srcs: [
577        "external/dex_file_supp_test.cc",
578    ],
579    static_libs: [
580        "libdexfile_static",
581    ],
582    enabled: false,
583    target: {
584        android: {
585            // Build static test binary on device, to make sure libdexfile_static can be used in
586            // static simpleperf binary in ndk.
587            static_executable: true,
588            static_libs: [
589                "libc",
590            ],
591        },
592        linux: {
593            enabled: true,
594        },
595    },
596    // TODO(b/181740144): Enable a ubsan check to create a dependency on
597    // ubsan_minimal. It's needed to be able to link with the prebuilt
598    // libdexfile_static.a, which contains libziparchive.a, which is
599    // built with some ubsan checks
600    // (https://cs.android.com/android/platform/superproject/+/master:system/libziparchive/Android.bp;l=47-59;drc=c7b498fdf2002194709e40ea58ce39f43684fc14)
601    // that the SDK snapshots currently don't propagate properly for static
602    // libs.
603    sanitize: {
604        misc_undefined: ["shift"],
605    },
606}
607
608filegroup {
609    name: "art_libdexfile_dex_instruction_list_header",
610    srcs: ["dex/dex_instruction_list.h"],
611}
612