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