• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
17srcs_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.
24    "crc32_simd.c",
25]
26
27cflags_arm = [
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",
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",
34]
35cflags_arm_neon = [
36    // Undo the -DCPU_NO_SIMD from the generic (non-NEON) ARM flags.
37    "-UCPU_NO_SIMD",
38    // We no longer support non-Neon platform builds, but the NDK just has one libz.
39    "-DADLER32_SIMD_NEON",
40    // TODO: causes `atest org.apache.harmony.tests.java.util.zip.DeflaterTest` failures.
41    //    "-DINFLATE_CHUNK_SIMD_NEON",
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]
46cflags_arm64 = cflags_arm + cflags_arm_neon
47
48// The *host* x86 configuration (with *lower* CPU feature requirements).
49cflags_x86 = [
50    // See ARMV8_OS_LINUX above.
51    "-DX86_NOT_WINDOWS",
52    // TODO: see arm above.
53    //    "-DINFLATE_CHUNK_SIMD_SSE2",
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).
63cflags_android_x86 = [
64    // Android's x86/x86-64 ABI includes SSE2 and SSSE3.
65    "-UCPU_NO_SIMD",
66    "-DADLER32_SIMD_SSSE3",
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]
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
80libz_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
99cc_defaults {
100    name: "libz_defaults",
101
102    cflags: [
103        // We do support hidden visibility, so turn that on.
104        "-DHAVE_HIDDEN",
105        // We do support const, so turn that on.
106        "-DZLIB_CONST",
107        // Enable -O3 as per chromium.
108        "-O3",
109        "-Wall",
110        "-Werror",
111        "-Wno-unused",
112        "-Wno-unused-parameter",
113    ],
114    stl: "none",
115    export_include_dirs: ["."],
116    srcs: libz_srcs,
117
118    arch: {
119        arm: {
120            // TODO: This is to work around b/24465209. Remove after root cause
121            // is fixed.
122            pack_relocations: false,
123            ldflags: ["-Wl,--hash-style=both"],
124
125            cflags: cflags_arm,
126            neon: {
127                cflags: cflags_arm_neon,
128                srcs: srcs_opt,
129            },
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,
142        },
143    },
144    target: {
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        },
153        android_x86: {
154            cflags: cflags_android_x86,
155        },
156        android_x86_64: {
157            cflags: cflags_android_x86,
158        },
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        },
172    },
173}
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,
184    product_available: true,
185    vndk: {
186        enabled: true,
187        support_system_process: true,
188    },
189    ramdisk_available: true,
190    vendor_ramdisk_available: true,
191    recovery_available: true,
192    native_bridge_supported: true,
193
194    target: {
195        linux_bionic: {
196            enabled: true,
197        },
198        windows: {
199            enabled: true,
200        },
201    },
202
203    stubs: {
204        versions: [
205            "29",
206            "30",
207        ],
208        symbol_file: "libz.map.txt",
209    },
210}
211
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
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",
226        // Enable -O3 as per chromium
227        "-O3",
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
242cc_binary_host {
243    name: "minigzip",
244    srcs: ["contrib/minigzip/minigzip.c"],
245    cflags: [
246        "-Wall",
247        "-Werror",
248        "-DUSE_MMAP",
249    ],
250    static_libs: ["libz"],
251    stl: "none",
252}
253
254cc_binary {
255    name: "zlib_bench",
256    srcs: ["contrib/bench/zlib_bench.cc"],
257    cflags: [
258        "-Wall",
259        "-Werror",
260        "-Wno-unused-parameter",
261    ],
262    host_supported: true,
263    shared_libs: ["libz"],
264    // We build zlib_bench32 and zlib_bench64 so it's easy to test LP32.
265    compile_multilib: "both",
266    multilib: {
267        lib32: {
268            suffix: "32",
269        },
270        lib64: {
271            suffix: "64",
272        },
273    },
274}
275
276cc_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
293ndk_headers {
294    name: "libz_headers",
295    from: "",
296    to: "",
297    srcs: [
298        "zconf.h",
299        "zlib.h",
300    ],
301    license: "LICENSE",
302}
303
304ndk_library {
305    name: "libz",
306    symbol_file: "libz.map.txt",
307    first_version: "9",
308    unversioned_until: "current",
309}
310