blob: ae055c05bb154461304af83e0cb37a854eaf0c92 [file] [log] [blame]
Bob Badour3f2566f2021-02-11 17:09:40 -08001package {
2 default_applicable_licenses: ["external_zlib_license"],
3}
4
5license {
6 name: "external_zlib_license",
7 visibility: [":__subpackages__"],
8 license_kinds: [
9 "SPDX-license-identifier-BSD",
10 "SPDX-license-identifier-Zlib",
11 ],
12 license_text: [
13 "LICENSE",
14 ],
15}
16
Elliott Hughesce1c0372020-02-14 00:58:28 +000017srcs_opt = [
18 "adler32_simd.c",
19 // See https://chromium-review.googlesource.com/749732.
20// TODO: causes `atest org.apache.harmony.tests.java.util.zip.DeflaterTest` failures.
21// "contrib/optimizations/inffast_chunk.c",
22// "contrib/optimizations/inflate.c",
23 // This file doesn't build for non-neon, so it can't be in the main srcs.
Elliott Hughesce1c0372020-02-14 00:58:28 +000024 "crc32_simd.c",
25]
26
27cflags_arm = [
28 // Since we're building for the platform, we claim to be Linux rather than
29 // Android so we use getauxval() directly instead of the NDK
30 // android_getCpuFeatures which isn't available to us anyway.
31 "-DARMV8_OS_LINUX",
32 // Testing with zlib_bench shows -O3 is a win for ARM but a bit of a wash
33 // for x86, so match the BUILD file in only enabling this for ARM.
34 "-O3",
Elliott Hughes784a86b2020-12-07 12:43:35 -080035 // We need a non-NEON libz.a for the NDK, and cpu_features.c won't build
36 // without this.
37 "-DCPU_NO_SIMD",
Elliott Hughesce1c0372020-02-14 00:58:28 +000038]
39cflags_arm_neon = [
Elliott Hughes784a86b2020-12-07 12:43:35 -080040 // Undo the -DCPU_NO_SIMD from the generic (non-NEON) ARM flags.
41 "-UCPU_NO_SIMD",
Elliott Hughesce1c0372020-02-14 00:58:28 +000042 // We no longer support non-Neon platform builds, but the NDK just has one libz.
43 "-DADLER32_SIMD_NEON",
44// TODO: causes `atest org.apache.harmony.tests.java.util.zip.DeflaterTest` failures.
45// "-DINFLATE_CHUNK_SIMD_NEON",
46 // HWCAP_CRC32 is checked at runtime, so it's okay to turn crc32
47 // acceleration on for both 32- and 64-bit.
48 "-DCRC32_ARMV8_CRC32",
49]
50cflags_arm64 = cflags_arm + cflags_arm_neon
51
Elliott Hughes8472b6c2021-01-06 14:52:46 -080052// The *host* x86 configuration (with *lower* CPU feature requirements).
Elliott Hughesce1c0372020-02-14 00:58:28 +000053cflags_x86 = [
54 // See ARMV8_OS_LINUX above.
55 "-DX86_NOT_WINDOWS",
Elliott Hughesce1c0372020-02-14 00:58:28 +000056// TODO: see arm above.
57// "-DINFLATE_CHUNK_SIMD_SSE2",
Elliott Hughes8472b6c2021-01-06 14:52:46 -080058 // Android's host CPU feature requirements are *lower* than the
59 // corresponding device CPU feature requirements, so it's easier to just
60 // say "no SIMD for you" rather than specificially disable SSSE3.
61 // We should have a conversation about that, but not until we at least have
62 // data on how many Studio users have CPUs that don't make the grade...
63 // https://issuetracker.google.com/171235570
64 "-DCPU_NO_SIMD",
65]
66// The *device* x86 configuration (with *higher* CPU feature requirements).
67cflags_android_x86 = [
68 // Android's x86/x86-64 ABI includes SSE2 and SSSE3.
69 "-UCPU_NO_SIMD",
70 "-DADLER32_SIMD_SSSE3",
Elliott Hughesce1c0372020-02-14 00:58:28 +000071 // PCLMUL isn't in the ABI, but it won't actually be used unless CPUID
72 // reports that the processor really does have the instruction.
73 "-mpclmul",
74 "-DCRC32_SIMD_SSE42_PCLMUL",
75]
76srcs_x86 = [
77 "crc_folding.c",
78 "fill_window_sse.c",
79] + srcs_opt
80
81// This optimization is applicable to arm64 and x86-64.
82cflags_64 = ["-DINFLATE_CHUNK_READ_64LE"]
83
Kelvin Zhange6a6dbd2021-01-12 14:54:06 -050084libz_srcs = [
85 "adler32.c",
86 "compress.c",
87 "cpu_features.c",
88 "crc32.c",
89 "deflate.c",
90 "gzclose.c",
91 "gzlib.c",
92 "gzread.c",
93 "gzwrite.c",
94 "infback.c",
95 "inffast.c",
96 "inflate.c",
97 "inftrees.c",
98 "trees.c",
99 "uncompr.c",
100 "zutil.c",
101]
102
Dan Albertca7b4152019-06-11 16:32:07 -0700103cc_defaults {
104 name: "libz_defaults",
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700105
106 cflags: [
Elliott Hughesce1c0372020-02-14 00:58:28 +0000107 // We do support hidden visibility, so turn that on.
Elliott Hughes35329cd2019-04-10 14:56:06 -0700108 "-DHAVE_HIDDEN",
Elliott Hughesce1c0372020-02-14 00:58:28 +0000109 // We do support const, so turn that on.
Tao Bao5604dec2016-12-19 13:29:53 -0800110 "-DZLIB_CONST",
Chih-Hung Hsieh3e5deb42017-09-29 11:41:33 -0700111 "-Wall",
112 "-Werror",
Elliott Hughese7091dd2019-06-06 12:47:16 -0700113 "-Wno-unused",
114 "-Wno-unused-parameter",
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700115 ],
116 stl: "none",
117 export_include_dirs: ["."],
Kelvin Zhange6a6dbd2021-01-12 14:54:06 -0500118 srcs: libz_srcs,
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700119
120 arch: {
121 arm: {
Elliott Hughese7091dd2019-06-06 12:47:16 -0700122 // TODO: This is to work around b/24465209. Remove after root cause
123 // is fixed.
Chih-Hung Hsieh19b536b2018-05-23 18:52:18 -0700124 pack_relocations: false,
Ian Pedowitzcca7bd42018-01-18 16:22:54 -0800125 ldflags: ["-Wl,--hash-style=both"],
Elliott Hughesce1c0372020-02-14 00:58:28 +0000126
127 cflags: cflags_arm,
128 neon: {
129 cflags: cflags_arm_neon,
130 srcs: srcs_opt,
131 }
132 },
133 arm64: {
134 cflags: cflags_arm64 + cflags_64,
135 srcs: srcs_opt,
136 },
137 x86: {
138 cflags: cflags_x86,
139 srcs: srcs_x86,
140 },
141 x86_64: {
142 cflags: cflags_x86 + cflags_64,
143 srcs: srcs_x86,
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700144 },
145 },
Elliott Hughes8472b6c2021-01-06 14:52:46 -0800146 target: {
147 android_x86: {
148 cflags: cflags_android_x86,
149 },
150 android_x86_64: {
151 cflags: cflags_android_x86,
152 },
153 },
Dan Albertca7b4152019-06-11 16:32:07 -0700154}
155
156cc_library {
157 name: "libz",
158 defaults: ["libz_defaults"],
159
160 host_supported: true,
161 unique_host_soname: true,
162 static_ndk_lib: true,
163
164 vendor_available: true,
Justin Yune66fac52020-11-11 18:26:47 +0900165 product_available: true,
Dan Albertca7b4152019-06-11 16:32:07 -0700166 vndk: {
167 enabled: true,
168 support_system_process: true,
169 },
Yifan Hongd4b6e522020-01-21 19:28:33 -0800170 ramdisk_available: true,
Yifan Hongc777f202020-10-21 18:44:36 -0700171 vendor_ramdisk_available: true,
Dan Albertca7b4152019-06-11 16:32:07 -0700172 recovery_available: true,
173 native_bridge_supported: true,
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700174
175 target: {
Dan Willemsen0bb579c2016-11-04 12:27:30 -0700176 linux_bionic: {
177 enabled: true,
178 },
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700179 windows: {
180 enabled: true,
181 },
182 },
Jiyong Parkd8ff0c72020-05-18 09:30:14 +0000183
184 stubs: {
185 versions: [
186 "29",
187 "30",
188 ],
189 symbol_file: "libz.map.txt",
190 },
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700191}
192
Kelvin Zhange6a6dbd2021-01-12 14:54:06 -0500193// A more stable build of libz. Build configuration of this library should be
194// the same for different targets. This is only used by imgdiff.
195
196cc_library {
197 name: "libz_stable",
198 visibility: [
199 "//bootable/recovery/applypatch",
200 "//bootable/recovery/tests",
201 ],
202 cflags: [
203 // We do support hidden visibility, so turn that on.
204 "-DHAVE_HIDDEN",
205 // We do support const, so turn that on.
206 "-DZLIB_CONST",
207 "-Wall",
208 "-Werror",
209 "-Wno-unused",
210 "-Wno-unused-parameter",
211 ],
212 stl: "none",
213 export_include_dirs: ["."],
214 srcs: libz_srcs,
215
216 host_supported: true,
217 vendor_available: true,
218 recovery_available: true,
219}
220
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700221cc_binary_host {
222 name: "minigzip",
Elliott Hughese7091dd2019-06-06 12:47:16 -0700223 srcs: ["contrib/minigzip/minigzip.c"],
224 cflags: ["-Wall", "-Werror", "-DUSE_MMAP"],
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700225 static_libs: ["libz"],
226 stl: "none",
227}
Dan Alberte405a262016-09-15 16:24:19 -0700228
Narayan Kamath1a14eb32017-01-06 12:49:24 +0000229cc_binary {
Elliott Hughese7091dd2019-06-06 12:47:16 -0700230 name: "zlib_bench",
231 srcs: ["contrib/bench/zlib_bench.cc"],
Chih-Hung Hsieh3e5deb42017-09-29 11:41:33 -0700232 cflags: ["-Wall", "-Werror"],
Elliott Hughese7091dd2019-06-06 12:47:16 -0700233 host_supported: true,
Narayan Kamath1a14eb32017-01-06 12:49:24 +0000234 shared_libs: ["libz"],
Elliott Hughesce1c0372020-02-14 00:58:28 +0000235 // We build zlib_bench32 and zlib_bench64 so it's easy to test LP32.
236 compile_multilib: "both",
237 multilib: {
238 lib32: { suffix: "32", },
239 lib64: { suffix: "64", },
240 },
Narayan Kamath1a14eb32017-01-06 12:49:24 +0000241}
242
Elliott Hughes822a4b82020-06-17 09:01:27 -0700243cc_test {
244 name: "zlib_tests",
245 srcs: [
246 "contrib/tests/infcover.cc",
247 "contrib/tests/utils_unittest.cc",
248 "google/compression_utils_portable.cc",
249 ],
250 include_dirs: [
251 "external/zlib/google",
252 // These tests include "gtest.h" rather than the usual "gtest/gtest.h".
253 "external/googletest/googletest/include/gtest/",
254 ],
255 shared_libs: ["libz"],
256 host_supported: true,
257 test_suites: ["device-tests"],
258}
259
Elliott Hughes58b328a2020-05-01 15:46:14 -0700260ndk_headers {
261 name: "libz_headers",
262 from: "",
263 to: "",
264 srcs: [
265 "zconf.h",
266 "zlib.h",
267 ],
268 license: "LICENSE",
269}
Dan Alberte405a262016-09-15 16:24:19 -0700270
271ndk_library {
Dan Willemsen67ce3272017-04-07 15:34:26 -0700272 name: "libz",
Dan Alberte405a262016-09-15 16:24:19 -0700273 symbol_file: "libz.map.txt",
274 first_version: "9",
Dan Albert40f22ad2017-01-05 15:55:02 -0800275 unversioned_until: "current",
Dan Alberte405a262016-09-15 16:24:19 -0700276}