• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Fork of external/zlib to external/tflite-support/third_party/zlib.
2// TODO(b/233151429): Clean up external/tflite-support/third_party/zlib so that it contains the
3// minimum set of files needed to support `BertNLClassifier`.
4
5package {
6    default_applicable_licenses: [
7        "external_tflite-support_third_party_zlib_license",
8    ],
9}
10
11// Added automatically by a large-scale-change that took the approach of
12// 'apply every license found to every target'. While this makes sure we respect
13// every license restriction, it may not be entirely correct.
14//
15// e.g. GPL in an MIT project might only apply to the contrib/ directory.
16//
17// Please consider splitting the single license below into multiple licenses,
18// taking care not to lose any license_kind information, and overriding the
19// default license using the 'licenses: [...]' property on targets as needed.
20//
21// For unused files, consider creating a 'fileGroup' with "//visibility:private"
22// to attach the license to, and including a comment whether the files may be
23// used in the current project.
24// See: http://go/android-license-faq
25license {
26    name: "external_tflite-support_third_party_zlib_license",
27    visibility: [":__subpackages__"],
28    license_kinds: [
29        "SPDX-license-identifier-BSD",
30        "SPDX-license-identifier-Zlib",
31    ],
32    license_text: [
33        "LICENSE",
34    ],
35}
36
37srcs_opt = [
38    "adler32_simd.c",
39    // See https://chromium-review.googlesource.com/749732.
40    // TODO: causes `atest org.apache.harmony.tests.java.util.zip.DeflaterTest` failures.
41    //    "contrib/optimizations/inffast_chunk.c",
42    //    "contrib/optimizations/inflate.c",
43    // This file doesn't build for non-neon, so it can't be in the main srcs.
44    "crc32_simd.c",
45]
46
47cflags_arm = [
48    // Testing with zlib_bench shows -O3 is a win for ARM but a bit of a wash
49    // for x86, so match the BUILD file in only enabling this for ARM.
50    "-O3",
51    // We need a non-NEON libz.a for the NDK, and cpu_features.c won't build
52    // without this.
53    "-DCPU_NO_SIMD",
54]
55cflags_arm_neon = [
56    // Undo the -DCPU_NO_SIMD from the generic (non-NEON) ARM flags.
57    "-UCPU_NO_SIMD",
58    // We no longer support non-Neon platform builds, but the NDK just has one libz.
59    "-DADLER32_SIMD_NEON",
60    // TODO: causes `atest org.apache.harmony.tests.java.util.zip.DeflaterTest` failures.
61    //    "-DINFLATE_CHUNK_SIMD_NEON",
62    // HWCAP_CRC32 is checked at runtime, so it's okay to turn crc32
63    // acceleration on for both 32- and 64-bit.
64    "-DCRC32_ARMV8_CRC32",
65]
66cflags_arm64 = cflags_arm + cflags_arm_neon
67
68// The *host* x86 configuration (with *lower* CPU feature requirements).
69cflags_x86 = [
70    // See ARMV8_OS_LINUX above.
71    "-DX86_NOT_WINDOWS",
72    // TODO: see arm above.
73    //    "-DINFLATE_CHUNK_SIMD_SSE2",
74    // Android's host CPU feature requirements are *lower* than the
75    // corresponding device CPU feature requirements, so it's easier to just
76    // say "no SIMD for you" rather than specificially disable SSSE3.
77    // We should have a conversation about that, but not until we at least have
78    // data on how many Studio users have CPUs that don't make the grade...
79    // https://issuetracker.google.com/171235570
80    "-DCPU_NO_SIMD",
81]
82// The *device* x86 configuration (with *higher* CPU feature requirements).
83cflags_android_x86 = [
84    // Android's x86/x86-64 ABI includes SSE2 and SSSE3.
85    "-UCPU_NO_SIMD",
86    "-DADLER32_SIMD_SSSE3",
87    // PCLMUL isn't in the ABI, but it won't actually be used unless CPUID
88    // reports that the processor really does have the instruction.
89    "-mpclmul",
90    "-DCRC32_SIMD_SSE42_PCLMUL",
91]
92srcs_x86 = [
93    "crc_folding.c",
94    "fill_window_sse.c",
95] + srcs_opt
96
97// This optimization is applicable to arm64 and x86-64.
98cflags_64 = ["-DINFLATE_CHUNK_READ_64LE"]
99
100tflite_support_libz_srcs = [
101    "adler32.c",
102    "compress.c",
103    "cpu_features.c",
104    "crc32.c",
105    "deflate.c",
106    "gzclose.c",
107    "gzlib.c",
108    "gzread.c",
109    "gzwrite.c",
110    "infback.c",
111    "inffast.c",
112    "inflate.c",
113    "inftrees.c",
114    "trees.c",
115    "uncompr.c",
116    "zutil.c",
117    "contrib/minizip/ioapi.c",
118    "contrib/minizip/unzip.c",
119]
120
121cc_defaults {
122    name: "tflite_support_libz_defaults",
123
124    cflags: [
125        // We do support hidden visibility, so turn that on.
126        "-DHAVE_HIDDEN",
127        // We do support const, so turn that on.
128        "-DZLIB_CONST",
129        // Enable -O3 as per chromium.
130        "-O3",
131        "-Wall",
132        "-Werror",
133        "-Wno-unused",
134        "-Wno-unused-parameter",
135    ],
136    stl: "none",
137    export_include_dirs: ["."],
138    srcs: tflite_support_libz_srcs,
139
140    arch: {
141        arm: {
142            // TODO: This is to work around b/24465209. Remove after root cause
143            // is fixed.
144            pack_relocations: false,
145            ldflags: ["-Wl,--hash-style=both"],
146
147            cflags: cflags_arm,
148            neon: {
149                cflags: cflags_arm_neon,
150                srcs: srcs_opt,
151            },
152        },
153        arm64: {
154            cflags: cflags_arm64 + cflags_64,
155            srcs: srcs_opt,
156        },
157        x86: {
158            cflags: cflags_x86,
159            srcs: srcs_x86,
160        },
161        x86_64: {
162            cflags: cflags_x86 + cflags_64,
163            srcs: srcs_x86,
164        },
165    },
166    target: {
167        android_arm: {
168            cflags: [
169                // Since we're building for the platform, we claim to be Linux rather than
170                // Android so we use getauxval() directly instead of the NDK
171                // android_getCpuFeatures which isn't available to us anyway.
172                "-DARMV8_OS_LINUX",
173            ],
174        },
175        android_x86: {
176            cflags: cflags_android_x86,
177        },
178        android_x86_64: {
179            cflags: cflags_android_x86,
180        },
181        darwin_arm64: {
182            cflags: [
183                "-DARMV8_OS_MACOS",
184            ],
185        },
186        linux_arm64: {
187            cflags: [
188                // Since we're building for the platform, we claim to be Linux rather than
189                // Android so we use getauxval() directly instead of the NDK
190                // android_getCpuFeatures which isn't available to us anyway.
191                "-DARMV8_OS_LINUX",
192            ],
193        },
194    },
195}
196
197cc_library_static {
198    name: "tflite_support_libz",
199    defaults: ["tflite_support_libz_defaults"],
200
201    host_supported: true,
202    unique_host_soname: true,
203    static_ndk_lib: true,
204    sdk_version: "current",
205    min_sdk_version: "30",
206
207    vendor_available: true,
208    product_available: true,
209    ramdisk_available: true,
210    vendor_ramdisk_available: true,
211    recovery_available: true,
212    native_bridge_supported: true,
213
214    target: {
215        linux_bionic: {
216            enabled: true,
217        },
218        windows: {
219            enabled: true,
220        },
221    },
222
223    apex_available: [
224        "//apex_available:platform",
225        "com.android.adservices",
226        "com.android.extservices",
227    ],
228}
229