xref: /aosp_15_r20/libcore/NativeCode.bp (revision 89a6322812dc8573315e60046e7959c50dad91d4)
1// Copyright (C) 2007 The Android Open Source Project
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
15//
16// Definitions for building the native code needed for the core library.
17//
18
19// Defaults that apply to all of the modules
20
21cc_defaults {
22    name: "core_native_default_flags",
23    host_supported: true,
24    cflags: [
25        "-Wall",
26        "-Wextra",
27        "-Werror",
28    ],
29    cppflags: ["-DU_USING_ICU_NAMESPACE=0"],
30
31    target: {
32        darwin: {
33            enabled: false,
34        },
35        windows: {
36            enabled: false,
37        },
38    },
39    min_sdk_version: "S",
40}
41
42cc_defaults {
43    name: "core_native_default_libs",
44    header_libs: ["jni_headers"],
45    shared_libs: [
46        "libbase",
47        "liblog",
48        "libnativehelper#impl",
49    ],
50    static_libs: ["libnativehelper_compat_libc++"],
51}
52
53cc_library_shared {
54    name: "libjavacore",
55    visibility: [
56        "//art/build/apex",
57        "//art/runtime",
58        "//art/tools/ahat",
59    ],
60    apex_available: [
61        "com.android.art",
62        "com.android.art.debug",
63    ],
64    defaults: [
65        "core_native_default_flags",
66        "core_native_default_libs",
67    ],
68    srcs: [
69        ":luni_native_srcs",
70    ],
71    shared_libs: [
72        "libandroidio",
73        "libicu",
74        "libexpat",
75        "libz",
76    ],
77    static_libs: [
78        "libcrypto_for_art",
79        "libziparchive",
80    ],
81    version_script: "libjavacore.map",
82}
83
84cc_library_shared {
85    name: "libandroidio",
86    visibility: [
87        "//art/build/apex",
88        "//art/build/sdk",
89        "//art/tools/ahat",
90        "//external/conscrypt",
91    ],
92    apex_available: [
93        "com.android.art",
94        "com.android.art.debug",
95    ],
96    defaults: [
97        "core_native_default_flags",
98    ],
99    shared_libs: [
100        "liblog",
101    ],
102    srcs: [
103        ":libandroidio_srcs",
104    ],
105    stubs: {
106        symbol_file: "libandroidio.map.txt",
107        versions: ["1"],
108    },
109}
110
111cc_defaults {
112    name: "libopenjdk_native_defaults",
113    defaults: [
114        "core_native_default_flags",
115        "core_native_default_libs",
116    ],
117    srcs: [":libopenjdk_native_srcs"],
118    local_include_dirs: [
119        "luni/src/main/native",
120    ],
121    cflags: [
122        // TODO(narayan): Prune down this list of exclusions once the underlying
123        // issues have been fixed. Most of these are small changes except for
124        // -Wunused-parameter.
125        "-Wno-unused-parameter",
126        "-Wno-unused-variable",
127        "-Wno-parentheses-equality",
128        "-Wno-constant-logical-operand",
129        "-Wno-sometimes-uninitialized",
130    ],
131
132    shared_libs: [
133        "libandroidio",
134        "libicu",
135        "libz",
136    ],
137    static_libs: [
138        "libcrypto_for_art",
139        "libfdlibm",
140    ],
141
142    target: {
143        musl: {
144            cflags: [
145                // Sigh.
146                "-D_LARGEFILE64_SOURCE",
147                "-D_GNU_SOURCE",
148                "-DLINUX",
149            ],
150        },
151        glibc: {
152            cflags: [
153                "-D__GLIBC__",
154                // Sigh.
155                "-D_LARGEFILE64_SOURCE",
156                "-D_GNU_SOURCE",
157                "-DLINUX",
158            ],
159        },
160        android: {
161            shared_libs: [
162                "libdl_android",
163            ],
164        },
165    },
166}
167
168cc_library_shared {
169    name: "libopenjdk",
170    visibility: [
171        "//art/build/apex",
172        "//art/tools/ahat",
173    ],
174    apex_available: [
175        "com.android.art",
176        "com.android.art.debug",
177    ],
178    defaults: ["libopenjdk_native_defaults"],
179    shared_libs: [
180        "libopenjdkjvm",
181    ],
182}
183
184// Debug version of libopenjdk. Depends on libopenjdkjvmd.
185cc_library_shared {
186    name: "libopenjdkd",
187    visibility: [
188        "//art/build/apex",
189        "//art/tools/ahat",
190    ],
191    apex_available: [
192        "com.android.art.debug",
193    ],
194    defaults: ["libopenjdk_native_defaults"],
195    shared_libs: [
196        "libopenjdkjvmd",
197    ],
198}
199
200// Test JNI library.
201cc_library_shared {
202    name: "libjavacoretests",
203    visibility: [
204        "//art/build/sdk",
205        "//cts/tests/libcore/luni",
206    ],
207    defaults: ["core_native_default_flags"],
208    host_supported: true,
209
210    srcs: [
211        "luni/src/test/native/libcore_dalvik_system_JniTest.cpp",
212        "luni/src/test/native/libcore_java_io_FileTest.cpp",
213        "luni/src/test/native/libcore_java_lang_OldStackTraceElementTest.cpp",
214        "luni/src/test/native/libcore_java_lang_ThreadTest.cpp",
215        "luni/src/test/native/libcore_java_nio_BufferTest.cpp",
216        "luni/src/test/native/libcore_java_time_TimeApisConsistencyTest.cpp",
217        "luni/src/test/native/libcore_libcore_util_NativeAllocationRegistryTest.cpp",
218        "luni/src/test/native/tests_support_AndroidProperties.cpp",
219    ],
220    shared_libs: [
221        "liblog",
222        "libnativehelper",
223    ],
224    static_libs: [
225        "libbase",
226    ],
227}
228
229// Set of gtest unit tests.
230cc_test {
231    name: "libjavacore-unit-tests",
232    defaults: ["core_native_default_flags"],
233
234    // TODO(b/172480617): Fix this source dependency from
235    // platform_testing/build/tasks/tests/native_test_list.mk.
236    enabled: true,
237
238    // Add -fno-builtin so that the compiler doesn't attempt to inline
239    // memcpy calls that are not really aligned.
240    cflags: ["-fno-builtin"],
241    srcs: [
242        "luni/src/test/native/libcore_io_Memory_test.cpp",
243        // libcore_io_Memory_test.cpp includes libcore_io_Memory.cpp which
244        // depends on JniConstants.cpp (but these are not used in the tests).
245        "luni/src/main/native/JniConstants.cpp",
246    ],
247
248    shared_libs: [
249        "liblog",
250        "libnativehelper",
251    ],
252
253    static_libs: ["libnativehelper_compat_libc++"],
254}
255
256// Set of benchmarks for libjavacore functions.
257cc_benchmark {
258    name: "libjavacore-benchmarks",
259    defaults: ["core_native_default_flags"],
260
261    // TODO(b/172480617): Fix this source dependency from
262    // platform_testing/build/tasks/tests/native_metric_test_list.mk.
263    enabled: true,
264
265    srcs: [
266        "luni/src/benchmark/native/libcore_io_Memory_bench.cpp",
267        // libcore_io_Memory_bench.cpp includes libcore_io_Memory.cpp which
268        // depends on JniConstants.cpp (but these are not used in the benchmark).
269        "luni/src/main/native/JniConstants.cpp",
270    ],
271    test_suites: ["device-tests"],
272
273    shared_libs: [
274        "liblog",
275        "libnativehelper",
276    ],
277}
278