Skip to content

Commit d315a06

Browse files
richardlaulpinca
authored andcommitted
build: rework gyp files for zlib
Restructure the zlib.gyp file based on the upstream gn file, breaking out the files with optimizations that need additional compiler flags. Use a copy of the GN-scraper.py script to reduce the amount of hand editing when the zlib dependency is updated.
1 parent 14b86a5 commit d315a06

File tree

3 files changed

+180
-108
lines changed

3 files changed

+180
-108
lines changed

deps/zlib/GN-scraper.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (c) 2019 Refael Ackeramnn<refack@gmail.com>. All rights reserved.
2+
# Use of this source code is governed by an MIT-style license.
3+
import re
4+
import os
5+
import sys
6+
7+
PLAIN_SOURCE_RE = re.compile('\s*"([^/$].+)"\s*')
8+
def DoMain(args):
9+
gn_filename, pattern = args
10+
src_root = os.path.dirname(gn_filename)
11+
with open(gn_filename, 'rb') as gn_file:
12+
gn_content = gn_file.read().decode('utf-8')
13+
14+
scraper_re = re.compile(pattern + r'\[([^\]]+)', re.DOTALL)
15+
matches = scraper_re.search(gn_content)
16+
match = matches.group(1)
17+
files = []
18+
for l in match.splitlines():
19+
m2 = PLAIN_SOURCE_RE.match(l)
20+
if not m2:
21+
continue
22+
files.append(m2.group(1))
23+
# always use `/` since GYP will process paths further downstream
24+
rel_files = ['"%s/%s"' % (src_root, f) for f in files]
25+
return ' '.join(rel_files)
26+
27+
if __name__ == '__main__':
28+
print(DoMain(sys.argv[1:]))

deps/zlib/zlib.gyp

+150-106
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
{
66
'variables': {
7+
'ZLIB_ROOT': '.',
78
'use_system_zlib%': 0,
89
'arm_fpu%': '',
910
'llvm_version%': '0.0',
@@ -12,146 +13,189 @@
1213
['use_system_zlib==0', {
1314
'targets': [
1415
{
15-
'target_name': 'zlib',
16+
'target_name': 'zlib_adler32_simd',
1617
'type': 'static_library',
18+
'conditions': [
19+
['target_arch in "ia32 x64" and OS!="ios"', {
20+
'defines': [ 'ADLER32_SIMD_SSSE3' ],
21+
'conditions': [
22+
['OS=="win"', {
23+
'defines': [ 'X86_WINDOWS' ],
24+
},{
25+
'defines': [ 'X86_NOT_WINDOWS' ],
26+
}],
27+
['OS!="win" or llvm_version!="0.0"', {
28+
'cflags': [ '-mssse3' ],
29+
'xcode_settings': {
30+
'OTHER_CFLAGS': [ '-mssse3' ],
31+
},
32+
}],
33+
],
34+
}],
35+
['arm_fpu=="neon"', {
36+
'defines': [ 'ADLER32_SIMD_NEON' ],
37+
}],
38+
],
39+
'include_dirs': [ '<(ZLIB_ROOT)' ],
40+
'defines': [ 'ZLIB_IMPLEMENTATION' ],
41+
'direct_dependent_settings': {
42+
'include_dirs': [ '<(ZLIB_ROOT)' ],
43+
},
1744
'sources': [
18-
'adler32.c',
19-
'compress.c',
20-
'contrib/optimizations/insert_string.h',
21-
'cpu_features.c',
22-
'cpu_features.h',
23-
'crc32.c',
24-
'crc32.h',
25-
'deflate.c',
26-
'deflate.h',
27-
'gzclose.c',
28-
'gzguts.h',
29-
'gzlib.c',
30-
'gzread.c',
31-
'gzwrite.c',
32-
'infback.c',
33-
'inffast.c',
34-
'inffast.h',
35-
'inffixed.h',
36-
'inflate.h',
37-
'inftrees.c',
38-
'inftrees.h',
39-
'trees.c',
40-
'trees.h',
41-
'uncompr.c',
42-
'zconf.h',
43-
'zlib.h',
44-
'zutil.c',
45-
'zutil.h',
45+
'<!@pymod_do_main(GN-scraper "<(ZLIB_ROOT)/BUILD.gn" "\\"zlib_adler32_simd\\".*?sources = ")',
46+
],
47+
}, # zlib_adler32_simd
48+
{
49+
'target_name': 'zlib_arm_crc32',
50+
'type': 'static_library',
51+
'conditions': [
52+
['OS!="ios"', {
53+
'conditions': [
54+
['OS!="win" and llvm_version=="0.0"', {
55+
'cflags': [ '-march=armv8-a+aes+crc' ],
56+
}],
57+
['OS=="android"', {
58+
'defines': [ 'ARMV8_OS_ANDROID' ],
59+
}],
60+
['OS=="linux"', {
61+
'defines': [ 'ARMV8_OS_LINUX' ],
62+
}],
63+
['OS=="mac"', {
64+
'defines': [ 'ARMV8_OS_MACOS' ],
65+
}],
66+
['OS=="win"', {
67+
'defines': [ 'ARMV8_OS_WINDOWS' ],
68+
}],
69+
],
70+
'defines': [ 'CRC32_ARMV8_CRC32' ],
71+
'include_dirs': [ '<(ZLIB_ROOT)' ],
72+
'direct_dependent_settings': {
73+
'include_dirs': [ '<(ZLIB_ROOT)' ],
74+
},
75+
'sources': [
76+
'<!@pymod_do_main(GN-scraper "<(ZLIB_ROOT)/BUILD.gn" "\\"zlib_arm_crc32\\".*?sources = ")',
77+
],
78+
}],
79+
],
80+
'defines': [ 'ZLIB_IMPLEMENTATION' ],
81+
}, # zlib_arm_crc32
82+
{
83+
'target_name': 'zlib_crc32_simd',
84+
'type': 'static_library',
85+
'conditions': [
86+
['OS!="win" or llvm_version!="0.0"', {
87+
'cflags': [
88+
'-msse4.2',
89+
'-mpclmul',
90+
],
91+
'xcode_settings': {
92+
'OTHER_CFLAGS': [
93+
'-msse4.2',
94+
'-mpclmul',
95+
],
96+
},
97+
}]
4698
],
47-
'include_dirs': [
48-
'.',
99+
'defines': [
100+
'CRC32_SIMD_SSE42_PCLMUL',
101+
'ZLIB_IMPLEMENTATION',
49102
],
103+
'include_dirs': [ '<(ZLIB_ROOT)' ],
50104
'direct_dependent_settings': {
51-
'include_dirs': [
52-
'.',
53-
],
105+
'include_dirs': [ '<(ZLIB_ROOT)' ],
106+
},
107+
'sources': [
108+
'<!@pymod_do_main(GN-scraper "<(ZLIB_ROOT)/BUILD.gn" "\\"zlib_crc32_simd\\".*?sources = ")',
109+
],
110+
}, # zlib_crc32_simd
111+
{
112+
'target_name': 'zlib_inflate_chunk_simd',
113+
'type': 'static_library',
114+
'conditions': [
115+
['target_arch in "ia32 x64" and OS!="ios"', {
116+
'defines': [ 'INFLATE_CHUNK_SIMD_SSE2' ],
117+
'conditions': [
118+
['target_arch=="x64"', {
119+
'defines': [ 'INFLATE_CHUNK_READ_64LE' ],
120+
}],
121+
],
122+
}],
123+
['arm_fpu=="neon"', {
124+
'defines': [ 'INFLATE_CHUNK_SIMD_NEON' ],
125+
'conditions': [
126+
['target_arch=="arm64"', {
127+
'defines': [ 'INFLATE_CHUNK_READ_64LE' ],
128+
}],
129+
],
130+
}]
131+
],
132+
'include_dirs': [ '<(ZLIB_ROOT)' ],
133+
'defines': [ 'ZLIB_IMPLEMENTATION' ],
134+
'direct_dependent_settings': {
135+
'include_dirs': [ '<(ZLIB_ROOT)' ],
136+
},
137+
'sources': [
138+
'<!@pymod_do_main(GN-scraper "<(ZLIB_ROOT)/BUILD.gn" "\\"zlib_inflate_chunk_simd\\".*?sources = ")',
139+
],
140+
}, # zlib_inflate_chunk_simd
141+
{
142+
'target_name': 'zlib',
143+
'type': 'static_library',
144+
'sources': [
145+
'<!@pymod_do_main(GN-scraper "<(ZLIB_ROOT)/BUILD.gn" "\\"zlib\\".*?sources = ")',
146+
],
147+
'include_dirs': [ '<(ZLIB_ROOT)' ],
148+
'direct_dependent_settings': {
149+
'include_dirs': [ '<(ZLIB_ROOT)' ],
54150
},
55151
'conditions': [
56152
['OS!="win"', {
57153
'cflags!': [ '-ansi' ],
58154
'cflags': [ '-Wno-implicit-fallthrough' ],
59155
'defines': [ 'HAVE_HIDDEN' ],
60156
}],
61-
['OS=="mac" or OS=="freebsd" or OS=="android"', {
157+
['OS=="mac" or OS=="ios" or OS=="freebsd" or OS=="android"', {
62158
# Mac, Android and the BSDs don't have fopen64, ftello64, or
63159
# fseeko64. We use fopen, ftell, and fseek instead on these
64160
# systems.
65161
'defines': [
66162
'USE_FILE32API'
67163
],
68164
}],
165+
# Incorporate optimizations where possible.
69166
['(target_arch in "ia32 x64" and OS!="ios") or arm_fpu=="neon"', {
70-
'sources': [
71-
'contrib/optimizations/chunkcopy.h',
72-
'contrib/optimizations/inffast_chunk.c',
73-
'contrib/optimizations/inffast_chunk.h',
74-
'contrib/optimizations/inflate.c',
75-
'slide_hash_simd.h'
76-
],
167+
'dependencies': [ 'zlib_inflate_chunk_simd' ],
168+
'sources': [ '<(ZLIB_ROOT)/slide_hash_simd.h' ]
77169
}, {
78-
'sources': [ 'inflate.c', ],
170+
'defines': [ 'CPU_NO_SIMD' ],
171+
'sources': [ '<(ZLIB_ROOT)/inflate.c' ],
79172
}],
80-
# Incorporate optimizations where possible
81173
['target_arch in "ia32 x64" and OS!="ios"', {
82-
'defines': [
83-
'ADLER32_SIMD_SSSE3',
84-
'INFLATE_CHUNK_SIMD_SSE2',
85-
'CRC32_SIMD_SSE42_PCLMUL',
86-
'DEFLATE_SLIDE_HASH_SSE2'
87-
],
88-
'sources': [
89-
'adler32_simd.c',
90-
'adler32_simd.h',
91-
'crc32_simd.c',
92-
'crc32_simd.h',
93-
'crc_folding.c'
94-
],
95-
'conditions': [
96-
['target_arch=="x64"', {
97-
'defines': [ 'INFLATE_CHUNK_READ_64LE' ],
98-
}],
99-
['OS=="win"', {
100-
'defines': [ 'X86_WINDOWS' ]
101-
}, {
102-
'defines': [ 'X86_NOT_WINDOWS' ]
103-
}]
174+
'dependencies': [
175+
'zlib_adler32_simd',
176+
'zlib_crc32_simd',
104177
],
178+
'defines': [ 'DEFLATE_SLIDE_HASH_SSE2' ],
105179
}],
106180
['arm_fpu=="neon"', {
107-
'defines': [ '__ARM_NEON__' ],
181+
'defines': [
182+
'__ARM_NEON__',
183+
'DEFLATE_SLIDE_HASH_NEON',
184+
],
108185
'conditions': [
109-
['OS=="win"', {
110-
'defines': [
111-
'ARMV8_OS_WINDOWS',
112-
'DEFLATE_SLIDE_HASH_NEON',
113-
'INFLATE_CHUNK_SIMD_NEON'
114-
]
115-
}, {
116-
'conditions': [
117-
['OS!="ios"', {
118-
'defines': [
119-
'ADLER32_SIMD_NEON',
120-
'CRC32_ARMV8_CRC32',
121-
'DEFLATE_SLIDE_HASH_NEON',
122-
'INFLATE_CHUNK_SIMD_NEON'
123-
],
124-
'sources': [
125-
'adler32_simd.c',
126-
'adler32_simd.h',
127-
'crc32_simd.c',
128-
'crc32_simd.h',
129-
],
130-
'conditions': [
131-
['OS=="android"', {
132-
'defines': [ 'ARMV8_OS_ANDROID' ],
133-
}],
134-
['OS=="linux"', {
135-
'defines': [ 'ARMV8_OS_LINUX' ],
136-
}],
137-
['OS=="mac"', {
138-
'defines': [ 'ARMV8_OS_MACOS' ],
139-
}],
140-
['llvm_version=="0.0"', {
141-
'cflags': [
142-
'-march=armv8-a+aes+crc',
143-
],
144-
}],
145-
],
146-
}]
147-
]
186+
['OS!="ios" and OS!="win"', {
187+
'dependencies': [
188+
'zlib_adler32_simd',
189+
'zlib_arm_crc32',
190+
],
148191
}],
149192
['target_arch=="arm64"', {
150193
'defines': [ 'INFLATE_CHUNK_READ_64LE' ],
151194
}],
152195
],
153196
}],
154197
],
198+
'defines': [ 'ZLIB_IMPLEMENTATION' ],
155199
},
156200
],
157201
}, {

doc/contributing/maintaining-zlib.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ Update zlib:
99

1010
```bash
1111
git clone https://chromium.googlesource.com/chromium/src/third_party/zlib
12-
cp deps/zlib/zlib.gyp deps/zlib/win32/zlib.def deps
12+
cp deps/zlib/zlib.gyp deps/zlib/GN-scraper.py deps/zlib/win32/zlib.def deps
1313
rm -rf deps/zlib zlib/.git
1414
mv zlib deps/
15-
mv deps/zlib.gyp deps/zlib/
15+
mv deps/zlib.gyp deps/GN-scraper.py deps/zlib/
1616
mkdir deps/zlib/win32
1717
mv deps/zlib.def deps/zlib/win32
1818
sed -i -- 's_^#include "chromeconf.h"_//#include "chromeconf.h"_' deps/zlib/zconf.h

0 commit comments

Comments
 (0)