BUILD.gn 12 KB

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