blob: 5d8f30aa3ec00f9b4d07cb8d4c74746b5198c44b [file] [log] [blame] [edit]
package {
default_applicable_licenses: ["external_zlib_license"],
}
license {
name: "external_zlib_license",
visibility: [":__subpackages__"],
license_kinds: [
"SPDX-license-identifier-BSD",
"SPDX-license-identifier-Zlib",
],
license_text: [
"LICENSE",
],
}
// These cflags are shared --- not only between all architectures,
// but between libz and libz_stable too.
cflags_shared = [
// Our compiler does support hidden visibility.
"-DHAVE_HIDDEN",
// Our compiler does support const.
"-DZLIB_CONST",
// Use the traditional Rabin-Karp rolling hash to match zlib DEFLATE output exactly.
"-DCHROMIUM_ZLIB_NO_CASTAGNOLI",
// Enable -O3 for everyone, as chromium's BUILD.gn does.
"-O3",
"-Wall",
"-Werror",
"-Wno-deprecated-non-prototype",
"-Wno-unused",
"-Wno-unused-parameter",
]
cflags_lp64 = [
"-DDEFLATE_CHUNK_WRITE_64LE",
"-DINFLATE_CHUNK_READ_64LE",
]
cflags_arm = [
// Even the NDK dropped non-neon support in r24.
"-DADLER32_SIMD_NEON",
// HWCAP_CRC32 is checked at runtime, so it's okay to enable crc32
// acceleration for both 64-bit and 32-bit (which may be armv7, at
// least for NDK users).
"-DCRC32_ARMV8_CRC32",
// TODO: DINFLATE_CHUNK_SIMD_NEON causes `atest org.apache.harmony.tests.java.util.zip.DeflaterTest` failures.
// "-DINFLATE_CHUNK_SIMD_NEON",
]
cflags_arm64 = cflags_arm + cflags_lp64
cflags_riscv64 = [
"-DRISCV_RVV",
"-DADLER32_SIMD_RVV",
"-DDEFLATE_SLIDE_HASH_RVV",
"-DINFLATE_CHUNK_GENERIC",
] + cflags_lp64
cflags_x86 = [
// Android's x86 and x86-64 ABIs both include SSE2 and SSSE3.
// The host doesn't (as of 2025), but this is guarded by a CPUID check.
"-DADLER32_SIMD_SSSE3",
// SSE4.2 is only in the x86-64 device ABI,
// and PCLMUL isn't guaranteed anywhere,
// but again this is guarded by a CPUID check.
"-DCRC32_SIMD_SSE42_PCLMUL",
// TODO: DINFLATE_CHUNK_SIMD_SSE2 causes `atest org.apache.harmony.tests.java.util.zip.DeflaterTest` failures.
// "-DINFLATE_CHUNK_SIMD_SSE2",
]
cflags_x86_64 = cflags_x86 + cflags_lp64
libz_srcs = [
"adler32.c",
"adler32_simd.c",
"compress.c",
"cpu_features.c",
"crc32.c",
"crc32_simd.c",
"crc_folding.c",
"deflate.c",
"gzclose.c",
"gzlib.c",
"gzread.c",
"gzwrite.c",
"infback.c",
"inffast.c",
"inflate.c",
"inftrees.c",
"trees.c",
"uncompr.c",
"zutil.c",
// Not-yet-enabled optimizations.
// See https://chromium-review.googlesource.com/749732.
// TODO: causes `atest org.apache.harmony.tests.java.util.zip.DeflaterTest` failures.
// "contrib/optimizations/inffast_chunk.c",
// "contrib/optimizations/inflate.c",
]
cc_defaults {
name: "libz_defaults",
defaults: [
"bug_24465209_workaround",
],
cflags: cflags_shared,
stl: "none",
export_include_dirs: ["."],
host_supported: true,
native_bridge_supported: true,
vendor_available: true,
product_available: true,
ramdisk_available: true,
vendor_ramdisk_available: true,
recovery_available: true,
arch: {
arm: {
cflags: cflags_arm,
},
arm64: {
cflags: cflags_arm64,
},
riscv64: {
cflags: cflags_riscv64,
},
x86: {
cflags: cflags_x86,
},
x86_64: {
cflags: cflags_x86_64,
},
},
target: {
//
// Tell zlib how to check for cpu features for all our supported combos.
//
linux_arm: {
cflags: [
"-DARMV8_OS_LINUX",
],
},
linux_arm64: {
cflags: [
"-DARMV8_OS_LINUX",
],
},
// riscv64 doesn't need anything, because zlib only supports Linux.
linux_x86: {
cflags: [
"-DX86_NOT_WINDOWS",
],
},
linux_x86_64: {
cflags: [
"-DX86_NOT_WINDOWS",
],
},
darwin_arm64: {
cflags: [
"-DARMV8_OS_MACOS",
],
},
darwin_x86_64: {
cflags: [
"-DX86_NOT_WINDOWS",
],
},
windows: {
enabled: true,
cflags: [
"-DX86_WINDOWS",
],
},
//
// zlib is needed by host bionic too.
//
linux_bionic: {
enabled: true,
},
},
}
cc_library {
name: "libz",
defaults: ["libz_defaults"],
srcs: libz_srcs,
unique_host_soname: true,
static_ndk_lib: true,
double_loadable: true,
stubs: {
versions: [
"29",
"30",
],
symbol_file: "libz.map.txt",
},
// Ignore the `internal_state` struct for ABI checks.
header_abi_checker: {
diff_flags: [
"-ignore-linker-set-key",
"_ZTI14internal_state",
],
},
// linker/linker64 statically link zlib.
static: {
apex_available: [
"com.android.runtime",
"com.android.appsearch",
],
},
// When used by Vendor/Product APEX,
// libz should be treated like non-stable module.
// (Hence, should be bundled in APEX).
target: {
product: {
no_stubs: true,
},
vendor: {
no_stubs: true,
},
},
afdo: true,
// TODO(b/390639586): Remove this line once the blocker is resolved.
min_sdk_version: "apex_inherit",
}
// A build of libz with identical behavior between architectures.
// Used by legacy OTA tools such as imgdiff and updater and their tests.
// New code should not use this library, because new code should not make
// assumptions about the _compressed_ bits, beyond the fact that they will
// decompress to the same input bytes. The actual compressed byte sequences
// can and do differ over time.
cc_library {
name: "libz_stable",
visibility: [
"//bootable/recovery/applypatch",
"//bootable/recovery/tests",
"//bootable/recovery/updater",
"//bootable/deprecated-ota/applypatch",
"//bootable/deprecated-ota/tests",
"//bootable/deprecated-ota/updater",
],
// We only use the shared flags here; the whole point is that this
// library behaves the same on all different architectures.
cflags: cflags_shared,
stl: "none",
export_include_dirs: ["."],
srcs: libz_srcs,
host_supported: true,
vendor_available: true,
recovery_available: true,
}
cc_binary {
name: "zlib_bench",
srcs: ["contrib/bench/zlib_bench.cc"],
cflags: [
"-Wall",
"-Werror",
"-Wno-deprecated-non-prototype",
"-Wno-unused-parameter",
],
host_supported: true,
shared_libs: ["libz"],
// We build zlib_bench32 and zlib_bench64 so it's easy to test LP32.
compile_multilib: "both",
multilib: {
lib32: {
suffix: "32",
},
lib64: {
suffix: "64",
},
},
}
cc_library {
name: "zlib_google_compression_utils_portable",
defaults: ["libz_defaults"],
srcs: [
"google/compression_utils_portable.cc",
],
export_include_dirs: ["google"],
host_supported: true,
shared_libs: ["libz"],
sdk_version: "minimum",
visibility: ["//external/angle"],
apex_available: [
"com.android.runtime",
"//apex_available:platform",
],
}
cc_library_static {
name: "tflite_support_libz",
defaults: ["libz_defaults"],
srcs: [
"contrib/minizip/ioapi.c",
"contrib/minizip/unzip.c",
],
sdk_version: "current",
// TODO: switch this to "apex_inherit".
min_sdk_version: "30",
apex_available: [
"//apex_available:platform",
"com.android.adservices",
"com.android.extservices",
],
}
cc_test {
name: "zlib_tests",
srcs: [
"contrib/tests/infcover.cc",
"contrib/tests/utils_unittest.cc",
],
cflags: [
"-DCMAKE_STANDALONE_UNITTESTS",
"-Wno-unused-parameter",
],
include_dirs: [
// These tests include "gtest.h" rather than the usual "gtest/gtest.h".
"external/googletest/googletest/include/gtest/",
],
shared_libs: ["libz"],
static_libs: ["zlib_google_compression_utils_portable"],
host_supported: true,
test_suites: ["device-tests"],
}
ndk_headers {
name: "libz_headers",
from: "",
to: "",
srcs: [
"zconf.h",
"zlib.h",
],
license: "LICENSE",
}
ndk_library {
name: "libz",
symbol_file: "libz.map.txt",
first_version: "9",
unversioned_until: "current",
bypass_artless_denylist: true,
}
// This runtime library does not depend on ART at all, so it simply gets an
// empty denylist.
// Export zlib headers for inclusion in the musl sysroot.
genrule {
name: "libc_musl_sysroot_zlib_headers",
visibility: ["//external/musl"],
srcs: [
"LICENSE",
"zconf.h",
"zlib.h",
],
out: ["libc_musl_sysroot_zlib_headers.zip"],
tools: [
"soong_zip",
"zip2zip",
],
cmd: "$(location soong_zip) -o $(genDir)/sysroot.zip -symlinks=false" +
// NOTICE
" -j -f $(location LICENSE) " +
// headers
" -j -P include " +
" -f $(location zconf.h) " +
" -f $(location zlib.h) " +
" && " +
"$(location zip2zip) -i $(genDir)/sysroot.zip -o $(out) " +
" include/**/*:include " +
" LICENSE:NOTICE.zlib",
}
cc_defaults {
name: "zlib_fuzz_defaults",
static_libs: ["libz"],
host_supported: true,
}
cc_fuzz {
name: "zlib_deflate_fuzzer",
defaults: ["zlib_fuzz_defaults"],
srcs: ["contrib/tests/fuzzers/deflate_fuzzer.cc"],
}
cc_fuzz {
name: "zlib_deflate_set_dictionary_fuzzer",
defaults: ["zlib_fuzz_defaults"],
srcs: ["contrib/tests/fuzzers/deflate_set_dictionary_fuzzer.cc"],
}
cc_fuzz {
name: "zlib_inflate_fuzzer",
defaults: ["zlib_fuzz_defaults"],
srcs: ["contrib/tests/fuzzers/inflate_fuzzer.cc"],
}
cc_fuzz {
name: "zlib_inflate_with_header_fuzzer",
defaults: ["zlib_fuzz_defaults"],
srcs: ["contrib/tests/fuzzers/inflate_with_header_fuzzer.cc"],
}
cc_fuzz {
name: "zlib_streaming_inflate_fuzzer",
defaults: ["zlib_fuzz_defaults"],
srcs: ["contrib/tests/fuzzers/streaming_inflate_fuzzer.cc"],
fuzz_config: {
libfuzzer_options: ["max_len=256000"],
},
}
cc_fuzz {
name: "zlib_uncompress_fuzzer",
defaults: ["zlib_fuzz_defaults"],
srcs: ["contrib/tests/fuzzers/uncompress_fuzzer.cc"],
}