4
4
5
5
import (" //build/config/compiler/compiler.gni" )
6
6
7
+ if (build_with_chromium ) {
8
+ import (" //testing/test.gni" )
9
+ }
10
+
7
11
if (current_cpu == " arm" || current_cpu == " arm64" ) {
8
12
import (" //build/config/arm.gni" )
9
13
}
@@ -14,10 +18,36 @@ config("zlib_config") {
14
18
15
19
config (" zlib_internal_config" ) {
16
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
+
32
+ source_set (" zlib_common_headers" ) {
33
+ sources = [
34
+ " chromeconf.h" ,
35
+ " deflate.h" ,
36
+ " inffast.h" ,
37
+ " inffixed.h" ,
38
+ " inflate.h" ,
39
+ " inftrees.h" ,
40
+ " zconf.h" ,
41
+ " zlib.h" ,
42
+ " zutil.h" ,
43
+ ]
17
44
}
18
45
19
46
use_arm_neon_optimizations = false
20
- if (current_cpu == " arm" || current_cpu == " arm64" ) {
47
+ if ((current_cpu == " arm" || current_cpu == " arm64" ) &&
48
+ ! (is_win && ! is_clang )) {
49
+ # TODO(richard.townsend@arm.com): Optimizations temporarily disabled for
50
+ # Windows on Arm MSVC builds, see http://crbug.com/v8/10012.
21
51
if (arm_use_neon ) {
22
52
use_arm_neon_optimizations = true
23
53
}
@@ -29,6 +59,11 @@ use_x86_x64_optimizations =
29
59
config (" zlib_adler32_simd_config" ) {
30
60
if (use_x86_x64_optimizations ) {
31
61
defines = [ " ADLER32_SIMD_SSSE3" ]
62
+ if (is_win ) {
63
+ defines += [ " X86_WINDOWS" ]
64
+ } else {
65
+ defines += [ " X86_NOT_WINDOWS" ]
66
+ }
32
67
}
33
68
34
69
if (use_arm_neon_optimizations ) {
@@ -55,16 +90,13 @@ source_set("zlib_adler32_simd") {
55
90
" adler32_simd.c" ,
56
91
" adler32_simd.h" ,
57
92
]
58
- if (! is_debug ) {
59
- # Use optimize_speed (-O3) to output the _smallest_ code.
60
- configs -= [ " //build/config/compiler:default_optimization" ]
61
- configs += [ " //build/config/compiler:optimize_speed" ]
62
- }
63
93
}
64
94
65
95
configs += [ " :zlib_internal_config" ]
66
96
67
97
public_configs = [ " :zlib_adler32_simd_config" ]
98
+
99
+ public_deps = [ " :zlib_common_headers" ]
68
100
}
69
101
70
102
if (use_arm_neon_optimizations ) {
@@ -78,6 +110,8 @@ if (use_arm_neon_optimizations) {
78
110
defines += [ " ARMV8_OS_ANDROID" ]
79
111
} else if (is_linux || is_chromeos ) {
80
112
defines += [ " ARMV8_OS_LINUX" ]
113
+ } else if (is_mac ) {
114
+ defines += [ " ARMV8_OS_MACOS" ]
81
115
} else if (is_fuchsia ) {
82
116
defines += [ " ARMV8_OS_FUCHSIA" ]
83
117
} else if (is_win ) {
@@ -94,37 +128,23 @@ if (use_arm_neon_optimizations) {
94
128
if (! is_ios ) {
95
129
include_dirs = [ " ." ]
96
130
97
- if (is_android ) {
98
- import (" //build/config/android/config.gni" )
99
- if (defined (android_ndk_root ) && android_ndk_root != " " ) {
100
- deps = [
101
- " //third_party/android_ndk:cpu_features" ,
102
- ]
103
- } else {
104
- assert (false , " CPU detection requires the Android NDK" )
105
- }
106
- } else if (! is_win && ! is_clang ) {
131
+ if (! is_win && ! is_clang ) {
107
132
assert (! use_thin_lto ,
108
133
" ThinLTO fails mixing different module-level targets" )
109
134
cflags_c = [ " -march=armv8-a+crc" ]
110
135
}
111
136
112
137
sources = [
113
- " arm_features.c" ,
114
- " arm_features.h" ,
115
138
" crc32_simd.c" ,
116
139
" crc32_simd.h" ,
117
140
]
118
-
119
- if (! is_debug ) {
120
- configs -= [ " //build/config/compiler:default_optimization" ]
121
- configs += [ " //build/config/compiler:optimize_speed" ]
122
- }
123
141
}
124
142
125
143
configs += [ " :zlib_internal_config" ]
126
144
127
145
public_configs = [ " :zlib_arm_crc32_config" ]
146
+
147
+ public_deps = [ " :zlib_common_headers" ]
128
148
}
129
149
}
130
150
@@ -139,6 +159,7 @@ config("zlib_inflate_chunk_simd_config") {
139
159
140
160
if (use_arm_neon_optimizations ) {
141
161
defines = [ " INFLATE_CHUNK_SIMD_NEON" ]
162
+
142
163
if (current_cpu == " arm64" ) {
143
164
defines += [ " INFLATE_CHUNK_READ_64LE" ]
144
165
}
@@ -157,22 +178,18 @@ source_set("zlib_inflate_chunk_simd") {
157
178
" contrib/optimizations/inffast_chunk.h" ,
158
179
" contrib/optimizations/inflate.c" ,
159
180
]
160
-
161
- if (use_arm_neon_optimizations && ! is_debug ) {
162
- # Here we trade better performance on newer/bigger ARMv8 cores
163
- # for less perf on ARMv7, per crbug.com/772870#c40
164
- configs -= [ " //build/config/compiler:default_optimization" ]
165
- configs += [ " //build/config/compiler:optimize_speed" ]
166
- }
167
181
}
168
182
183
+ configs += [ " :zlib_internal_config" ]
184
+
185
+ # Needed for MSVC, which is still supported by V8 and PDFium. zlib uses K&R C
186
+ # style function declarations, which triggers warning C4131.
169
187
configs -= [ " //build/config/compiler:chromium_code" ]
170
- configs += [
171
- " :zlib_internal_config" ,
172
- " //build/config/compiler:no_chromium_code" ,
173
- ]
188
+ configs += [ " //build/config/compiler:no_chromium_code" ]
174
189
175
190
public_configs = [ " :zlib_inflate_chunk_simd_config" ]
191
+
192
+ public_deps = [ " :zlib_common_headers" ]
176
193
}
177
194
178
195
config (" zlib_crc32_simd_config" ) {
@@ -201,6 +218,16 @@ source_set("zlib_crc32_simd") {
201
218
configs += [ " :zlib_internal_config" ]
202
219
203
220
public_configs = [ " :zlib_crc32_simd_config" ]
221
+ public_deps = [ " :zlib_common_headers" ]
222
+ }
223
+
224
+ config (" zlib_x86_simd_config" ) {
225
+ if (use_x86_x64_optimizations ) {
226
+ defines = [
227
+ " CRC32_SIMD_SSE42_PCLMUL" ,
228
+ " DEFLATE_FILL_WINDOW_SSE2" ,
229
+ ]
230
+ }
204
231
}
205
232
206
233
source_set (" zlib_x86_simd" ) {
@@ -218,17 +245,13 @@ source_set("zlib_x86_simd") {
218
245
" -mpclmul" ,
219
246
]
220
247
}
221
- } else {
222
- sources = [
223
- " simd_stub.c" ,
224
- ]
225
248
}
226
249
227
- configs - = [ " //build/config/compiler:chromium_code " ]
228
- configs += [
229
- " :zlib_internal_config " ,
230
- " //build/config/compiler:no_chromium_code " ,
231
- ]
250
+ configs + = [ " :zlib_internal_config " ]
251
+
252
+ public_configs = [ " :zlib_x86_simd_config " ]
253
+
254
+ public_deps = [ " :zlib_common_headers " ]
232
255
}
233
256
234
257
config (" zlib_warnings" ) {
@@ -248,6 +271,8 @@ component("zlib") {
248
271
" chromeconf.h" ,
249
272
" compress.c" ,
250
273
" contrib/optimizations/insert_string.h" ,
274
+ " cpu_features.c" ,
275
+ " cpu_features.h" ,
251
276
" crc32.c" ,
252
277
" crc32.h" ,
253
278
" deflate.c" ,
@@ -267,7 +292,6 @@ component("zlib") {
267
292
" trees.c" ,
268
293
" trees.h" ,
269
294
" uncompr.c" ,
270
- " x86.h" ,
271
295
" zconf.h" ,
272
296
" zlib.h" ,
273
297
" zutil.c" ,
@@ -277,14 +301,27 @@ component("zlib") {
277
301
defines = []
278
302
deps = []
279
303
304
+ if (! use_x86_x64_optimizations && ! use_arm_neon_optimizations ) {
305
+ # Apparently android_cronet bot builds with NEON disabled and
306
+ # we also should disable optimizations for iOS@x86 (a.k.a. simulator).
307
+ defines += [ " CPU_NO_SIMD" ]
308
+ }
309
+
310
+ if (is_ios ) {
311
+ # iOS@ARM is a special case where we always have NEON but don't check
312
+ # for crypto extensions.
313
+ # TODO(cavalcantii ): verify what is the current state of CPU features
314
+ # shipped on latest iOS devices.
315
+ defines += [ " ARM_OS_IOS" ]
316
+ }
317
+
280
318
if (use_x86_x64_optimizations || use_arm_neon_optimizations ) {
281
319
deps += [
282
320
" :zlib_adler32_simd" ,
283
321
" :zlib_inflate_chunk_simd" ,
284
322
]
285
323
286
324
if (use_x86_x64_optimizations ) {
287
- sources += [ " x86.c" ]
288
325
deps += [ " :zlib_crc32_simd" ]
289
326
} else if (use_arm_neon_optimizations ) {
290
327
sources += [ " contrib/optimizations/slide_hash_neon.h" ]
@@ -294,18 +331,29 @@ component("zlib") {
294
331
sources += [ " inflate.c" ]
295
332
}
296
333
334
+ deps += [ " :zlib_x86_simd" ]
335
+
336
+ if (is_android ) {
337
+ import (" //build/config/android/config.gni" )
338
+ if (defined (android_ndk_root ) && android_ndk_root != " " ) {
339
+ deps += [ " //third_party/android_ndk:cpu_features" ]
340
+ } else {
341
+ assert (false , " CPU detection requires the Android NDK" )
342
+ }
343
+ }
344
+
297
345
configs -= [ " //build/config/compiler:chromium_code" ]
346
+ configs += [ " //build/config/compiler:no_chromium_code" ]
347
+
348
+ public_configs = [ " :zlib_config" ]
349
+
298
350
configs += [
299
351
" :zlib_internal_config" ,
300
- " //build/config/compiler:no_chromium_code" ,
301
352
302
353
# Must be after no_chromium_code for warning flags to be ordered correctly.
303
354
" :zlib_warnings" ,
304
355
]
305
356
306
- public_configs = [ " :zlib_config" ]
307
-
308
- deps += [ " :zlib_x86_simd" ]
309
357
allow_circular_includes_from = deps
310
358
}
311
359
@@ -337,43 +385,63 @@ static_library("minizip") {
337
385
]
338
386
}
339
387
340
- if (is_mac || is_ios || is_android || is_nacl ) {
388
+ if (is_apple || is_android || is_nacl ) {
341
389
# Mac, Android and the BSDs don't have fopen64, ftello64, or fseeko64. We
342
390
# use fopen, ftell, and fseek instead on these systems.
343
391
defines = [ " USE_FILE32API" ]
344
392
}
345
393
346
- deps = [
347
- " :zlib" ,
348
- ]
394
+ deps = [ " :zlib" ]
349
395
350
396
configs -= [ " //build/config/compiler:chromium_code" ]
351
- configs += [
352
- " //build/config/compiler:no_chromium_code" ,
397
+ configs += [ " //build/config/compiler:no_chromium_code" ]
353
398
399
+ public_configs = [ " :zlib_config" ]
400
+
401
+ configs += [
354
402
# Must be after no_chromium_code for warning flags to be ordered correctly.
355
403
" :minizip_warnings" ,
356
404
]
357
-
358
- public_configs = [ " :zlib_config" ]
359
405
}
360
406
361
407
executable (" zlib_bench" ) {
362
408
include_dirs = [ " ." ]
363
409
364
- sources = [
365
- " contrib/bench/zlib_bench.cc" ,
366
- ]
367
-
410
+ sources = [ " contrib/bench/zlib_bench.cc" ]
368
411
if (! is_debug ) {
369
412
configs -= [ " //build/config/compiler:default_optimization" ]
370
413
configs += [ " //build/config/compiler:optimize_speed" ]
371
414
}
372
415
416
+ deps = [ " :zlib" ]
417
+
373
418
configs -= [ " //build/config/compiler:chromium_code" ]
374
419
configs += [ " //build/config/compiler:no_chromium_code" ]
420
+ }
375
421
376
- deps = [
377
- " :zlib" ,
378
- ]
422
+ if (build_with_chromium ) {
423
+ test (" zlib_unittests" ) {
424
+ testonly = true
425
+
426
+ sources = [
427
+ " contrib/tests/infcover.cc" ,
428
+ " contrib/tests/infcover.h" ,
429
+ " contrib/tests/run_all_unittests.cc" ,
430
+ " contrib/tests/utils_unittest.cc" ,
431
+ " google/compression_utils_portable.cc" ,
432
+ " google/compression_utils_portable.h" ,
433
+ ]
434
+
435
+ deps = [
436
+ " :zlib" ,
437
+ " //base/test:test_support" ,
438
+ " //testing/gtest" ,
439
+ ]
440
+
441
+ include_dirs = [
442
+ " //third_party/googletest/src/googletest/include/gtest" ,
443
+ " ." ,
444
+ " google" ,
445
+ ]
446
+ }
379
447
}
0 commit comments