Skip to content

Commit 09bc89d

Browse files
richardlautargos
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. PR-URL: #45589 Fixes: #32856 Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 1d823a6 commit 09bc89d

File tree

3 files changed

+212
-97
lines changed

3 files changed

+212
-97
lines changed

deps/zlib/GN-scraper.py

Lines changed: 28 additions & 0 deletions
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

Lines changed: 182 additions & 95 deletions
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,139 +13,225 @@
1213
['use_system_zlib==0', {
1314
'targets': [
1415
{
15-
'target_name': 'zlib',
16+
'target_name': 'zlib_adler32_simd',
17+
'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+
'direct_dependent_settings': {
41+
'conditions': [
42+
['target_arch in "ia32 x64" and OS!="ios"', {
43+
'defines': [ 'ADLER32_SIMD_SSSE3' ],
44+
'conditions': [
45+
['OS=="win"', {
46+
'defines': [ 'X86_WINDOWS' ],
47+
},{
48+
'defines': [ 'X86_NOT_WINDOWS' ],
49+
}],
50+
],
51+
}],
52+
['arm_fpu=="neon"', {
53+
'defines': [ 'ADLER32_SIMD_NEON' ],
54+
}],
55+
],
56+
'include_dirs': [ '<(ZLIB_ROOT)' ],
57+
},
58+
'sources': [
59+
'<!@pymod_do_main(GN-scraper "<(ZLIB_ROOT)/BUILD.gn" "\\"zlib_adler32_simd\\".*?sources = ")',
60+
],
61+
}, # zlib_adler32_simd
62+
{
63+
'target_name': 'zlib_arm_crc32',
1664
'type': 'static_library',
65+
'conditions': [
66+
['OS!="ios"', {
67+
'conditions': [
68+
['OS!="win" and llvm_version=="0.0"', {
69+
'cflags': [ '-march=armv8-a+aes+crc' ],
70+
}],
71+
['OS=="android"', {
72+
'defines': [ 'ARMV8_OS_ANDROID' ],
73+
}],
74+
['OS=="linux"', {
75+
'defines': [ 'ARMV8_OS_LINUX' ],
76+
}],
77+
['OS=="mac"', {
78+
'defines': [ 'ARMV8_OS_MACOS' ],
79+
}],
80+
['OS=="win"', {
81+
'defines': [ 'ARMV8_OS_WINDOWS' ],
82+
}],
83+
],
84+
'defines': [ 'CRC32_ARMV8_CRC32' ],
85+
'include_dirs': [ '<(ZLIB_ROOT)' ],
86+
'direct_dependent_settings': {
87+
'defines': [ 'CRC32_ARMV8_CRC32' ],
88+
'conditions': [
89+
['OS=="android"', {
90+
'defines': [ 'ARMV8_OS_ANDROID' ],
91+
}],
92+
['OS=="linux"', {
93+
'defines': [ 'ARMV8_OS_LINUX' ],
94+
}],
95+
['OS=="mac"', {
96+
'defines': [ 'ARMV8_OS_MACOS' ],
97+
}],
98+
['OS=="win"', {
99+
'defines': [ 'ARMV8_OS_WINDOWS' ],
100+
}],
101+
],
102+
'include_dirs': [ '<(ZLIB_ROOT)' ],
103+
},
104+
'sources': [
105+
'<!@pymod_do_main(GN-scraper "<(ZLIB_ROOT)/BUILD.gn" "\\"zlib_arm_crc32\\".*?sources = ")',
106+
],
107+
}],
108+
],
109+
}, # zlib_arm_crc32
110+
{
111+
'target_name': 'zlib_crc32_simd',
112+
'type': 'static_library',
113+
'conditions': [
114+
['OS!="win" or llvm_version!="0.0"', {
115+
'cflags': [
116+
'-msse4.2',
117+
'-mpclmul',
118+
],
119+
'xcode_settings': {
120+
'OTHER_CFLAGS': [
121+
'-msse4.2',
122+
'-mpclmul',
123+
],
124+
},
125+
}]
126+
],
127+
'defines': [ 'CRC32_SIMD_SSE42_PCLMUL' ],
128+
'include_dirs': [ '<(ZLIB_ROOT)' ],
129+
'direct_dependent_settings': {
130+
'defines': [ 'CRC32_SIMD_SSE42_PCLMUL' ],
131+
'include_dirs': [ '<(ZLIB_ROOT)' ],
132+
},
17133
'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',
134+
'<!@pymod_do_main(GN-scraper "<(ZLIB_ROOT)/BUILD.gn" "\\"zlib_crc32_simd\\".*?sources = ")',
46135
],
47-
'include_dirs': [
48-
'.',
136+
}, # zlib_crc32_simd
137+
{
138+
'target_name': 'zlib_inflate_chunk_simd',
139+
'type': 'static_library',
140+
'conditions': [
141+
['target_arch in "ia32 x64" and OS!="ios"', {
142+
'defines': [ 'INFLATE_CHUNK_SIMD_SSE2' ],
143+
'conditions': [
144+
['target_arch=="x64"', {
145+
'defines': [ 'INFLATE_CHUNK_READ_64LE' ],
146+
}],
147+
],
148+
}],
149+
['arm_fpu=="neon"', {
150+
'defines': [ 'INFLATE_CHUNK_SIMD_NEON' ],
151+
'conditions': [
152+
['target_arch=="arm64"', {
153+
'defines': [ 'INFLATE_CHUNK_READ_64LE' ],
154+
}],
155+
],
156+
}],
49157
],
158+
'include_dirs': [ '<(ZLIB_ROOT)' ],
50159
'direct_dependent_settings': {
51-
'include_dirs': [
52-
'.',
160+
'conditions': [
161+
['target_arch in "ia32 x64" and OS!="ios"', {
162+
'defines': [ 'INFLATE_CHUNK_SIMD_SSE2' ],
163+
}],
164+
['arm_fpu=="neon"', {
165+
'defines': [ 'INFLATE_CHUNK_SIMD_NEON' ],
166+
}],
53167
],
168+
'include_dirs': [ '<(ZLIB_ROOT)' ],
169+
},
170+
'sources': [
171+
'<!@pymod_do_main(GN-scraper "<(ZLIB_ROOT)/BUILD.gn" "\\"zlib_inflate_chunk_simd\\".*?sources = ")',
172+
],
173+
}, # zlib_inflate_chunk_simd
174+
{
175+
'target_name': 'zlib',
176+
'type': 'static_library',
177+
'sources': [
178+
'<!@pymod_do_main(GN-scraper "<(ZLIB_ROOT)/BUILD.gn" "\\"zlib\\".*?sources = ")',
179+
],
180+
'include_dirs': [ '<(ZLIB_ROOT)' ],
181+
'direct_dependent_settings': {
182+
'include_dirs': [ '<(ZLIB_ROOT)' ],
54183
},
55184
'conditions': [
56185
['OS!="win"', {
57186
'cflags!': [ '-ansi' ],
58187
'cflags': [ '-Wno-implicit-fallthrough' ],
59188
'defines': [ 'HAVE_HIDDEN' ],
60189
}],
61-
['OS=="mac" or OS=="freebsd" or OS=="android"', {
190+
['OS=="mac" or OS=="ios" or OS=="freebsd" or OS=="android"', {
62191
# Mac, Android and the BSDs don't have fopen64, ftello64, or
63192
# fseeko64. We use fopen, ftell, and fseek instead on these
64193
# systems.
65194
'defines': [
66195
'USE_FILE32API'
67196
],
68197
}],
198+
# Incorporate optimizations where possible.
69199
['(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-
],
200+
'dependencies': [ 'zlib_inflate_chunk_simd' ],
201+
'sources': [ '<(ZLIB_ROOT)/slide_hash_simd.h' ]
77202
}, {
78-
'sources': [ 'inflate.c', ],
203+
'defines': [ 'CPU_NO_SIMD' ],
204+
'sources': [ '<(ZLIB_ROOT)/inflate.c' ],
79205
}],
80-
# Incorporate optimizations where possible
81206
['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'
207+
'dependencies': [
208+
'zlib_adler32_simd',
209+
'zlib_crc32_simd',
94210
],
211+
'defines': [ 'DEFLATE_SLIDE_HASH_SSE2' ],
95212
'conditions': [
96213
['target_arch=="x64"', {
97214
'defines': [ 'INFLATE_CHUNK_READ_64LE' ],
98215
}],
99-
['OS=="win"', {
100-
'defines': [ 'X86_WINDOWS' ]
101-
}, {
102-
'defines': [ 'X86_NOT_WINDOWS' ]
103-
}]
104216
],
105217
}],
106218
['arm_fpu=="neon"', {
107-
'defines': [ '__ARM_NEON__' ],
219+
'defines': [
220+
'__ARM_NEON__',
221+
'DEFLATE_SLIDE_HASH_NEON',
222+
],
108223
'conditions': [
109224
['OS=="win"', {
110-
'defines': [
111-
'ARMV8_OS_WINDOWS',
112-
'DEFLATE_SLIDE_HASH_NEON',
113-
'INFLATE_CHUNK_SIMD_NEON'
114-
]
225+
'defines': [ 'ARMV8_OS_WINDOWS' ],
115226
}, {
116227
'conditions': [
117228
['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-
}],
229+
'dependencies': [
230+
'zlib_adler32_simd',
231+
'zlib_arm_crc32',
145232
],
146-
}]
147-
]
233+
}],
234+
],
148235
}],
149236
['target_arch=="arm64"', {
150237
'defines': [ 'INFLATE_CHUNK_READ_64LE' ],

doc/contributing/maintaining-zlib.md

Lines changed: 2 additions & 2 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy