From e18a61afc1669d4897e6c5c8a6694f4995a0f4d6 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 4 Mar 2020 07:50:45 -0800 Subject: [PATCH] build: shrink bloated addon binaries on windows PR-URL: https://github.com/nodejs/node-gyp/pull/2060 Reviewed-By: Bartosz Sosnowski --- addon.gypi | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/addon.gypi b/addon.gypi index 6462f539ff..9327b0d722 100644 --- a/addon.gypi +++ b/addon.gypi @@ -1,7 +1,8 @@ { 'variables' : { 'node_engine_include_dir%': 'deps/v8/include', - 'node_host_binary%': 'node' + 'node_host_binary%': 'node', + 'node_with_ltcg%': 'true', }, 'target_defaults': { 'type': 'loadable_module', @@ -126,6 +127,26 @@ 'library_dirs': [ '<(node_root_dir)/$(ConfigurationName)' ], 'libraries': [ '<@(node_engine_libs)' ], }], + ['node_with_ltcg=="true"', { + 'msvs_settings': { + 'VCCLCompilerTool': { + 'WholeProgramOptimization': 'true' # /GL, whole program optimization, needed for LTCG + }, + 'VCLibrarianTool': { + 'AdditionalOptions': [ + '/LTCG:INCREMENTAL', # incremental link-time code generation + ] + }, + 'VCLinkerTool': { + 'OptimizeReferences': 2, # /OPT:REF + 'EnableCOMDATFolding': 2, # /OPT:ICF + 'LinkIncremental': 1, # disable incremental linking + 'AdditionalOptions': [ + '/LTCG:INCREMENTAL', # incremental link-time code generation + ] + } + } + }] ], 'libraries': [ '-lkernel32.lib',