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