218218 help = "Enable compiling with lto of a binary. This feature is only available "
219219 "with gcc 5.4.1+ or clang 3.9.1+." )
220220
221+ parser .add_argument ("--enable-thin-lto" ,
222+ action = "store_true" ,
223+ dest = "enable_thin_lto" ,
224+ default = None ,
225+ help = "Enable compiling with thin lto of a binary. This feature is only available "
226+ "on windows." )
227+
221228parser .add_argument ("--link-module" ,
222229 action = "append" ,
223230 dest = "linked_module" ,
919926 action = 'store_true' ,
920927 dest = 'with_ltcg' ,
921928 default = None ,
922- help = 'Use Thin LTO. This feature is only available on Windows.' )
929+ help = 'Use Thin LTO scoped to node.exe and libnode only. '
930+ 'This feature is only available on Windows.' )
923931
924932parser .add_argument ('--write-snapshot-as-array-literals' ,
925933 action = 'store_true' ,
@@ -1932,11 +1940,27 @@ def configure_node(o):
19321940 o ['variables' ]['enable_pgo_generate' ] = b (options .enable_pgo_generate )
19331941 o ['variables' ]['enable_pgo_use' ] = b (options .enable_pgo_use )
19341942
1935- if flavor == 'win' and ( options .enable_lto ) :
1943+ if flavor != 'win' and options .enable_thin_lto :
19361944 raise Exception (
1937- 'Use Link Time Code Generation instead.' )
1945+ 'Use --enable-lto instead.' )
1946+
1947+ # LTO mutual exclusion
1948+ if flavor == 'win' :
1949+ lto_options = []
1950+ if options .enable_lto :
1951+ lto_options .append ('--enable-lto' )
1952+ if options .enable_thin_lto :
1953+ lto_options .append ('--enable-thin-lto' )
1954+ if options .with_ltcg :
1955+ lto_options .append ('--with-ltcg' )
1956+ if len (lto_options ) > 1 :
1957+ raise Exception (
1958+ f'Only one LTO option can be specified at a time: { ", " .join (lto_options )} . '
1959+ 'Use --enable-lto for Full LTO (global), '
1960+ '--enable-thin-lto for Thin LTO (global), '
1961+ 'or --with-ltcg for Thin LTO (scoped to node.exe and libnode).' )
19381962
1939- if options .enable_lto :
1963+ if options .enable_lto and flavor != 'win' :
19401964 gcc_version_checked = (5 , 4 , 1 )
19411965 clang_version_checked = (3 , 9 , 1 )
19421966 if not gcc_version_ge (gcc_version_checked ) and not clang_version_ge (clang_version_checked ):
@@ -1947,6 +1971,7 @@ def configure_node(o):
19471971 f'or clang { clang_version_checked_str } + only.' )
19481972
19491973 o ['variables' ]['enable_lto' ] = b (options .enable_lto )
1974+ o ['variables' ]['enable_thin_lto' ] = b (options .enable_thin_lto )
19501975
19511976 if options .node_use_large_pages or options .node_use_large_pages_script_lld :
19521977 warn ('''The `--use-largepages` and `--use-largepages-script-lld` options
0 commit comments