From 4304674a002acf1254a161ed42dadcc13e8a4e26 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. PR-URL: https://github.com/nodejs/node/pull/45589 Fixes: https://github.com/nodejs/node/issues/32856 Reviewed-By: Richard Lau Reviewed-By: Yagiz Nizipli --- deps/zlib/GN-scraper.py | 28 +++ deps/zlib/zlib.gyp | 277 ++++++++++++++++++--------- doc/contributing/maintaining-zlib.md | 4 +- 3 files changed, 212 insertions(+), 97 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..c57918cc4613f6 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,173 @@ ['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)' ], + 'direct_dependent_settings': { + 'conditions': [ + ['target_arch in "ia32 x64" and OS!="ios"', { + 'defines': [ 'ADLER32_SIMD_SSSE3' ], + 'conditions': [ + ['OS=="win"', { + 'defines': [ 'X86_WINDOWS' ], + },{ + 'defines': [ 'X86_NOT_WINDOWS' ], + }], + ], + }], + ['arm_fpu=="neon"', { + 'defines': [ 'ADLER32_SIMD_NEON' ], + }], + ], + 'include_dirs': [ '<(ZLIB_ROOT)' ], + }, + 'sources': [ + '