• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2013 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import("//build/config/compiler/compiler.gni")
6
7if (build_with_chromium) {
8  import("//testing/test.gni")
9}
10
11if (current_cpu == "arm" || current_cpu == "arm64") {
12  import("//build/config/arm.gni")
13}
14
15config("zlib_config") {
16  include_dirs = [ "." ]
17}
18
19config("zlib_internal_config") {
20  defines = [ "ZLIB_IMPLEMENTATION" ]
21
22  if (!is_debug) {
23    # Build code using -O3, see: crbug.com/1084371.
24    configs = [ "//build/config/compiler:optimize_speed" ]
25  }
26  if (is_debug || use_libfuzzer) {
27    # Enable zlib's asserts in debug and fuzzer builds.
28    defines += [ "ZLIB_DEBUG" ]
29  }
30}
31
32source_set("zlib_common_headers") {
33  sources = [
34    "chromeconf.h",
35    "deflate.h",
36    "inffast.h",
37    "inffixed.h",
38    "inflate.h",
39    "inftrees.h",
40    "zconf.h",
41    "zlib.h",
42    "zutil.h",
43  ]
44}
45
46use_arm_neon_optimizations = false
47if ((current_cpu == "arm" || current_cpu == "arm64") &&
48    !(is_win && !is_clang)) {
49  # TODO(richard.townsend@arm.com): Optimizations temporarily disabled for
50  # Windows on Arm MSVC builds, see http://crbug.com/v8/10012.
51  if (arm_use_neon) {
52    use_arm_neon_optimizations = true
53  }
54}
55
56use_x86_x64_optimizations =
57    (current_cpu == "x86" || current_cpu == "x64") && !is_ios
58
59config("zlib_adler32_simd_config") {
60  if (use_x86_x64_optimizations) {
61    defines = [ "ADLER32_SIMD_SSSE3" ]
62    if (is_win) {
63      defines += [ "X86_WINDOWS" ]
64    } else {
65      defines += [ "X86_NOT_WINDOWS" ]
66    }
67  }
68
69  if (use_arm_neon_optimizations) {
70    defines = [ "ADLER32_SIMD_NEON" ]
71  }
72}
73
74source_set("zlib_adler32_simd") {
75  visibility = [ ":*" ]
76
77  if (use_x86_x64_optimizations) {
78    sources = [
79      "adler32_simd.c",
80      "adler32_simd.h",
81    ]
82
83    if (!is_win || is_clang) {
84      cflags = [ "-mssse3" ]
85    }
86  }
87
88  if (use_arm_neon_optimizations) {
89    sources = [
90      "adler32_simd.c",
91      "adler32_simd.h",
92    ]
93  }
94
95  configs += [ ":zlib_internal_config" ]
96
97  public_configs = [ ":zlib_adler32_simd_config" ]
98
99  public_deps = [ ":zlib_common_headers" ]
100}
101
102if (use_arm_neon_optimizations) {
103  config("zlib_arm_crc32_config") {
104    # Disabled for iPhone, as described in DDI0487C_a_armv8_arm:
105    #  "All implementations of the ARMv8.1 architecture are required to
106    #   implement the CRC32* instructions. These are optional in ARMv8.0."
107    if (!is_ios) {
108      defines = [ "CRC32_ARMV8_CRC32" ]
109      if (is_android) {
110        defines += [ "ARMV8_OS_ANDROID" ]
111      } else if (is_linux || is_chromeos) {
112        defines += [ "ARMV8_OS_LINUX" ]
113      } else if (is_mac) {
114        defines += [ "ARMV8_OS_MACOS" ]
115      } else if (is_fuchsia) {
116        defines += [ "ARMV8_OS_FUCHSIA" ]
117      } else if (is_win) {
118        defines += [ "ARMV8_OS_WINDOWS" ]
119      } else {
120        assert(false, "Unsupported ARM OS")
121      }
122    }
123  }
124
125  source_set("zlib_arm_crc32") {
126    visibility = [ ":*" ]
127
128    if (!is_ios) {
129      include_dirs = [ "." ]
130
131      if (!is_win && !is_clang) {
132        assert(!use_thin_lto,
133               "ThinLTO fails mixing different module-level targets")
134        cflags_c = [ "-march=armv8-a+crc" ]
135      }
136
137      sources = [
138        "crc32_simd.c",
139        "crc32_simd.h",
140      ]
141    }
142
143    configs += [ ":zlib_internal_config" ]
144
145    public_configs = [ ":zlib_arm_crc32_config" ]
146
147    public_deps = [ ":zlib_common_headers" ]
148  }
149}
150
151config("zlib_inflate_chunk_simd_config") {
152  if (use_x86_x64_optimizations) {
153    defines = [ "INFLATE_CHUNK_SIMD_SSE2" ]
154
155    if (current_cpu == "x64") {
156      defines += [ "INFLATE_CHUNK_READ_64LE" ]
157    }
158  }
159
160  if (use_arm_neon_optimizations) {
161    defines = [ "INFLATE_CHUNK_SIMD_NEON" ]
162
163    if (current_cpu == "arm64") {
164      defines += [ "INFLATE_CHUNK_READ_64LE" ]
165    }
166  }
167}
168
169source_set("zlib_inflate_chunk_simd") {
170  visibility = [ ":*" ]
171
172  if (use_x86_x64_optimizations || use_arm_neon_optimizations) {
173    include_dirs = [ "." ]
174
175    sources = [
176      "contrib/optimizations/chunkcopy.h",
177      "contrib/optimizations/inffast_chunk.c",
178      "contrib/optimizations/inffast_chunk.h",
179      "contrib/optimizations/inflate.c",
180    ]
181  }
182
183  configs += [ ":zlib_internal_config" ]
184
185  # Needed for MSVC, which is still supported by V8 and PDFium. zlib uses K&R C
186  # style function declarations, which triggers warning C4131.
187  configs -= [ "//build/config/compiler:chromium_code" ]
188  configs += [ "//build/config/compiler:no_chromium_code" ]
189
190  public_configs = [ ":zlib_inflate_chunk_simd_config" ]
191
192  public_deps = [ ":zlib_common_headers" ]
193}
194
195config("zlib_crc32_simd_config") {
196  if (use_x86_x64_optimizations) {
197    defines = [ "CRC32_SIMD_SSE42_PCLMUL" ]
198  }
199}
200
201source_set("zlib_crc32_simd") {
202  visibility = [ ":*" ]
203
204  if (use_x86_x64_optimizations) {
205    sources = [
206      "crc32_simd.c",
207      "crc32_simd.h",
208    ]
209
210    if (!is_win || is_clang) {
211      cflags = [
212        "-msse4.2",
213        "-mpclmul",
214      ]
215    }
216  }
217
218  configs += [ ":zlib_internal_config" ]
219
220  public_configs = [ ":zlib_crc32_simd_config" ]
221  public_deps = [ ":zlib_common_headers" ]
222}
223
224config("zlib_x86_simd_config") {
225  if (use_x86_x64_optimizations) {
226    defines = [
227      "CRC32_SIMD_SSE42_PCLMUL",
228      "DEFLATE_FILL_WINDOW_SSE2",
229    ]
230  }
231}
232
233source_set("zlib_x86_simd") {
234  visibility = [ ":*" ]
235
236  if (use_x86_x64_optimizations) {
237    sources = [
238      "crc_folding.c",
239      "fill_window_sse.c",
240    ]
241
242    if (!is_win || is_clang) {
243      cflags = [
244        "-msse4.2",
245        "-mpclmul",
246      ]
247    }
248  }
249
250  configs += [ ":zlib_internal_config" ]
251
252  public_configs = [ ":zlib_x86_simd_config" ]
253
254  public_deps = [ ":zlib_common_headers" ]
255}
256
257config("zlib_warnings") {
258  if (is_clang && use_x86_x64_optimizations) {
259    cflags = [ "-Wno-incompatible-pointer-types" ]
260  }
261}
262
263component("zlib") {
264  if (!is_win) {
265    # Don't stomp on "libzlib" on other platforms.
266    output_name = "chrome_zlib"
267  }
268
269  sources = [
270    "adler32.c",
271    "chromeconf.h",
272    "compress.c",
273    "contrib/optimizations/insert_string.h",
274    "cpu_features.c",
275    "cpu_features.h",
276    "crc32.c",
277    "crc32.h",
278    "deflate.c",
279    "deflate.h",
280    "gzclose.c",
281    "gzguts.h",
282    "gzlib.c",
283    "gzread.c",
284    "gzwrite.c",
285    "infback.c",
286    "inffast.c",
287    "inffast.h",
288    "inffixed.h",
289    "inflate.h",
290    "inftrees.c",
291    "inftrees.h",
292    "trees.c",
293    "trees.h",
294    "uncompr.c",
295    "zconf.h",
296    "zlib.h",
297    "zutil.c",
298    "zutil.h",
299  ]
300
301  defines = []
302  deps = []
303
304  if (!use_x86_x64_optimizations && !use_arm_neon_optimizations) {
305    # Apparently android_cronet bot builds with NEON disabled and
306    # we also should disable optimizations for iOS@x86 (a.k.a. simulator).
307    defines += [ "CPU_NO_SIMD" ]
308  }
309
310  if (is_ios) {
311    # iOS@ARM is a special case where we always have NEON but don't check
312    # for crypto extensions.
313    # TODO(cavalcantii): verify what is the current state of CPU features
314    # shipped on latest iOS devices.
315    defines += [ "ARM_OS_IOS" ]
316  }
317
318  if (use_x86_x64_optimizations || use_arm_neon_optimizations) {
319    deps += [
320      ":zlib_adler32_simd",
321      ":zlib_inflate_chunk_simd",
322    ]
323
324    if (use_x86_x64_optimizations) {
325      deps += [ ":zlib_crc32_simd" ]
326    } else if (use_arm_neon_optimizations) {
327      sources += [ "contrib/optimizations/slide_hash_neon.h" ]
328      deps += [ ":zlib_arm_crc32" ]
329    }
330  } else {
331    sources += [ "inflate.c" ]
332  }
333
334  deps += [ ":zlib_x86_simd" ]
335
336  if (is_android) {
337    import("//build/config/android/config.gni")
338    if (defined(android_ndk_root) && android_ndk_root != "") {
339      deps += [ "//third_party/android_ndk:cpu_features" ]
340    } else {
341      assert(false, "CPU detection requires the Android NDK")
342    }
343  }
344
345  configs -= [ "//build/config/compiler:chromium_code" ]
346  configs += [ "//build/config/compiler:no_chromium_code" ]
347
348  public_configs = [ ":zlib_config" ]
349
350  configs += [
351    ":zlib_internal_config",
352
353    # Must be after no_chromium_code for warning flags to be ordered correctly.
354    ":zlib_warnings",
355  ]
356
357  allow_circular_includes_from = deps
358}
359
360config("minizip_warnings") {
361  visibility = [ ":*" ]
362
363  if (is_clang) {
364    # zlib uses `if ((a == b))` for some reason.
365    cflags = [ "-Wno-parentheses-equality" ]
366  }
367}
368
369static_library("minizip") {
370  sources = [
371    "contrib/minizip/ioapi.c",
372    "contrib/minizip/ioapi.h",
373    "contrib/minizip/iowin32.c",
374    "contrib/minizip/iowin32.h",
375    "contrib/minizip/unzip.c",
376    "contrib/minizip/unzip.h",
377    "contrib/minizip/zip.c",
378    "contrib/minizip/zip.h",
379  ]
380
381  if (!is_win) {
382    sources -= [
383      "contrib/minizip/iowin32.c",
384      "contrib/minizip/iowin32.h",
385    ]
386  }
387
388  if (is_apple || is_android || is_nacl) {
389    # Mac, Android and the BSDs don't have fopen64, ftello64, or fseeko64. We
390    # use fopen, ftell, and fseek instead on these systems.
391    defines = [ "USE_FILE32API" ]
392  }
393
394  deps = [ ":zlib" ]
395
396  configs -= [ "//build/config/compiler:chromium_code" ]
397  configs += [ "//build/config/compiler:no_chromium_code" ]
398
399  public_configs = [ ":zlib_config" ]
400
401  configs += [
402    # Must be after no_chromium_code for warning flags to be ordered correctly.
403    ":minizip_warnings",
404  ]
405}
406
407executable("zlib_bench") {
408  include_dirs = [ "." ]
409
410  sources = [ "contrib/bench/zlib_bench.cc" ]
411  if (!is_debug) {
412    configs -= [ "//build/config/compiler:default_optimization" ]
413    configs += [ "//build/config/compiler:optimize_speed" ]
414  }
415
416  deps = [ ":zlib" ]
417
418  configs -= [ "//build/config/compiler:chromium_code" ]
419  configs += [ "//build/config/compiler:no_chromium_code" ]
420}
421
422if (!is_win || target_os != "winuwp") {
423  executable("minizip_bin") {
424    include_dirs = [ "." ]
425
426    sources = [ "contrib/minizip/minizip.c" ]
427
428    if (is_clang) {
429      cflags = [ "-Wno-incompatible-pointer-types-discards-qualifiers" ]
430    }
431
432    if (!is_debug) {
433      configs -= [ "//build/config/compiler:default_optimization" ]
434      configs += [ "//build/config/compiler:optimize_speed" ]
435    }
436
437    deps = [ ":minizip" ]
438
439    configs -= [ "//build/config/compiler:chromium_code" ]
440    configs += [ "//build/config/compiler:no_chromium_code" ]
441  }
442
443  executable("miniunz_bin") {
444    include_dirs = [ "." ]
445
446    sources = [ "contrib/minizip/miniunz.c" ]
447
448    if (is_clang) {
449      cflags = [ "-Wno-incompatible-pointer-types-discards-qualifiers" ]
450    }
451
452    if (!is_debug) {
453      configs -= [ "//build/config/compiler:default_optimization" ]
454      configs += [ "//build/config/compiler:optimize_speed" ]
455    }
456
457    deps = [ ":minizip" ]
458
459    configs -= [ "//build/config/compiler:chromium_code" ]
460    configs += [ "//build/config/compiler:no_chromium_code" ]
461  }
462}
463
464if (build_with_chromium) {
465  test("zlib_unittests") {
466    testonly = true
467
468    sources = [
469      "contrib/tests/infcover.cc",
470      "contrib/tests/infcover.h",
471      "contrib/tests/run_all_unittests.cc",
472      "contrib/tests/utils_unittest.cc",
473      "google/compression_utils_unittest.cc",
474      "google/zip_reader_unittest.cc",
475      "google/zip_unittest.cc",
476    ]
477
478    data = [ "google/test/data/" ]
479
480    deps = [
481      ":zlib",
482      "google:compression_utils",
483      "google:zip",
484      "//base/test:test_support",
485      "//testing/gtest",
486    ]
487
488    include_dirs = [
489      "//third_party/googletest/src/googletest/include/gtest",
490      ".",
491      "google",
492    ]
493  }
494}
495