From cddb80dd5ba6fcda38feaaae2a91537f16047737 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Fri, 24 Apr 2020 13:51:34 -0400 Subject: [PATCH] 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. --- deps/zlib/GN-scraper.py | 28 +++ deps/zlib/zlib.gyp | 253 ++++++++++++++++----------- doc/contributing/maintaining-zlib.md | 4 +- 3 files changed, 185 insertions(+), 100 deletions(-) create mode 100644 deps/zlib/GN-scraper.py diff --git a/deps/zlib/GN-scraper.py b/deps/zlib/GN-scraper.py new file mode 100644 index 00000000000000..f22e19a2a96cee --- /dev/null +++ b/deps/zlib/GN-scraper.py @@ -0,0 +1,28 @@ +# Copyright (c) 2019 Refael Ackeramnn. All rights reserved. +# Use of this source code is governed by an MIT-style license. +import re +import os +import sys + +PLAIN_SOURCE_RE = re.compile('\s*"([^/$].+)"\s*') +def DoMain(args): + gn_filename, pattern = args + src_root = os.path.dirname(gn_filename) + with open(gn_filename, 'rb') as gn_file: + gn_content = gn_file.read().decode('utf-8') + + scraper_re = re.compile(pattern + r'\[([^\]]+)', re.DOTALL) + matches = scraper_re.search(gn_content) + match = matches.group(1) + files = [] + for l in match.splitlines(): + m2 = PLAIN_SOURCE_RE.match(l) + if not m2: + continue + files.append(m2.group(1)) + # always use `/` since GYP will process paths further downstream + rel_files = ['"%s/%s"' % (src_root, f) for f in files] + return ' '.join(rel_files) + +if __name__ == '__main__': + print(DoMain(sys.argv[1:])) diff --git a/deps/zlib/zlib.gyp b/deps/zlib/zlib.gyp index 547143e19dca45..b335d6641094dd 100644 --- a/deps/zlib/zlib.gyp +++ b/deps/zlib/zlib.gyp @@ -4,6 +4,7 @@ { 'variables': { + 'ZLIB_ROOT': '.', 'use_system_zlib%': 0, 'arm_fpu%': '', 'llvm_version%': '0.0', @@ -12,45 +13,140 @@ ['use_system_zlib==0', { 'targets': [ { - 'target_name': 'zlib', + 'target_name': 'zlib_adler32_simd', 'type': 'static_library', + 'conditions': [ + ['target_arch in "ia32 x64" and OS!="ios"', { + 'defines': [ 'ADLER32_SIMD_SSSE3' ], + 'conditions': [ + ['OS=="win"', { + 'defines': [ 'X86_WINDOWS' ], + },{ + 'defines': [ 'X86_NOT_WINDOWS' ], + }], + ['OS!="win" or llvm_version!="0.0"', { + 'cflags': [ '-mssse3' ], + 'xcode_settings': { + 'OTHER_CFLAGS': [ '-mssse3' ], + }, + }], + ], + }], + ['arm_fpu=="neon"', { + 'defines': [ 'ADLER32_SIMD_NEON' ], + }], + ], + 'include_dirs': [ '<(ZLIB_ROOT)' ], + 'defines': [ 'ZLIB_IMPLEMENTATION' ], + 'direct_dependent_settings': { + 'include_dirs': [ '<(ZLIB_ROOT)' ], + }, 'sources': [ - 'adler32.c', - 'compress.c', - 'contrib/optimizations/insert_string.h', - 'cpu_features.c', - 'cpu_features.h', - 'crc32.c', - 'crc32.h', - 'deflate.c', - 'deflate.h', - 'gzclose.c', - 'gzguts.h', - 'gzlib.c', - 'gzread.c', - 'gzwrite.c', - 'infback.c', - 'inffast.c', - 'inffast.h', - 'inffixed.h', - 'inflate.h', - 'inftrees.c', - 'inftrees.h', - 'trees.c', - 'trees.h', - 'uncompr.c', - 'zconf.h', - 'zlib.h', - 'zutil.c', - 'zutil.h', + '