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