Skip to content

Commit e595379

Browse files
build,win: replace LTCG with Thin LTO for releases
PR-URL: #63114 Refs: #61964 Reviewed-By: Michaël Zasso <targos@protonmail.com> Signed-off-by: StefanStojanovic <stefan.stojanovic@janeasystems.com>
1 parent e711d3f commit e595379

3 files changed

Lines changed: 33 additions & 13 deletions

File tree

‎common.gypi‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@
277277
},
278278
},
279279
},],
280+
['(enable_thin_lto=="true" or enable_lto=="true") and lto_jobs!=""', {
281+
'msvs_settings': {
282+
'VCLinkerTool': {
283+
'AdditionalOptions': ['/opt:lldltojobs=<(lto_jobs)'],
284+
},
285+
},
286+
},],
280287
],
281288
'target_conditions': [
282289
['_toolset=="target"', {

‎configure.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,14 @@
231231
help="Enable compiling with thin lto of a binary. This feature is only available "
232232
"on windows.")
233233

234+
parser.add_argument("--lto-jobs",
235+
action="store",
236+
dest="lto_jobs",
237+
default=None,
238+
help="Set the number of parallel LTO code generation jobs during linking. "
239+
"Defaults to the number of CPU cores. Lower values reduce peak memory "
240+
"usage at the cost of longer link times. Only effective with LTO enabled.")
241+
234242
parser.add_argument("--link-module",
235243
action="append",
236244
dest="linked_module",
@@ -1833,6 +1841,7 @@ def configure_node(o):
18331841

18341842
o['variables']['enable_lto'] = b(options.enable_lto)
18351843
o['variables']['enable_thin_lto'] = b(options.enable_thin_lto)
1844+
o['variables']['lto_jobs'] = options.lto_jobs or ''
18361845

18371846
if options.node_use_large_pages or options.node_use_large_pages_script_lld:
18381847
warn('''The `--use-largepages` and `--use-largepages-script-lld` options

‎vcbuild.bat‎

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ set target_arch=x64
2626
set ltcg=
2727
set thin_lto=
2828
set lto=
29+
set lto_jobs=
2930
set pgo_generate=
3031
set pgo_use=
3132
set target_env=
@@ -105,6 +106,7 @@ if /i "%1"=="nocorepack" set nocorepack=1&goto arg-ok
105106
if /i "%1"=="ltcg" set ltcg=1&goto arg-ok
106107
if /i "%1"=="thin-lto" set thin_lto=1&goto arg-ok
107108
if /i "%1"=="lto" set lto=1&goto arg-ok
109+
if /i "%1"=="lto-jobs" set "lto_jobs=%2"&goto arg-ok-2
108110
if /i "%1"=="pgo-generate" set pgo_generate=1&goto arg-ok
109111
if /i "%1"=="pgo-use" set pgo_use=1&goto arg-ok
110112
if /i "%1"=="v8windbg" set v8windbg=1&goto arg-ok
@@ -175,6 +177,18 @@ goto next-arg
175177

176178
:args-done
177179

180+
if defined build_release (
181+
set config=Release
182+
set package=1
183+
set msi=1
184+
set licensertf=1
185+
set download_arg="--download=all"
186+
set i18n_arg=full-icu
187+
set projgen=1
188+
set cctest=1
189+
set thin_lto=1
190+
)
191+
178192
:: LTO mutual exclusion
179193
set lto_count=0
180194
if defined ltcg set /a lto_count+=1
@@ -196,18 +210,6 @@ if defined pgo_generate if defined pgo_use (
196210
exit /b 1
197211
)
198212

199-
if defined build_release (
200-
set config=Release
201-
set package=1
202-
set msi=1
203-
set licensertf=1
204-
set download_arg="--download=all"
205-
set i18n_arg=full-icu
206-
set projgen=1
207-
set cctest=1
208-
set ltcg=1
209-
)
210-
211213
if defined msi set stage_package=1
212214
if defined package set stage_package=1
213215

@@ -231,6 +233,7 @@ if defined nocorepack set configure_flags=%configure_flags% --without-core
231233
if defined ltcg set configure_flags=%configure_flags% --with-ltcg
232234
if defined thin_lto set configure_flags=%configure_flags% --enable-thin-lto
233235
if defined lto set configure_flags=%configure_flags% --enable-lto
236+
if defined lto_jobs set configure_flags=%configure_flags% --lto-jobs=%lto_jobs%
234237
if defined pgo_generate set configure_flags=%configure_flags% --enable-pgo-generate
235238
if defined pgo_use set configure_flags=%configure_flags% --enable-pgo-use
236239
if defined release_urlbase set configure_flags=%configure_flags% --release-urlbase=%release_urlbase%
@@ -881,7 +884,7 @@ set exit_code=1
881884
goto exit
882885

883886
:help
884-
echo vcbuild.bat [debug/release] [msi] [doc] [test/test-all/test-addons/test-doc/test-js-native-api/test-node-api/test-internet/test-tick-processor/test-known-issues/test-node-inspect/test-check-deopts/test-npm/test-v8/test-v8-intl/test-v8-benchmarks/test-v8-all] [ignore-flaky] [static/dll] [noprojgen] [projgen] [clang-cl] [ccache path-to-ccache] [small-icu/full-icu/without-intl] [nobuild] [nosnapshot] [nonpm] [nocorepack] [ltcg] [thin-lto] [lto] [pgo-generate] [pgo-use] [licensetf] [sign] [x64/arm64] [vs2022/vs2026] [download-all] [enable-vtune] [lint/lint-ci/lint-js/lint-md] [lint-md-build] [format-md] [package] [build-release] [upload] [no-NODE-OPTIONS] [link-module path-to-module] [debug-http2] [debug-nghttp2] [clean] [cctest] [no-cctest] [openssl-no-asm]
887+
echo vcbuild.bat [debug/release] [msi] [doc] [test/test-all/test-addons/test-doc/test-js-native-api/test-node-api/test-internet/test-tick-processor/test-known-issues/test-node-inspect/test-check-deopts/test-npm/test-v8/test-v8-intl/test-v8-benchmarks/test-v8-all] [ignore-flaky] [static/dll] [noprojgen] [projgen] [clang-cl] [ccache path-to-ccache] [small-icu/full-icu/without-intl] [nobuild] [nosnapshot] [nonpm] [nocorepack] [ltcg] [thin-lto] [lto] [lto-jobs number-of-jobs] [pgo-generate] [pgo-use] [licensetf] [sign] [x64/arm64] [vs2022/vs2026] [download-all] [enable-vtune] [lint/lint-ci/lint-js/lint-md] [lint-md-build] [format-md] [package] [build-release] [upload] [no-NODE-OPTIONS] [link-module path-to-module] [debug-http2] [debug-nghttp2] [clean] [cctest] [no-cctest] [openssl-no-asm]
885888
echo Examples:
886889
echo vcbuild.bat : builds release build
887890
echo vcbuild.bat debug : builds debug build
@@ -895,6 +898,7 @@ echo vcbuild.bat no-cctest : skip building cctest.exe
895898
echo vcbuild.bat ccache c:\ccache\ : use ccache to speed build
896899
echo vcbuild.bat thin-lto : builds with Thin LTO applied globally to all targets
897900
echo vcbuild.bat lto : builds with Full LTO applied globally to all targets
901+
echo vcbuild.bat thin-lto lto-jobs 2 : builds with Thin LTO applied globally to all targets and limits parallel LTO link jobs (reduces peak memory usage)
898902
echo vcbuild.bat pgo-generate : builds instrumented binary for PGO (profile first, then rebuild with pgo-use)
899903
echo vcbuild.bat pgo-use : builds optimized binary using PGO profile data
900904
goto exit

0 commit comments

Comments
 (0)