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