From 8bf2beaea4a94b98a00e9880c05b35c0c73128e7 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Wed, 23 Aug 2017 09:52:59 +0200 Subject: [PATCH 1/7] test: --enable-static linked executable The motivation for this commit is to enable projects embedding Node.js and building with --enable-static to be able to run the test suite and linter. Currently when building with --enable-static no node executable will be created which means that the tests (apart from the cctest) and linter cannot be run. This is currently a work in progress and works on MacOS but I need to run the CI, and manually on different environments to verify that it works as expected. --- common.gypi | 4 +- node.gyp | 61 +++++++++++++++++++++++-- node.gypi | 4 +- test/addons/openssl-binding/binding.gyp | 19 ++++++-- test/addons/zlib-binding/binding.gyp | 13 ++++++ 5 files changed, 88 insertions(+), 13 deletions(-) diff --git a/common.gypi b/common.gypi index ba441781698841..52a4bbcec85374 100644 --- a/common.gypi +++ b/common.gypi @@ -64,9 +64,9 @@ 'V8_BASE': '<(PRODUCT_DIR)/libv8_base.a', }], ['openssl_fips != ""', { - 'OPENSSL_PRODUCT': 'libcrypto.a', + 'OPENSSL_PRODUCT': '<(STATIC_LIB_PREFIX)crypto<(STATIC_LIB_SUFFIX)', }, { - 'OPENSSL_PRODUCT': 'libopenssl.a', + 'OPENSSL_PRODUCT': '<(STATIC_LIB_PREFIX)openssl<(STATIC_LIB_SUFFIX)', }], ['OS=="mac"', { 'clang%': 1, diff --git a/node.gyp b/node.gyp index 63ace809396bd2..3d51c12dfbabe6 100644 --- a/node.gyp +++ b/node.gyp @@ -343,6 +343,13 @@ 'src/backtrace_win32.cc', 'src/res/node.rc', ], + 'conditions': [ + [ 'node_target_type!="static_library"', { + 'sources': [ + 'src/res/node.rc', + ], + }], + ], 'defines!': [ 'NODE_PLATFORM="win"', ], @@ -508,7 +515,7 @@ 'target_name': 'node_etw', 'type': 'none', 'conditions': [ - [ 'node_use_etw=="true"', { + [ 'node_use_etw=="true" and node_target_type!="static_library"', { 'actions': [ { 'action_name': 'node_etw', @@ -529,7 +536,7 @@ 'target_name': 'node_perfctr', 'type': 'none', 'conditions': [ - [ 'node_use_perfctr=="true"', { + [ 'node_use_perfctr=="true" and node_target_type!="static_library"', { 'actions': [ { 'action_name': 'node_perfctr_man', @@ -591,13 +598,15 @@ '<(SHARED_INTERMEDIATE_DIR)/node_javascript.cc', ], 'conditions': [ - [ 'node_use_dtrace=="false" and node_use_etw=="false"', { + [ 'node_use_dtrace=="false" and node_use_etw=="false" or ' + 'node_target_type=="static_library"', { 'inputs': [ 'src/notrace_macros.py' ] }], - ['node_use_lttng=="false"', { + ['node_use_lttng=="false" or node_target_type=="static_library"', { 'inputs': [ 'src/nolttng_macros.py' ] }], - [ 'node_use_perfctr=="false"', { + [ 'node_use_perfctr=="false" or ' + 'node_target_type=="static_library"', { 'inputs': [ 'src/noperfctr_macros.py' ] }] ], @@ -952,6 +961,48 @@ ], # end targets 'conditions': [ + [ 'node_target_type=="static_library"', { + 'targets': [ + { + 'target_name': 'static_node', + 'type': 'executable', + 'product_name': '<(node_core_target_name)', + 'dependencies': [ + '<(node_core_target_name)', + ], + 'sources+': [ + 'src/node_main.cc', + ], + 'include_dirs': [ + 'deps/v8/include', + ], + 'xcode_settings': { + 'OTHER_LDFLAGS': [ + '-Wl,-force_load,<(PRODUCT_DIR)/<(STATIC_LIB_PREFIX)' + '<(node_core_target_name)<(STATIC_LIB_SUFFIX)', + ], + }, + 'msvs_settings': { + 'VCLinkerTool': { + 'AdditionalOptions': [ + '/WHOLEARCHIVE:<(PRODUCT_DIR)/lib/' + '<(node_core_target_name)<(STATIC_LIB_SUFFIX)', + ], + }, + }, + 'conditions': [ + ['OS in "linux freebsd openbsd solaris android aix"', { + 'ldflags': [ + '-Wl,--whole-archive,' + '<(OBJ_DIR)/<(STATIC_LIB_PREFIX)' + '<(node_core_target_name)<(STATIC_LIB_SUFFIX) ', + '-Wl,--no-whole-archive', + ], + }], + ], + }, + ], + }], ['OS=="aix"', { 'targets': [ { diff --git a/node.gypi b/node.gypi index 718ef0c9e7ff01..ec78df2a339203 100644 --- a/node.gypi +++ b/node.gypi @@ -78,7 +78,7 @@ 'src/node_lttng.cc' ], } ], - [ 'node_use_etw=="true"', { + [ 'node_use_etw=="true" and node_target_type!="static_library"', { 'defines': [ 'HAVE_ETW=1' ], 'dependencies': [ 'node_etw' ], 'sources': [ @@ -90,7 +90,7 @@ 'tools/msvs/genfiles/node_etw_provider.rc', ] } ], - [ 'node_use_perfctr=="true"', { + [ 'node_use_perfctr=="true" and node_target_type!="static_library"', { 'defines': [ 'HAVE_PERFCTR=1' ], 'dependencies': [ 'node_perfctr' ], 'sources': [ diff --git a/test/addons/openssl-binding/binding.gyp b/test/addons/openssl-binding/binding.gyp index bafde41348ce3a..425b38caa3f659 100644 --- a/test/addons/openssl-binding/binding.gyp +++ b/test/addons/openssl-binding/binding.gyp @@ -1,12 +1,23 @@ { + 'includes': ['../../../config.gypi'], + 'variables': { + 'node_target_type%': '', + }, 'targets': [ { 'target_name': 'binding', 'conditions': [ - ['node_use_openssl=="true"', { - 'sources': ['binding.cc'], - 'include_dirs': ['../../../deps/openssl/openssl/include'], - }] + ['node_use_openssl=="true"', { + 'sources': ['binding.cc'], + 'include_dirs': ['../../../deps/openssl/openssl/include'], + 'conditions': [ + ['OS=="win" and node_target_type=="static_library"', { + 'libraries': [ + '../../../../$(Configuration)/lib/<(OPENSSL_PRODUCT)' + ], + }], + ], + }] ] }, ] diff --git a/test/addons/zlib-binding/binding.gyp b/test/addons/zlib-binding/binding.gyp index 60a9bb82661820..24c3ae78a2440a 100644 --- a/test/addons/zlib-binding/binding.gyp +++ b/test/addons/zlib-binding/binding.gyp @@ -1,9 +1,22 @@ { + 'includes': ['../../../config.gypi'], + 'variables': { + 'node_target_type%': '', + }, 'targets': [ { 'target_name': 'binding', 'sources': ['binding.cc'], 'include_dirs': ['../../../deps/zlib'], + 'conditions': [ + ['node_target_type=="static_library"', { + 'conditions': [ + ['OS=="win"', { + 'libraries': ['../../../../$(Configuration)/lib/zlib.lib'], + }], + ], + }], + ], }, ] } From 163f0e598076958afe47e9c48a9123216e0a9244 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Mon, 9 Oct 2017 14:50:24 +0200 Subject: [PATCH 2/7] Revert "build: for --enable-static, run only cctest" This reverts commit a36b5405029597ce09e15373a321c47930689c08. --- Makefile | 5 ----- configure | 2 -- vcbuild.bat | 6 ++---- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index b2facee41a8442..e5510b45c254ab 100644 --- a/Makefile +++ b/Makefile @@ -205,10 +205,6 @@ v8: tools/make-v8.sh $(MAKE) -C deps/v8 $(V8_ARCH).$(BUILDTYPE_LOWER) $(V8_BUILD_OPTIONS) -ifeq ($(NODE_TARGET_TYPE),static_library) -test: all - $(MAKE) cctest -else test: all $(MAKE) build-addons $(MAKE) build-addons-napi @@ -221,7 +217,6 @@ test: all $(CI_NATIVE_SUITES) \ $(CI_DOC) \ known_issues -endif # For a quick test, does not run linter or build doc test-only: all diff --git a/configure b/configure index 0c5aed8fcc0456..bbccf05fb47c35 100755 --- a/configure +++ b/configure @@ -1461,8 +1461,6 @@ config = { 'BUILDTYPE': 'Debug' if options.debug else 'Release', 'USE_XCODE': str(int(options.use_xcode or 0)), 'PYTHON': sys.executable, - 'NODE_TARGET_TYPE': variables['node_target_type'] if options.enable_static \ - else '', } if options.prefix: diff --git a/vcbuild.bat b/vcbuild.bat index d2683f99887cc0..a765bcb439b3c5 100644 --- a/vcbuild.bat +++ b/vcbuild.bat @@ -110,7 +110,7 @@ if /i "%1"=="download-all" set download_arg="--download=all"&goto arg-ok if /i "%1"=="ignore-flaky" set test_args=%test_args% --flaky-tests=dontcare&goto arg-ok if /i "%1"=="enable-vtune" set enable_vtune_arg=1&goto arg-ok if /i "%1"=="dll" set dll=1&goto arg-ok -if /i "%1"=="static" set enable_static=1&goto arg-ok +if /i "%1"=="static" set enable_static=1&goto arg-ok if /i "%1"=="no-NODE-OPTIONS" set no_NODE_OPTIONS=1&goto arg-ok if /i "%1"=="debug-http2" set debug_http2=1&goto arg-ok if /i "%1"=="debug-nghttp2" set debug_nghttp2=1&goto arg-ok @@ -465,9 +465,8 @@ if "%config%"=="Debug" set test_args=--mode=debug %test_args% if "%config%"=="Release" set test_args=--mode=release %test_args% echo running 'cctest %cctest_args%' "%config%\cctest" %cctest_args% -REM when building a static library there's no binary to run tests -if defined enable_static goto test-v8 call :run-python tools\test.py %test_args% +goto test-v8 :test-v8 if not defined custom_v8_test goto lint-cpp @@ -520,7 +519,6 @@ set "localcppfilelist=%localcppfilelist% %1" goto exit :lint-js -if defined enable_static goto exit if defined lint_js_ci goto lint-js-ci if not defined lint_js goto exit if not exist tools\eslint goto no-lint From acb0b8bdf32dce626b18b29031575cccd4ae2c52 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 2 Nov 2017 05:54:46 +0100 Subject: [PATCH 3/7] squash: fix intentation in node.gyp --- node.gyp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/node.gyp b/node.gyp index 3d51c12dfbabe6..d70d3ae1b17878 100644 --- a/node.gyp +++ b/node.gyp @@ -979,23 +979,22 @@ 'xcode_settings': { 'OTHER_LDFLAGS': [ '-Wl,-force_load,<(PRODUCT_DIR)/<(STATIC_LIB_PREFIX)' - '<(node_core_target_name)<(STATIC_LIB_SUFFIX)', + '<(node_core_target_name)<(STATIC_LIB_SUFFIX)', ], }, 'msvs_settings': { 'VCLinkerTool': { 'AdditionalOptions': [ '/WHOLEARCHIVE:<(PRODUCT_DIR)/lib/' - '<(node_core_target_name)<(STATIC_LIB_SUFFIX)', + '<(node_core_target_name)<(STATIC_LIB_SUFFIX)', ], }, }, 'conditions': [ ['OS in "linux freebsd openbsd solaris android aix"', { 'ldflags': [ - '-Wl,--whole-archive,' - '<(OBJ_DIR)/<(STATIC_LIB_PREFIX)' - '<(node_core_target_name)<(STATIC_LIB_SUFFIX) ', + '-Wl,--whole-archive,<(OBJ_DIR)/<(STATIC_LIB_PREFIX)' + '<(node_core_target_name)<(STATIC_LIB_SUFFIX) ', '-Wl,--no-whole-archive', ], }], From 469256125a9385f5674f6505c2db7163003100ac Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 2 Nov 2017 05:55:05 +0100 Subject: [PATCH 4/7] squash: remove whitspace and extra goto statement --- vcbuild.bat | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vcbuild.bat b/vcbuild.bat index a765bcb439b3c5..3db9a2a4cea870 100644 --- a/vcbuild.bat +++ b/vcbuild.bat @@ -110,7 +110,7 @@ if /i "%1"=="download-all" set download_arg="--download=all"&goto arg-ok if /i "%1"=="ignore-flaky" set test_args=%test_args% --flaky-tests=dontcare&goto arg-ok if /i "%1"=="enable-vtune" set enable_vtune_arg=1&goto arg-ok if /i "%1"=="dll" set dll=1&goto arg-ok -if /i "%1"=="static" set enable_static=1&goto arg-ok +if /i "%1"=="static" set enable_static=1&goto arg-ok if /i "%1"=="no-NODE-OPTIONS" set no_NODE_OPTIONS=1&goto arg-ok if /i "%1"=="debug-http2" set debug_http2=1&goto arg-ok if /i "%1"=="debug-nghttp2" set debug_nghttp2=1&goto arg-ok @@ -466,7 +466,6 @@ if "%config%"=="Release" set test_args=--mode=release %test_args% echo running 'cctest %cctest_args%' "%config%\cctest" %cctest_args% call :run-python tools\test.py %test_args% -goto test-v8 :test-v8 if not defined custom_v8_test goto lint-cpp From 8f23991fa0dedb4e84cbf42fbe93ccd8465d3a94 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 2 Nov 2017 07:41:57 +0100 Subject: [PATCH 5/7] squash: remove extra whitespace --- node.gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node.gyp b/node.gyp index d70d3ae1b17878..88ff311ebec6f6 100644 --- a/node.gyp +++ b/node.gyp @@ -994,7 +994,7 @@ ['OS in "linux freebsd openbsd solaris android aix"', { 'ldflags': [ '-Wl,--whole-archive,<(OBJ_DIR)/<(STATIC_LIB_PREFIX)' - '<(node_core_target_name)<(STATIC_LIB_SUFFIX) ', + '<(node_core_target_name)<(STATIC_LIB_SUFFIX)', '-Wl,--no-whole-archive', ], }], From 0b632764dbca34de7d922213db1234d20db41a95 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 2 Nov 2017 16:48:26 +0100 Subject: [PATCH 6/7] squash: remove whole-archive for aix This commit excludes aix from using whole-archive which does not seem to be supported. Reading the documentation for ld (https://www.ibm.com/support/knowledgecenter/ssw_aix_61/ com.ibm.aix.cmds3/ld.htm) I found this: "The first definition of a symbol is kept, even if no reference to the symbol has been seen when the archive is read. In other versions of the ld command, a symbol defined in an archive is ignored if no reference to the symbol has been seen when the archive is read." This sounds like it will not ignore a symbol just because it is not used similar to when the whole-archive flag is used. Going to try this and see if it works. --- node.gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node.gyp b/node.gyp index 88ff311ebec6f6..a090818a5ebdd6 100644 --- a/node.gyp +++ b/node.gyp @@ -991,7 +991,7 @@ }, }, 'conditions': [ - ['OS in "linux freebsd openbsd solaris android aix"', { + ['OS in "linux freebsd openbsd solaris android"', { 'ldflags': [ '-Wl,--whole-archive,<(OBJ_DIR)/<(STATIC_LIB_PREFIX)' '<(node_core_target_name)<(STATIC_LIB_SUFFIX)', From 83027c0d55dadfb8ad0bb2817c2463ca1ebb2526 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Mon, 13 Nov 2017 05:51:04 -0800 Subject: [PATCH 7/7] squash: remove node.res if build is static --- node.gyp | 1 - 1 file changed, 1 deletion(-) diff --git a/node.gyp b/node.gyp index a090818a5ebdd6..d0fa50c8696327 100644 --- a/node.gyp +++ b/node.gyp @@ -341,7 +341,6 @@ [ 'OS=="win"', { 'sources': [ 'src/backtrace_win32.cc', - 'src/res/node.rc', ], 'conditions': [ [ 'node_target_type!="static_library"', {