blob: 6895ea32af8d4dc4f936d3e5e4b4ae7e656e3ca2 [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.
Dan Willemsence89a592021-10-19 20:22:25 -070020 // TODO: causes `atest org.apache.harmony.tests.java.util.zip.DeflaterTest` failures.
21 // "contrib/optimizations/inffast_chunk.c",
22 // "contrib/optimizations/inflate.c",
Elliott Hughesce1c0372020-02-14 00:58:28 +000023 // 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 = [
Elliott Hughesce1c0372020-02-14 00:58:28 +000028 // Testing with zlib_bench shows -O3 is a win for ARM but a bit of a wash
29 // for x86, so match the BUILD file in only enabling this for ARM.
30 "-O3",
Elliott Hughes784a86b2020-12-07 12:43:35 -080031 // We need a non-NEON libz.a for the NDK, and cpu_features.c won't build
32 // without this.
33 "-DCPU_NO_SIMD",
Elliott Hughesce1c0372020-02-14 00:58:28 +000034]
35cflags_arm_neon = [
Elliott Hughes784a86b2020-12-07 12:43:35 -080036 // Undo the -DCPU_NO_SIMD from the generic (non-NEON) ARM flags.
37 "-UCPU_NO_SIMD",
Elliott Hughesce1c0372020-02-14 00:58:28 +000038 // We no longer support non-Neon platform builds, but the NDK just has one libz.
39 "-DADLER32_SIMD_NEON",
Dan Willemsence89a592021-10-19 20:22:25 -070040 // TODO: causes `atest org.apache.harmony.tests.java.util.zip.DeflaterTest` failures.
41 // "-DINFLATE_CHUNK_SIMD_NEON",
Elliott Hughesce1c0372020-02-14 00:58:28 +000042 // HWCAP_CRC32 is checked at runtime, so it's okay to turn crc32
43 // acceleration on for both 32- and 64-bit.
44 "-DCRC32_ARMV8_CRC32",
45]
46cflags_arm64 = cflags_arm + cflags_arm_neon
47
Elliott Hughes8472b6c2021-01-06 14:52:46 -080048// The *host* x86 configuration (with *lower* CPU feature requirements).
Elliott Hughesce1c0372020-02-14 00:58:28 +000049cflags_x86 = [
50 // See ARMV8_OS_LINUX above.
51 "-DX86_NOT_WINDOWS",
Dan Willemsence89a592021-10-19 20:22:25 -070052 // TODO: see arm above.
53 // "-DINFLATE_CHUNK_SIMD_SSE2",
Elliott Hughes8472b6c2021-01-06 14:52:46 -080054 // Android's host CPU feature requirements are *lower* than the
55 // corresponding device CPU feature requirements, so it's easier to just
56 // say "no SIMD for you" rather than specificially disable SSSE3.
57 // We should have a conversation about that, but not until we at least have
58 // data on how many Studio users have CPUs that don't make the grade...
59 // https://issuetracker.google.com/171235570
60 "-DCPU_NO_SIMD",
61]
62// The *device* x86 configuration (with *higher* CPU feature requirements).
63cflags_android_x86 = [
64 // Android's x86/x86-64 ABI includes SSE2 and SSSE3.
65 "-UCPU_NO_SIMD",
66 "-DADLER32_SIMD_SSSE3",
Elliott Hughesce1c0372020-02-14 00:58:28 +000067 // PCLMUL isn't in the ABI, but it won't actually be used unless CPUID
68 // reports that the processor really does have the instruction.
69 "-mpclmul",
70 "-DCRC32_SIMD_SSE42_PCLMUL",
71]
72srcs_x86 = [
73 "crc_folding.c",
74 "fill_window_sse.c",
75] + srcs_opt
76
77// This optimization is applicable to arm64 and x86-64.
78cflags_64 = ["-DINFLATE_CHUNK_READ_64LE"]
79
Kelvin Zhange6a6dbd2021-01-12 14:54:06 -050080libz_srcs = [
81 "adler32.c",
82 "compress.c",
83 "cpu_features.c",
84 "crc32.c",
85 "deflate.c",
86 "gzclose.c",
87 "gzlib.c",
88 "gzread.c",
89 "gzwrite.c",
90 "infback.c",
91 "inffast.c",
92 "inflate.c",
93 "inftrees.c",
94 "trees.c",
95 "uncompr.c",
96 "zutil.c",
97]
98
Dan Albertca7b4152019-06-11 16:32:07 -070099cc_defaults {
100 name: "libz_defaults",
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700101
102 cflags: [
Elliott Hughesce1c0372020-02-14 00:58:28 +0000103 // We do support hidden visibility, so turn that on.
Elliott Hughes35329cd2019-04-10 14:56:06 -0700104 "-DHAVE_HIDDEN",
Elliott Hughesce1c0372020-02-14 00:58:28 +0000105 // We do support const, so turn that on.
Tao Bao5604dec2016-12-19 13:29:53 -0800106 "-DZLIB_CONST",
Vishalcj174edd88d2021-05-11 13:46:03 +0700107 // Enable -O3 as per chromium.
108 "-O3",
Chih-Hung Hsieh3e5deb42017-09-29 11:41:33 -0700109 "-Wall",
110 "-Werror",
Elliott Hughese7091dd2019-06-06 12:47:16 -0700111 "-Wno-unused",
112 "-Wno-unused-parameter",
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700113 ],
114 stl: "none",
115 export_include_dirs: ["."],
Kelvin Zhange6a6dbd2021-01-12 14:54:06 -0500116 srcs: libz_srcs,
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700117
118 arch: {
119 arm: {
Elliott Hughese7091dd2019-06-06 12:47:16 -0700120 // TODO: This is to work around b/24465209. Remove after root cause
121 // is fixed.
Chih-Hung Hsieh19b536b2018-05-23 18:52:18 -0700122 pack_relocations: false,
Ian Pedowitzcca7bd42018-01-18 16:22:54 -0800123 ldflags: ["-Wl,--hash-style=both"],
Elliott Hughesce1c0372020-02-14 00:58:28 +0000124
125 cflags: cflags_arm,
126 neon: {
127 cflags: cflags_arm_neon,
128 srcs: srcs_opt,
Dan Willemsence89a592021-10-19 20:22:25 -0700129 },
Elliott Hughesce1c0372020-02-14 00:58:28 +0000130 },
131 arm64: {
132 cflags: cflags_arm64 + cflags_64,
133 srcs: srcs_opt,
134 },
135 x86: {
136 cflags: cflags_x86,
137 srcs: srcs_x86,
138 },
139 x86_64: {
140 cflags: cflags_x86 + cflags_64,
141 srcs: srcs_x86,
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700142 },
143 },
Elliott Hughes8472b6c2021-01-06 14:52:46 -0800144 target: {
Dan Willemsence89a592021-10-19 20:22:25 -0700145 android_arm: {
146 cflags: [
147 // Since we're building for the platform, we claim to be Linux rather than
148 // Android so we use getauxval() directly instead of the NDK
149 // android_getCpuFeatures which isn't available to us anyway.
150 "-DARMV8_OS_LINUX",
151 ],
152 },
Elliott Hughes8472b6c2021-01-06 14:52:46 -0800153 android_x86: {
154 cflags: cflags_android_x86,
155 },
156 android_x86_64: {
157 cflags: cflags_android_x86,
158 },
Dan Willemsence89a592021-10-19 20:22:25 -0700159 darwin_arm64: {
160 cflags: [
161 "-DARMV8_OS_MACOS",
162 ],
163 },
164 linux_arm64: {
165 cflags: [
166 // Since we're building for the platform, we claim to be Linux rather than
167 // Android so we use getauxval() directly instead of the NDK
168 // android_getCpuFeatures which isn't available to us anyway.
169 "-DARMV8_OS_LINUX",
170 ],
171 },
Elliott Hughes8472b6c2021-01-06 14:52:46 -0800172 },
Dan Albertca7b4152019-06-11 16:32:07 -0700173}
174
175cc_library {
176 name: "libz",
177 defaults: ["libz_defaults"],
178
179 host_supported: true,
180 unique_host_soname: true,
181 static_ndk_lib: true,
182
183 vendor_available: true,
Justin Yune66fac52020-11-11 18:26:47 +0900184 product_available: true,
Dan Albertca7b4152019-06-11 16:32:07 -0700185 vndk: {
186 enabled: true,
187 support_system_process: true,
188 },
Yifan Hongd4b6e522020-01-21 19:28:33 -0800189 ramdisk_available: true,
Yifan Hongc777f202020-10-21 18:44:36 -0700190 vendor_ramdisk_available: true,
Dan Albertca7b4152019-06-11 16:32:07 -0700191 recovery_available: true,
192 native_bridge_supported: true,
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700193
194 target: {
Dan Willemsen0bb579c2016-11-04 12:27:30 -0700195 linux_bionic: {
196 enabled: true,
197 },
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700198 windows: {
199 enabled: true,
200 },
201 },
Jiyong Parkd8ff0c72020-05-18 09:30:14 +0000202
203 stubs: {
204 versions: [
205 "29",
206 "30",
207 ],
208 symbol_file: "libz.map.txt",
209 },
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700210}
211
Kelvin Zhange6a6dbd2021-01-12 14:54:06 -0500212// A more stable build of libz. Build configuration of this library should be
213// the same for different targets. This is only used by imgdiff.
214
215cc_library {
216 name: "libz_stable",
217 visibility: [
218 "//bootable/recovery/applypatch",
219 "//bootable/recovery/tests",
220 ],
221 cflags: [
222 // We do support hidden visibility, so turn that on.
223 "-DHAVE_HIDDEN",
224 // We do support const, so turn that on.
225 "-DZLIB_CONST",
Vishalcj174edd88d2021-05-11 13:46:03 +0700226 // Enable -O3 as per chromium
227 "-O3",
Kelvin Zhange6a6dbd2021-01-12 14:54:06 -0500228 "-Wall",
229 "-Werror",
230 "-Wno-unused",
231 "-Wno-unused-parameter",
232 ],
233 stl: "none",
234 export_include_dirs: ["."],
235 srcs: libz_srcs,
236
237 host_supported: true,
238 vendor_available: true,
239 recovery_available: true,
240}
241
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700242cc_binary_host {
243 name: "minigzip",
Elliott Hughese7091dd2019-06-06 12:47:16 -0700244 srcs: ["contrib/minigzip/minigzip.c"],
Dan Willemsence89a592021-10-19 20:22:25 -0700245 cflags: [
246 "-Wall",
247 "-Werror",
248 "-DUSE_MMAP",
249 ],
Dan Willemsenc1b393b2016-07-06 19:05:32 -0700250 static_libs: ["libz"],
251 stl: "none",
252}
Dan Alberte405a262016-09-15 16:24:19 -0700253
Narayan Kamath1a14eb32017-01-06 12:49:24 +0000254cc_binary {
Elliott Hughese7091dd2019-06-06 12:47:16 -0700255 name: "zlib_bench",
256 srcs: ["contrib/bench/zlib_bench.cc"],
Dan Willemsence89a592021-10-19 20:22:25 -0700257 cflags: [
258 "-Wall",
259 "-Werror",
Florian Mayer5d3fb932022-03-23 17:26:51 -0700260 "-Wno-unused-parameter",
Dan Willemsence89a592021-10-19 20:22:25 -0700261 ],
Elliott Hughese7091dd2019-06-06 12:47:16 -0700262 host_supported: true,
Narayan Kamath1a14eb32017-01-06 12:49:24 +0000263 shared_libs: ["libz"],
Elliott Hughesce1c0372020-02-14 00:58:28 +0000264 // We build zlib_bench32 and zlib_bench64 so it's easy to test LP32.
265 compile_multilib: "both",
266 multilib: {
Dan Willemsence89a592021-10-19 20:22:25 -0700267 lib32: {
268 suffix: "32",
269 },
270 lib64: {
271 suffix: "64",
272 },
Elliott Hughesce1c0372020-02-14 00:58:28 +0000273 },
Narayan Kamath1a14eb32017-01-06 12:49:24 +0000274}
275
Elliott Hughes822a4b82020-06-17 09:01:27 -0700276cc_test {
277 name: "zlib_tests",
278 srcs: [
279 "contrib/tests/infcover.cc",
280 "contrib/tests/utils_unittest.cc",
281 "google/compression_utils_portable.cc",
282 ],
283 include_dirs: [
284 "external/zlib/google",
285 // These tests include "gtest.h" rather than the usual "gtest/gtest.h".
286 "external/googletest/googletest/include/gtest/",
287 ],
288 shared_libs: ["libz"],
289 host_supported: true,
290 test_suites: ["device-tests"],
291}
292
Elliott Hughes58b328a2020-05-01 15:46:14 -0700293ndk_headers {
294 name: "libz_headers",
295 from: "",
296 to: "",
297 srcs: [
298 "zconf.h",
299 "zlib.h",
300 ],
301 license: "LICENSE",
302}
Dan Alberte405a262016-09-15 16:24:19 -0700303
304ndk_library {
Dan Willemsen67ce3272017-04-07 15:34:26 -0700305 name: "libz",
Dan Alberte405a262016-09-15 16:24:19 -0700306 symbol_file: "libz.map.txt",
307 first_version: "9",
Dan Albert40f22ad2017-01-05 15:55:02 -0800308 unversioned_until: "current",
Dan Alberte405a262016-09-15 16:24:19 -0700309}