blob: 6c8c37c7435be6e6d025da3471914c91ddcbd29b [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",
Vishalcj174edd88d2021-05-11 13:46:03 +0700111 // Enable -O3 as per chromium.
112 "-O3",
Chih-Hung Hsieh3e5deb42017-09-29 11:41:33 -0700113 "-Wall",
114 "-Werror",
Elliott Hughese7091dd2019-06-06 12:47:16 -0700115 "-Wno-unused",
116 "-Wno-unused-parameter",
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700117 ],
118 stl: "none",
119 export_include_dirs: ["."],
Kelvin Zhange6a6dbd2021-01-12 14:54:06 -0500120 srcs: libz_srcs,
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700121
122 arch: {
123 arm: {
Elliott Hughese7091dd2019-06-06 12:47:16 -0700124 // TODO: This is to work around b/24465209. Remove after root cause
125 // is fixed.
Chih-Hung Hsieh19b536b2018-05-23 18:52:18 -0700126 pack_relocations: false,
Ian Pedowitzcca7bd42018-01-18 16:22:54 -0800127 ldflags: ["-Wl,--hash-style=both"],
Elliott Hughesce1c0372020-02-14 00:58:28 +0000128
129 cflags: cflags_arm,
130 neon: {
131 cflags: cflags_arm_neon,
132 srcs: srcs_opt,
133 }
134 },
135 arm64: {
136 cflags: cflags_arm64 + cflags_64,
137 srcs: srcs_opt,
138 },
139 x86: {
140 cflags: cflags_x86,
141 srcs: srcs_x86,
142 },
143 x86_64: {
144 cflags: cflags_x86 + cflags_64,
145 srcs: srcs_x86,
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700146 },
147 },
Elliott Hughes8472b6c2021-01-06 14:52:46 -0800148 target: {
149 android_x86: {
150 cflags: cflags_android_x86,
151 },
152 android_x86_64: {
153 cflags: cflags_android_x86,
154 },
155 },
Dan Albertca7b4152019-06-11 16:32:07 -0700156}
157
158cc_library {
159 name: "libz",
160 defaults: ["libz_defaults"],
161
162 host_supported: true,
163 unique_host_soname: true,
164 static_ndk_lib: true,
165
166 vendor_available: true,
Justin Yune66fac52020-11-11 18:26:47 +0900167 product_available: true,
Dan Albertca7b4152019-06-11 16:32:07 -0700168 vndk: {
169 enabled: true,
170 support_system_process: true,
171 },
Yifan Hongd4b6e522020-01-21 19:28:33 -0800172 ramdisk_available: true,
Yifan Hongc777f202020-10-21 18:44:36 -0700173 vendor_ramdisk_available: true,
Dan Albertca7b4152019-06-11 16:32:07 -0700174 recovery_available: true,
175 native_bridge_supported: true,
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700176
177 target: {
Dan Willemsen0bb579c2016-11-04 12:27:30 -0700178 linux_bionic: {
179 enabled: true,
180 },
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700181 windows: {
182 enabled: true,
183 },
184 },
Jiyong Parkd8ff0c72020-05-18 09:30:14 +0000185
186 stubs: {
187 versions: [
188 "29",
189 "30",
190 ],
191 symbol_file: "libz.map.txt",
192 },
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700193}
194
Kelvin Zhange6a6dbd2021-01-12 14:54:06 -0500195// A more stable build of libz. Build configuration of this library should be
196// the same for different targets. This is only used by imgdiff.
197
198cc_library {
199 name: "libz_stable",
200 visibility: [
201 "//bootable/recovery/applypatch",
202 "//bootable/recovery/tests",
203 ],
204 cflags: [
205 // We do support hidden visibility, so turn that on.
206 "-DHAVE_HIDDEN",
207 // We do support const, so turn that on.
208 "-DZLIB_CONST",
Vishalcj174edd88d2021-05-11 13:46:03 +0700209 // Enable -O3 as per chromium
210 "-O3",
Kelvin Zhange6a6dbd2021-01-12 14:54:06 -0500211 "-Wall",
212 "-Werror",
213 "-Wno-unused",
214 "-Wno-unused-parameter",
215 ],
216 stl: "none",
217 export_include_dirs: ["."],
218 srcs: libz_srcs,
219
220 host_supported: true,
221 vendor_available: true,
222 recovery_available: true,
223}
224
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700225cc_binary_host {
226 name: "minigzip",
Elliott Hughese7091dd2019-06-06 12:47:16 -0700227 srcs: ["contrib/minigzip/minigzip.c"],
228 cflags: ["-Wall", "-Werror", "-DUSE_MMAP"],
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700229 static_libs: ["libz"],
230 stl: "none",
231}
Dan Alberte405a262016-09-15 16:24:19 -0700232
Narayan Kamath1a14eb32017-01-06 12:49:24 +0000233cc_binary {
Elliott Hughese7091dd2019-06-06 12:47:16 -0700234 name: "zlib_bench",
235 srcs: ["contrib/bench/zlib_bench.cc"],
Chih-Hung Hsieh3e5deb42017-09-29 11:41:33 -0700236 cflags: ["-Wall", "-Werror"],
Elliott Hughese7091dd2019-06-06 12:47:16 -0700237 host_supported: true,
Narayan Kamath1a14eb32017-01-06 12:49:24 +0000238 shared_libs: ["libz"],
Elliott Hughesce1c0372020-02-14 00:58:28 +0000239 // We build zlib_bench32 and zlib_bench64 so it's easy to test LP32.
240 compile_multilib: "both",
241 multilib: {
242 lib32: { suffix: "32", },
243 lib64: { suffix: "64", },
244 },
Narayan Kamath1a14eb32017-01-06 12:49:24 +0000245}
246
Elliott Hughes822a4b82020-06-17 09:01:27 -0700247cc_test {
248 name: "zlib_tests",
249 srcs: [
250 "contrib/tests/infcover.cc",
251 "contrib/tests/utils_unittest.cc",
252 "google/compression_utils_portable.cc",
253 ],
254 include_dirs: [
255 "external/zlib/google",
256 // These tests include "gtest.h" rather than the usual "gtest/gtest.h".
257 "external/googletest/googletest/include/gtest/",
258 ],
259 shared_libs: ["libz"],
260 host_supported: true,
261 test_suites: ["device-tests"],
262}
263
Elliott Hughes58b328a2020-05-01 15:46:14 -0700264ndk_headers {
265 name: "libz_headers",
266 from: "",
267 to: "",
268 srcs: [
269 "zconf.h",
270 "zlib.h",
271 ],
272 license: "LICENSE",
273}
Dan Alberte405a262016-09-15 16:24:19 -0700274
275ndk_library {
Dan Willemsen67ce3272017-04-07 15:34:26 -0700276 name: "libz",
Dan Alberte405a262016-09-15 16:24:19 -0700277 symbol_file: "libz.map.txt",
278 first_version: "9",
Dan Albert40f22ad2017-01-05 15:55:02 -0800279 unversioned_until: "current",
Dan Alberte405a262016-09-15 16:24:19 -0700280}