diff options
author | Richard Lau <riclau@uk.ibm.com> | 2020-04-24 13:51:34 -0400 |
---|---|---|
committer | Danielle Adams <adamzdanielle@gmail.com> | 2023-01-04 20:31:51 -0500 |
commit | 72109720c09f76bddfd8e72a49ba62c1ca6c27a8 (patch) | |
tree | 13cb12c59aaa86639479d4244082ee911ee861f5 | |
parent | 97d14f6069e34323cda4dfc32c3a051c5f31384c (diff) | |
download | node-new-72109720c09f76bddfd8e72a49ba62c1ca6c27a8.tar.gz |
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 <rlau@redhat.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
-rw-r--r-- | deps/zlib/GN-scraper.py | 28 | ||||
-rw-r--r-- | deps/zlib/zlib.gyp | 277 | ||||
-rw-r--r-- | doc/contributing/maintaining-zlib.md | 4 |
3 files changed, 212 insertions, 97 deletions
diff --git a/deps/zlib/GN-scraper.py b/deps/zlib/GN-scraper.py new file mode 100644 index 0000000000..f22e19a2a9 --- /dev/null +++ b/deps/zlib/GN-scraper.py @@ -0,0 +1,28 @@ +# Copyright (c) 2019 Refael Ackeramnn<refack@gmail.com>. 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 547143e19d..c57918cc46 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': [ + '<!@pymod_do_main(GN-scraper "<(ZLIB_ROOT)/BUILD.gn" "\\"zlib_adler32_simd\\".*?sources = ")', + ], + }, # zlib_adler32_simd + { + 'target_name': 'zlib_arm_crc32', 'type': 'static_library', + 'conditions': [ + ['OS!="ios"', { + 'conditions': [ + ['OS!="win" and llvm_version=="0.0"', { + 'cflags': [ '-march=armv8-a+aes+crc' ], + }], + ['OS=="android"', { + 'defines': [ 'ARMV8_OS_ANDROID' ], + }], + ['OS=="linux"', { + 'defines': [ 'ARMV8_OS_LINUX' ], + }], + ['OS=="mac"', { + 'defines': [ 'ARMV8_OS_MACOS' ], + }], + ['OS=="win"', { + 'defines': [ 'ARMV8_OS_WINDOWS' ], + }], + ], + 'defines': [ 'CRC32_ARMV8_CRC32' ], + 'include_dirs': [ '<(ZLIB_ROOT)' ], + 'direct_dependent_settings': { + 'defines': [ 'CRC32_ARMV8_CRC32' ], + 'conditions': [ + ['OS=="android"', { + 'defines': [ 'ARMV8_OS_ANDROID' ], + }], + ['OS=="linux"', { + 'defines': [ 'ARMV8_OS_LINUX' ], + }], + ['OS=="mac"', { + 'defines': [ 'ARMV8_OS_MACOS' ], + }], + ['OS=="win"', { + 'defines': [ 'ARMV8_OS_WINDOWS' ], + }], + ], + 'include_dirs': [ '<(ZLIB_ROOT)' ], + }, + 'sources': [ + '<!@pymod_do_main(GN-scraper "<(ZLIB_ROOT)/BUILD.gn" "\\"zlib_arm_crc32\\".*?sources = ")', + ], + }], + ], + }, # zlib_arm_crc32 + { + 'target_name': 'zlib_crc32_simd', + 'type': 'static_library', + 'conditions': [ + ['OS!="win" or llvm_version!="0.0"', { + 'cflags': [ + '-msse4.2', + '-mpclmul', + ], + 'xcode_settings': { + 'OTHER_CFLAGS': [ + '-msse4.2', + '-mpclmul', + ], + }, + }] + ], + 'defines': [ 'CRC32_SIMD_SSE42_PCLMUL' ], + 'include_dirs': [ '<(ZLIB_ROOT)' ], + 'direct_dependent_settings': { + 'defines': [ 'CRC32_SIMD_SSE42_PCLMUL' ], + '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', + '<!@pymod_do_main(GN-scraper "<(ZLIB_ROOT)/BUILD.gn" "\\"zlib_crc32_simd\\".*?sources = ")', ], - 'include_dirs': [ - '.', + }, # zlib_crc32_simd + { + 'target_name': 'zlib_inflate_chunk_simd', + 'type': 'static_library', + 'conditions': [ + ['target_arch in "ia32 x64" and OS!="ios"', { + 'defines': [ 'INFLATE_CHUNK_SIMD_SSE2' ], + 'conditions': [ + ['target_arch=="x64"', { + 'defines': [ 'INFLATE_CHUNK_READ_64LE' ], + }], + ], + }], + ['arm_fpu=="neon"', { + 'defines': [ 'INFLATE_CHUNK_SIMD_NEON' ], + 'conditions': [ + ['target_arch=="arm64"', { + 'defines': [ 'INFLATE_CHUNK_READ_64LE' ], + }], + ], + }], ], + 'include_dirs': [ '<(ZLIB_ROOT)' ], 'direct_dependent_settings': { - 'include_dirs': [ - '.', + 'conditions': [ + ['target_arch in "ia32 x64" and OS!="ios"', { + 'defines': [ 'INFLATE_CHUNK_SIMD_SSE2' ], + }], + ['arm_fpu=="neon"', { + 'defines': [ 'INFLATE_CHUNK_SIMD_NEON' ], + }], ], + 'include_dirs': [ '<(ZLIB_ROOT)' ], + }, + 'sources': [ + '<!@pymod_do_main(GN-scraper "<(ZLIB_ROOT)/BUILD.gn" "\\"zlib_inflate_chunk_simd\\".*?sources = ")', + ], + }, # zlib_inflate_chunk_simd + { + 'target_name': 'zlib', + 'type': 'static_library', + 'sources': [ + '<!@pymod_do_main(GN-scraper "<(ZLIB_ROOT)/BUILD.gn" "\\"zlib\\".*?sources = ")', + ], + 'include_dirs': [ '<(ZLIB_ROOT)' ], + 'direct_dependent_settings': { + 'include_dirs': [ '<(ZLIB_ROOT)' ], }, 'conditions': [ ['OS!="win"', { @@ -58,7 +187,7 @@ 'cflags': [ '-Wno-implicit-fallthrough' ], 'defines': [ 'HAVE_HIDDEN' ], }], - ['OS=="mac" or OS=="freebsd" or OS=="android"', { + ['OS=="mac" or OS=="ios" or OS=="freebsd" or OS=="android"', { # Mac, Android and the BSDs don't have fopen64, ftello64, or # fseeko64. We use fopen, ftell, and fseek instead on these # systems. @@ -66,85 +195,43 @@ 'USE_FILE32API' ], }], + # Incorporate optimizations where possible. ['(target_arch in "ia32 x64" and OS!="ios") or arm_fpu=="neon"', { - 'sources': [ - 'contrib/optimizations/chunkcopy.h', - 'contrib/optimizations/inffast_chunk.c', - 'contrib/optimizations/inffast_chunk.h', - 'contrib/optimizations/inflate.c', - 'slide_hash_simd.h' - ], + 'dependencies': [ 'zlib_inflate_chunk_simd' ], + 'sources': [ '<(ZLIB_ROOT)/slide_hash_simd.h' ] }, { - 'sources': [ 'inflate.c', ], + 'defines': [ 'CPU_NO_SIMD' ], + 'sources': [ '<(ZLIB_ROOT)/inflate.c' ], }], - # Incorporate optimizations where possible ['target_arch in "ia32 x64" and OS!="ios"', { - 'defines': [ - 'ADLER32_SIMD_SSSE3', - 'INFLATE_CHUNK_SIMD_SSE2', - 'CRC32_SIMD_SSE42_PCLMUL', - 'DEFLATE_SLIDE_HASH_SSE2' - ], - 'sources': [ - 'adler32_simd.c', - 'adler32_simd.h', - 'crc32_simd.c', - 'crc32_simd.h', - 'crc_folding.c' + 'dependencies': [ + 'zlib_adler32_simd', + 'zlib_crc32_simd', ], + 'defines': [ 'DEFLATE_SLIDE_HASH_SSE2' ], 'conditions': [ ['target_arch=="x64"', { 'defines': [ 'INFLATE_CHUNK_READ_64LE' ], }], - ['OS=="win"', { - 'defines': [ 'X86_WINDOWS' ] - }, { - 'defines': [ 'X86_NOT_WINDOWS' ] - }] ], }], ['arm_fpu=="neon"', { - 'defines': [ '__ARM_NEON__' ], + 'defines': [ + '__ARM_NEON__', + 'DEFLATE_SLIDE_HASH_NEON', + ], 'conditions': [ ['OS=="win"', { - 'defines': [ - 'ARMV8_OS_WINDOWS', - 'DEFLATE_SLIDE_HASH_NEON', - 'INFLATE_CHUNK_SIMD_NEON' - ] + 'defines': [ 'ARMV8_OS_WINDOWS' ], }, { 'conditions': [ ['OS!="ios"', { - 'defines': [ - 'ADLER32_SIMD_NEON', - 'CRC32_ARMV8_CRC32', - 'DEFLATE_SLIDE_HASH_NEON', - 'INFLATE_CHUNK_SIMD_NEON' - ], - 'sources': [ - 'adler32_simd.c', - 'adler32_simd.h', - 'crc32_simd.c', - 'crc32_simd.h', - ], - 'conditions': [ - ['OS=="android"', { - 'defines': [ 'ARMV8_OS_ANDROID' ], - }], - ['OS=="linux"', { - 'defines': [ 'ARMV8_OS_LINUX' ], - }], - ['OS=="mac"', { - 'defines': [ 'ARMV8_OS_MACOS' ], - }], - ['llvm_version=="0.0"', { - 'cflags': [ - '-march=armv8-a+aes+crc', - ], - }], + 'dependencies': [ + 'zlib_adler32_simd', + 'zlib_arm_crc32', ], - }] - ] + }], + ], }], ['target_arch=="arm64"', { 'defines': [ 'INFLATE_CHUNK_READ_64LE' ], diff --git a/doc/contributing/maintaining-zlib.md b/doc/contributing/maintaining-zlib.md index caed2534c6..75c2b54c04 100644 --- a/doc/contributing/maintaining-zlib.md +++ b/doc/contributing/maintaining-zlib.md @@ -9,10 +9,10 @@ Update zlib: ```bash git clone https://chromium.googlesource.com/chromium/src/third_party/zlib -cp deps/zlib/zlib.gyp deps/zlib/win32/zlib.def deps +cp deps/zlib/zlib.gyp deps/zlib/GN-scraper.py deps/zlib/win32/zlib.def deps rm -rf deps/zlib zlib/.git mv zlib deps/ -mv deps/zlib.gyp deps/zlib/ +mv deps/zlib.gyp deps/GN-scraper.py deps/zlib/ mkdir deps/zlib/win32 mv deps/zlib.def deps/zlib/win32 sed -i -- 's_^#include "chromeconf.h"_//#include "chromeconf.h"_' deps/zlib/zconf.h |