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