Bob Badour | 3f2566f | 2021-02-11 17:09:40 -0800 | [diff] [blame] | 1 | package { |
| 2 | default_applicable_licenses: ["external_zlib_license"], |
| 3 | } |
| 4 | |
| 5 | license { |
| 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 Hughes | ce1c037 | 2020-02-14 00:58:28 +0000 | [diff] [blame] | 17 | srcs_opt = [ |
| 18 | "adler32_simd.c", |
| 19 | // See https://chromium-review.googlesource.com/749732. |
Dan Willemsen | ce89a59 | 2021-10-19 20:22:25 -0700 | [diff] [blame] | 20 | // TODO: causes `atest org.apache.harmony.tests.java.util.zip.DeflaterTest` failures. |
| 21 | // "contrib/optimizations/inffast_chunk.c", |
| 22 | // "contrib/optimizations/inflate.c", |
Elliott Hughes | ce1c037 | 2020-02-14 00:58:28 +0000 | [diff] [blame] | 23 | // This file doesn't build for non-neon, so it can't be in the main srcs. |
Elliott Hughes | ce1c037 | 2020-02-14 00:58:28 +0000 | [diff] [blame] | 24 | "crc32_simd.c", |
| 25 | ] |
| 26 | |
| 27 | cflags_arm = [ |
Elliott Hughes | ce1c037 | 2020-02-14 00:58:28 +0000 | [diff] [blame] | 28 | // 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 Hughes | 784a86b | 2020-12-07 12:43:35 -0800 | [diff] [blame] | 31 | // 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 Hughes | ce1c037 | 2020-02-14 00:58:28 +0000 | [diff] [blame] | 34 | ] |
| 35 | cflags_arm_neon = [ |
Elliott Hughes | 784a86b | 2020-12-07 12:43:35 -0800 | [diff] [blame] | 36 | // Undo the -DCPU_NO_SIMD from the generic (non-NEON) ARM flags. |
| 37 | "-UCPU_NO_SIMD", |
Elliott Hughes | ce1c037 | 2020-02-14 00:58:28 +0000 | [diff] [blame] | 38 | // We no longer support non-Neon platform builds, but the NDK just has one libz. |
| 39 | "-DADLER32_SIMD_NEON", |
Dan Willemsen | ce89a59 | 2021-10-19 20:22:25 -0700 | [diff] [blame] | 40 | // TODO: causes `atest org.apache.harmony.tests.java.util.zip.DeflaterTest` failures. |
| 41 | // "-DINFLATE_CHUNK_SIMD_NEON", |
Elliott Hughes | ce1c037 | 2020-02-14 00:58:28 +0000 | [diff] [blame] | 42 | // 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 | ] |
| 46 | cflags_arm64 = cflags_arm + cflags_arm_neon |
| 47 | |
Elliott Hughes | 8472b6c | 2021-01-06 14:52:46 -0800 | [diff] [blame] | 48 | // The *host* x86 configuration (with *lower* CPU feature requirements). |
Elliott Hughes | ce1c037 | 2020-02-14 00:58:28 +0000 | [diff] [blame] | 49 | cflags_x86 = [ |
| 50 | // See ARMV8_OS_LINUX above. |
| 51 | "-DX86_NOT_WINDOWS", |
Dan Willemsen | ce89a59 | 2021-10-19 20:22:25 -0700 | [diff] [blame] | 52 | // TODO: see arm above. |
| 53 | // "-DINFLATE_CHUNK_SIMD_SSE2", |
Elliott Hughes | 8472b6c | 2021-01-06 14:52:46 -0800 | [diff] [blame] | 54 | // 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). |
| 63 | cflags_android_x86 = [ |
| 64 | // Android's x86/x86-64 ABI includes SSE2 and SSSE3. |
| 65 | "-UCPU_NO_SIMD", |
| 66 | "-DADLER32_SIMD_SSSE3", |
Elliott Hughes | ce1c037 | 2020-02-14 00:58:28 +0000 | [diff] [blame] | 67 | // 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 | ] |
| 72 | srcs_x86 = [ |
| 73 | "crc_folding.c", |
| 74 | "fill_window_sse.c", |
| 75 | ] + srcs_opt |
| 76 | |
| 77 | // This optimization is applicable to arm64 and x86-64. |
| 78 | cflags_64 = ["-DINFLATE_CHUNK_READ_64LE"] |
| 79 | |
Kelvin Zhang | e6a6dbd | 2021-01-12 14:54:06 -0500 | [diff] [blame] | 80 | libz_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 Albert | ca7b415 | 2019-06-11 16:32:07 -0700 | [diff] [blame] | 99 | cc_defaults { |
| 100 | name: "libz_defaults", |
Dan Willemsen | c1b393b | 2016-07-06 19:05:32 -0700 | [diff] [blame] | 101 | |
| 102 | cflags: [ |
Elliott Hughes | ce1c037 | 2020-02-14 00:58:28 +0000 | [diff] [blame] | 103 | // We do support hidden visibility, so turn that on. |
Elliott Hughes | 35329cd | 2019-04-10 14:56:06 -0700 | [diff] [blame] | 104 | "-DHAVE_HIDDEN", |
Elliott Hughes | ce1c037 | 2020-02-14 00:58:28 +0000 | [diff] [blame] | 105 | // We do support const, so turn that on. |
Tao Bao | 5604dec | 2016-12-19 13:29:53 -0800 | [diff] [blame] | 106 | "-DZLIB_CONST", |
Vishalcj17 | 4edd88d | 2021-05-11 13:46:03 +0700 | [diff] [blame] | 107 | // Enable -O3 as per chromium. |
| 108 | "-O3", |
Chih-Hung Hsieh | 3e5deb4 | 2017-09-29 11:41:33 -0700 | [diff] [blame] | 109 | "-Wall", |
| 110 | "-Werror", |
Elliott Hughes | e7091dd | 2019-06-06 12:47:16 -0700 | [diff] [blame] | 111 | "-Wno-unused", |
| 112 | "-Wno-unused-parameter", |
Dan Willemsen | c1b393b | 2016-07-06 19:05:32 -0700 | [diff] [blame] | 113 | ], |
| 114 | stl: "none", |
| 115 | export_include_dirs: ["."], |
Kelvin Zhang | e6a6dbd | 2021-01-12 14:54:06 -0500 | [diff] [blame] | 116 | srcs: libz_srcs, |
Dan Willemsen | c1b393b | 2016-07-06 19:05:32 -0700 | [diff] [blame] | 117 | |
| 118 | arch: { |
| 119 | arm: { |
Elliott Hughes | e7091dd | 2019-06-06 12:47:16 -0700 | [diff] [blame] | 120 | // TODO: This is to work around b/24465209. Remove after root cause |
| 121 | // is fixed. |
Chih-Hung Hsieh | 19b536b | 2018-05-23 18:52:18 -0700 | [diff] [blame] | 122 | pack_relocations: false, |
Ian Pedowitz | cca7bd4 | 2018-01-18 16:22:54 -0800 | [diff] [blame] | 123 | ldflags: ["-Wl,--hash-style=both"], |
Elliott Hughes | ce1c037 | 2020-02-14 00:58:28 +0000 | [diff] [blame] | 124 | |
| 125 | cflags: cflags_arm, |
| 126 | neon: { |
| 127 | cflags: cflags_arm_neon, |
| 128 | srcs: srcs_opt, |
Dan Willemsen | ce89a59 | 2021-10-19 20:22:25 -0700 | [diff] [blame] | 129 | }, |
Elliott Hughes | ce1c037 | 2020-02-14 00:58:28 +0000 | [diff] [blame] | 130 | }, |
| 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 Willemsen | c1b393b | 2016-07-06 19:05:32 -0700 | [diff] [blame] | 142 | }, |
| 143 | }, |
Elliott Hughes | 8472b6c | 2021-01-06 14:52:46 -0800 | [diff] [blame] | 144 | target: { |
Dan Willemsen | ce89a59 | 2021-10-19 20:22:25 -0700 | [diff] [blame] | 145 | 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 Hughes | 8472b6c | 2021-01-06 14:52:46 -0800 | [diff] [blame] | 153 | android_x86: { |
| 154 | cflags: cflags_android_x86, |
| 155 | }, |
| 156 | android_x86_64: { |
| 157 | cflags: cflags_android_x86, |
| 158 | }, |
Dan Willemsen | ce89a59 | 2021-10-19 20:22:25 -0700 | [diff] [blame] | 159 | 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 Hughes | 8472b6c | 2021-01-06 14:52:46 -0800 | [diff] [blame] | 172 | }, |
Dan Albert | ca7b415 | 2019-06-11 16:32:07 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | cc_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 Yun | e66fac5 | 2020-11-11 18:26:47 +0900 | [diff] [blame] | 184 | product_available: true, |
Dan Albert | ca7b415 | 2019-06-11 16:32:07 -0700 | [diff] [blame] | 185 | vndk: { |
| 186 | enabled: true, |
| 187 | support_system_process: true, |
| 188 | }, |
Yifan Hong | d4b6e52 | 2020-01-21 19:28:33 -0800 | [diff] [blame] | 189 | ramdisk_available: true, |
Yifan Hong | c777f20 | 2020-10-21 18:44:36 -0700 | [diff] [blame] | 190 | vendor_ramdisk_available: true, |
Dan Albert | ca7b415 | 2019-06-11 16:32:07 -0700 | [diff] [blame] | 191 | recovery_available: true, |
| 192 | native_bridge_supported: true, |
Dan Willemsen | c1b393b | 2016-07-06 19:05:32 -0700 | [diff] [blame] | 193 | |
| 194 | target: { |
Dan Willemsen | 0bb579c | 2016-11-04 12:27:30 -0700 | [diff] [blame] | 195 | linux_bionic: { |
| 196 | enabled: true, |
| 197 | }, |
Dan Willemsen | c1b393b | 2016-07-06 19:05:32 -0700 | [diff] [blame] | 198 | windows: { |
| 199 | enabled: true, |
| 200 | }, |
| 201 | }, |
Jiyong Park | d8ff0c7 | 2020-05-18 09:30:14 +0000 | [diff] [blame] | 202 | |
| 203 | stubs: { |
| 204 | versions: [ |
| 205 | "29", |
| 206 | "30", |
| 207 | ], |
| 208 | symbol_file: "libz.map.txt", |
| 209 | }, |
Dan Willemsen | c1b393b | 2016-07-06 19:05:32 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Kelvin Zhang | e6a6dbd | 2021-01-12 14:54:06 -0500 | [diff] [blame] | 212 | // 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 | |
| 215 | cc_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", |
Vishalcj17 | 4edd88d | 2021-05-11 13:46:03 +0700 | [diff] [blame] | 226 | // Enable -O3 as per chromium |
| 227 | "-O3", |
Kelvin Zhang | e6a6dbd | 2021-01-12 14:54:06 -0500 | [diff] [blame] | 228 | "-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 Willemsen | c1b393b | 2016-07-06 19:05:32 -0700 | [diff] [blame] | 242 | cc_binary_host { |
| 243 | name: "minigzip", |
Elliott Hughes | e7091dd | 2019-06-06 12:47:16 -0700 | [diff] [blame] | 244 | srcs: ["contrib/minigzip/minigzip.c"], |
Dan Willemsen | ce89a59 | 2021-10-19 20:22:25 -0700 | [diff] [blame] | 245 | cflags: [ |
| 246 | "-Wall", |
| 247 | "-Werror", |
| 248 | "-DUSE_MMAP", |
| 249 | ], |
Dan Willemsen | c1b393b | 2016-07-06 19:05:32 -0700 | [diff] [blame] | 250 | static_libs: ["libz"], |
| 251 | stl: "none", |
| 252 | } |
Dan Albert | e405a26 | 2016-09-15 16:24:19 -0700 | [diff] [blame] | 253 | |
Narayan Kamath | 1a14eb3 | 2017-01-06 12:49:24 +0000 | [diff] [blame] | 254 | cc_binary { |
Elliott Hughes | e7091dd | 2019-06-06 12:47:16 -0700 | [diff] [blame] | 255 | name: "zlib_bench", |
| 256 | srcs: ["contrib/bench/zlib_bench.cc"], |
Dan Willemsen | ce89a59 | 2021-10-19 20:22:25 -0700 | [diff] [blame] | 257 | cflags: [ |
| 258 | "-Wall", |
| 259 | "-Werror", |
Florian Mayer | 5d3fb93 | 2022-03-23 17:26:51 -0700 | [diff] [blame] | 260 | "-Wno-unused-parameter", |
Dan Willemsen | ce89a59 | 2021-10-19 20:22:25 -0700 | [diff] [blame] | 261 | ], |
Elliott Hughes | e7091dd | 2019-06-06 12:47:16 -0700 | [diff] [blame] | 262 | host_supported: true, |
Narayan Kamath | 1a14eb3 | 2017-01-06 12:49:24 +0000 | [diff] [blame] | 263 | shared_libs: ["libz"], |
Elliott Hughes | ce1c037 | 2020-02-14 00:58:28 +0000 | [diff] [blame] | 264 | // We build zlib_bench32 and zlib_bench64 so it's easy to test LP32. |
| 265 | compile_multilib: "both", |
| 266 | multilib: { |
Dan Willemsen | ce89a59 | 2021-10-19 20:22:25 -0700 | [diff] [blame] | 267 | lib32: { |
| 268 | suffix: "32", |
| 269 | }, |
| 270 | lib64: { |
| 271 | suffix: "64", |
| 272 | }, |
Elliott Hughes | ce1c037 | 2020-02-14 00:58:28 +0000 | [diff] [blame] | 273 | }, |
Narayan Kamath | 1a14eb3 | 2017-01-06 12:49:24 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Elliott Hughes | 822a4b8 | 2020-06-17 09:01:27 -0700 | [diff] [blame] | 276 | cc_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 Hughes | 58b328a | 2020-05-01 15:46:14 -0700 | [diff] [blame] | 293 | ndk_headers { |
| 294 | name: "libz_headers", |
| 295 | from: "", |
| 296 | to: "", |
| 297 | srcs: [ |
| 298 | "zconf.h", |
| 299 | "zlib.h", |
| 300 | ], |
| 301 | license: "LICENSE", |
| 302 | } |
Dan Albert | e405a26 | 2016-09-15 16:24:19 -0700 | [diff] [blame] | 303 | |
| 304 | ndk_library { |
Dan Willemsen | 67ce327 | 2017-04-07 15:34:26 -0700 | [diff] [blame] | 305 | name: "libz", |
Dan Albert | e405a26 | 2016-09-15 16:24:19 -0700 | [diff] [blame] | 306 | symbol_file: "libz.map.txt", |
| 307 | first_version: "9", |
Dan Albert | 40f22ad | 2017-01-05 15:55:02 -0800 | [diff] [blame] | 308 | unversioned_until: "current", |
Dan Albert | e405a26 | 2016-09-15 16:24:19 -0700 | [diff] [blame] | 309 | } |