1package { 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 17// These cflags are shared --- not only between all architectures, 18// but between libz and libz_stable too. 19cflags_shared = [ 20 // Our compiler does support hidden visibility. 21 "-DHAVE_HIDDEN", 22 // Our compiler does support const. 23 "-DZLIB_CONST", 24 // Use the traditional Rabin-Karp rolling hash to match zlib DEFLATE output exactly. 25 "-DCHROMIUM_ZLIB_NO_CASTAGNOLI", 26 // Enable -O3 for everyone, as chromium's BUILD.gn does. 27 "-O3", 28 "-Wall", 29 "-Werror", 30 "-Wno-deprecated-non-prototype", 31 "-Wno-unused", 32 "-Wno-unused-parameter", 33] 34 35cflags_arm = [ 36 // Even the NDK dropped non-neon support in r24. 37 "-DADLER32_SIMD_NEON", 38 // HWCAP_CRC32 is checked at runtime, so it's okay to enable crc32 39 // acceleration for both 64-bit and 32-bit (which may be armv7, at 40 // least for NDK users). 41 "-DCRC32_ARMV8_CRC32", 42 // TODO: DINFLATE_CHUNK_SIMD_NEON causes `atest org.apache.harmony.tests.java.util.zip.DeflaterTest` failures. 43 // "-DINFLATE_CHUNK_SIMD_NEON", 44] 45cflags_arm64 = cflags_arm + ["-DINFLATE_CHUNK_READ_64LE"] 46 47cflags_riscv64 = [ 48 "-DRISCV_RVV", 49 "-DADLER32_SIMD_RVV", 50 "-DDEFLATE_SLIDE_HASH_RVV", 51 "-DINFLATE_CHUNK_GENERIC", 52 "-DINFLATE_CHUNK_READ_64LE", 53] 54 55// The *host* x86 configuration (with *lower* CPU feature requirements). 56cflags_x86 = [ 57 // See ARMV8_OS_LINUX above. 58 "-DX86_NOT_WINDOWS", 59 // Android's host CPU feature requirements are *lower* than the 60 // corresponding device CPU feature requirements, so it's easier to just 61 // say "no SIMD for you" rather than specificially disable SSSE3. 62 // We should have a conversation about that, but not until we at least have 63 // data on how many Studio users have CPUs that don't make the grade... 64 // https://issuetracker.google.com/171235570 65 "-DCPU_NO_SIMD", 66] 67cflags_x86_64 = cflags_x86 + ["-DINFLATE_CHUNK_READ_64LE"] 68 69// The additional *device* x86/x86_64 configuration. Devices have *higher* CPU 70// feature requirements than the host. 71cflags_android_x86 = [ 72 // Android's x86 and x86-64 ABIs both include SSE2 and SSSE3. 73 "-UCPU_NO_SIMD", 74 "-DADLER32_SIMD_SSSE3", 75 // TODO: DINFLATE_CHUNK_SIMD_SSE2 causes `atest org.apache.harmony.tests.java.util.zip.DeflaterTest` failures. 76 // "-DINFLATE_CHUNK_SIMD_SSE2", 77] 78 79libz_srcs = [ 80 "adler32.c", 81 "adler32_simd.c", 82 "compress.c", 83 "cpu_features.c", 84 "crc32.c", 85 "crc32_simd.c", 86 "crc_folding.c", 87 "deflate.c", 88 "gzclose.c", 89 "gzlib.c", 90 "gzread.c", 91 "gzwrite.c", 92 "infback.c", 93 "inffast.c", 94 "inflate.c", 95 "inftrees.c", 96 "trees.c", 97 "uncompr.c", 98 "zutil.c", 99 100 // Not-yet-enabled optimizations. 101 // See https://chromium-review.googlesource.com/749732. 102 // TODO: causes `atest org.apache.harmony.tests.java.util.zip.DeflaterTest` failures. 103 // "contrib/optimizations/inffast_chunk.c", 104 // "contrib/optimizations/inflate.c", 105] 106 107cc_defaults { 108 name: "libz_defaults", 109 defaults: [ 110 "bug_24465209_workaround", 111 ], 112 113 cflags: cflags_shared, 114 stl: "none", 115 export_include_dirs: ["."], 116 117 host_supported: true, 118 native_bridge_supported: true, 119 120 vendor_available: true, 121 product_available: true, 122 ramdisk_available: true, 123 vendor_ramdisk_available: true, 124 recovery_available: true, 125 126 arch: { 127 arm: { 128 cflags: cflags_arm, 129 }, 130 arm64: { 131 cflags: cflags_arm64, 132 }, 133 riscv64: { 134 cflags: cflags_riscv64, 135 }, 136 x86: { 137 cflags: cflags_x86, 138 }, 139 x86_64: { 140 cflags: cflags_x86_64, 141 }, 142 }, 143 target: { 144 android_arm: { 145 cflags: [ 146 // Since we're building for the platform, we claim to be Linux rather than 147 // Android so we use getauxval() directly instead of the NDK 148 // android_getCpuFeatures which isn't available to us anyway. 149 "-DARMV8_OS_LINUX", 150 ], 151 }, 152 android_x86: { 153 cflags: cflags_android_x86, 154 }, 155 android_x86_64: { 156 cflags: cflags_android_x86, 157 }, 158 darwin_arm64: { 159 cflags: [ 160 "-DARMV8_OS_MACOS", 161 ], 162 }, 163 linux_bionic: { 164 enabled: true, 165 }, 166 linux_arm64: { 167 cflags: [ 168 // Since we're building for the platform, we claim to be Linux rather than 169 // Android so we use getauxval() directly instead of the NDK 170 // android_getCpuFeatures which isn't available to us anyway. 171 "-DARMV8_OS_LINUX", 172 ], 173 }, 174 windows: { 175 enabled: true, 176 }, 177 }, 178} 179 180cc_library { 181 name: "libz", 182 defaults: ["libz_defaults"], 183 184 srcs: libz_srcs, 185 186 unique_host_soname: true, 187 static_ndk_lib: true, 188 189 double_loadable: true, 190 191 stubs: { 192 versions: [ 193 "29", 194 "30", 195 ], 196 symbol_file: "libz.map.txt", 197 }, 198 199 // linker/linker64 statically link zlib. 200 static: { 201 apex_available: [ 202 "com.android.runtime", 203 ], 204 }, 205 206 // When used by Vendor/Product APEX, 207 // libz should be treated like non-stable module. 208 // (Hence, should be bundled in APEX). 209 target: { 210 product: { 211 no_stubs: true, 212 }, 213 vendor: { 214 no_stubs: true, 215 }, 216 }, 217 218 afdo: true, 219} 220 221// A build of libz with identical behavior between architectures. 222// Used by legacy OTA tools such as imgdiff and updater and their tests. 223// New code should not use this library, because new code should not make 224// assumptions about the _compressed_ bits, beyond the fact that they will 225// decompress to the same input bytes. The actual compressed byte sequences 226// can and do differ over time. 227cc_library { 228 name: "libz_stable", 229 visibility: [ 230 "//bootable/recovery/applypatch", 231 "//bootable/recovery/tests", 232 "//bootable/recovery/updater", 233 "//bootable/deprecated-ota/applypatch", 234 "//bootable/deprecated-ota/tests", 235 "//bootable/deprecated-ota/updater", 236 ], 237 // We only use the shared flags here; the whole point is that this 238 // library behaves the same on all different architectures. 239 cflags: cflags_shared, 240 stl: "none", 241 export_include_dirs: ["."], 242 srcs: libz_srcs, 243 host_supported: true, 244 vendor_available: true, 245 recovery_available: true, 246} 247 248cc_binary { 249 name: "zlib_bench", 250 srcs: ["contrib/bench/zlib_bench.cc"], 251 cflags: [ 252 "-Wall", 253 "-Werror", 254 "-Wno-deprecated-non-prototype", 255 "-Wno-unused-parameter", 256 ], 257 host_supported: true, 258 shared_libs: ["libz"], 259 // We build zlib_bench32 and zlib_bench64 so it's easy to test LP32. 260 compile_multilib: "both", 261 multilib: { 262 lib32: { 263 suffix: "32", 264 }, 265 lib64: { 266 suffix: "64", 267 }, 268 }, 269} 270 271cc_library { 272 name: "zlib_google_compression_utils_portable", 273 defaults: ["libz_defaults"], 274 srcs: [ 275 "google/compression_utils_portable.cc", 276 ], 277 export_include_dirs: ["google"], 278 host_supported: true, 279 shared_libs: ["libz"], 280 sdk_version: "minimum", 281 visibility: ["//external/angle"], 282 apex_available: [ 283 "com.android.runtime", 284 "//apex_available:platform", 285 ], 286} 287 288cc_library_static { 289 name: "tflite_support_libz", 290 defaults: ["libz_defaults"], 291 srcs: [ 292 "contrib/minizip/ioapi.c", 293 "contrib/minizip/unzip.c", 294 ], 295 sdk_version: "current", 296 // TODO: switch this to "apex_inherit". 297 min_sdk_version: "30", 298 apex_available: [ 299 "//apex_available:platform", 300 "com.android.adservices", 301 "com.android.extservices", 302 ], 303} 304 305cc_test { 306 name: "zlib_tests", 307 srcs: [ 308 "contrib/tests/infcover.cc", 309 "contrib/tests/utils_unittest.cc", 310 ], 311 cflags: [ 312 "-DCMAKE_STANDALONE_UNITTESTS", 313 "-Wno-unused-parameter", 314 ], 315 include_dirs: [ 316 // These tests include "gtest.h" rather than the usual "gtest/gtest.h". 317 "external/googletest/googletest/include/gtest/", 318 ], 319 shared_libs: ["libz"], 320 static_libs: ["zlib_google_compression_utils_portable"], 321 host_supported: true, 322 test_suites: ["device-tests"], 323} 324 325ndk_headers { 326 name: "libz_headers", 327 from: "", 328 to: "", 329 srcs: [ 330 "zconf.h", 331 "zlib.h", 332 ], 333 license: "LICENSE", 334} 335 336ndk_library { 337 name: "libz", 338 symbol_file: "libz.map.txt", 339 first_version: "9", 340 unversioned_until: "current", 341} 342 343// Export zlib headers for inclusion in the musl sysroot. 344genrule { 345 name: "libc_musl_sysroot_zlib_headers", 346 visibility: ["//external/musl"], 347 srcs: [ 348 "LICENSE", 349 "zconf.h", 350 "zlib.h", 351 ], 352 out: ["libc_musl_sysroot_zlib_headers.zip"], 353 tools: [ 354 "soong_zip", 355 "zip2zip", 356 ], 357 cmd: "$(location soong_zip) -o $(genDir)/sysroot.zip -symlinks=false" + 358 // NOTICE 359 " -j -f $(location LICENSE) " + 360 // headers 361 " -j -P include " + 362 " -f $(location zconf.h) " + 363 " -f $(location zlib.h) " + 364 " && " + 365 "$(location zip2zip) -i $(genDir)/sysroot.zip -o $(out) " + 366 " include/**/*:include " + 367 " LICENSE:NOTICE.zlib", 368} 369 370cc_defaults { 371 name: "zlib_fuzz_defaults", 372 static_libs: ["libz"], 373 host_supported: true, 374} 375 376cc_fuzz { 377 name: "zlib_deflate_fuzzer", 378 defaults: ["zlib_fuzz_defaults"], 379 srcs: ["contrib/tests/fuzzers/deflate_fuzzer.cc"], 380} 381 382cc_fuzz { 383 name: "zlib_deflate_set_dictionary_fuzzer", 384 defaults: ["zlib_fuzz_defaults"], 385 srcs: ["contrib/tests/fuzzers/deflate_set_dictionary_fuzzer.cc"], 386} 387 388cc_fuzz { 389 name: "zlib_inflate_fuzzer", 390 defaults: ["zlib_fuzz_defaults"], 391 srcs: ["contrib/tests/fuzzers/inflate_fuzzer.cc"], 392} 393 394cc_fuzz { 395 name: "zlib_inflate_with_header_fuzzer", 396 defaults: ["zlib_fuzz_defaults"], 397 srcs: ["contrib/tests/fuzzers/inflate_with_header_fuzzer.cc"], 398} 399 400cc_fuzz { 401 name: "zlib_streaming_inflate_fuzzer", 402 defaults: ["zlib_fuzz_defaults"], 403 srcs: ["contrib/tests/fuzzers/streaming_inflate_fuzzer.cc"], 404 fuzz_config: { 405 libfuzzer_options: ["max_len=256000"], 406 }, 407} 408 409cc_fuzz { 410 name: "zlib_uncompress_fuzzer", 411 defaults: ["zlib_fuzz_defaults"], 412 srcs: ["contrib/tests/fuzzers/uncompress_fuzzer.cc"], 413} 414