Only use custom LTO flags when we actually want LTO

This considerably speeds up linking of release binaries with msvc when testing locally, when LTO is of no concern.

Also properly override b_lto and b_vscrt in all cases for all targets, never leaving them to take default values.
This commit is contained in:
Tamás Bálint Misius
2024-12-09 17:28:19 +01:00
parent a85bee5578
commit 9233b0036f
3 changed files with 28 additions and 13 deletions

2
.github/build.sh vendored
View File

@@ -308,7 +308,7 @@ if [[ "$BSH_HOST_PLATFORM-$BSH_HOST_LIBC" == "windows-mingw" ]]; then
meson_configure+=$'\t'-Dwindows_icons=false meson_configure+=$'\t'-Dwindows_icons=false
fi fi
if [[ $BSH_DEBUG_RELEASE-$BSH_STATIC_DYNAMIC == release-static ]]; then if [[ $BSH_DEBUG_RELEASE-$BSH_STATIC_DYNAMIC == release-static ]]; then
meson_configure+=$'\t'-Db_lto=true meson_configure+=$'\t'-Dlto=true
fi fi
if [[ $BSH_HOST_PLATFORM-$BSH_HOST_ARCH == darwin-aarch64 ]]; then if [[ $BSH_HOST_PLATFORM-$BSH_HOST_ARCH == darwin-aarch64 ]]; then
meson_configure+=$'\t'--cross-file=.github/macaa64-ghactions.ini meson_configure+=$'\t'--cross-file=.github/macaa64-ghactions.ini

View File

@@ -261,16 +261,23 @@ if not is_debug
project_cpp_args += args_ccomp_opt project_cpp_args += args_ccomp_opt
endif endif
if not is_debug lto = get_option('lto')
args_ccomp_lto = [] if cpp_compiler.get_argument_syntax() == 'msvc'
if cpp_compiler.get_id() in [ 'clang', 'clang-cl' ] if lto
# use ThinLTO for Clang/LLVM # apparently meson doesn't know how to tell msvc to use lto: b_lto doesn't even exist when using msvc
args_ccomp_lto += [ '-flto=thin' ] # https://github.com/mesonbuild/meson/blob/1.4.2/mesonbuild/compilers/mixins/visualstudio.py#L113
elif cpp_compiler.get_argument_syntax() == 'msvc' # so we do it ourselves
args_ccomp_lto += [ '/GL' ] project_cpp_args += [ '/GL' ]
project_link_args += [ '/LTCG' ] project_link_args += [ '/LTCG' ]
endif endif
project_cpp_args += args_ccomp_lto else
target_options += [ 'b_lto=@0@'.format(lto) ]
if lto
if cpp_compiler.get_id() in [ 'clang', 'clang-cl' ]
# use ThinLTO for Clang/LLVM
project_cpp_args += [ '-flto=thin' ]
endif
endif
endif endif
if cpp_compiler.get_argument_syntax() == 'msvc' if cpp_compiler.get_argument_syntax() == 'msvc'
@@ -358,10 +365,12 @@ if host_platform == 'windows'
endif endif
endforeach endforeach
endif endif
if tpt_libs_static == 'static' and host_libc == 'msvc' if host_libc == 'msvc'
target_options += [ if tpt_libs_static == 'static'
'b_vscrt=static_from_buildtype', target_options += [ 'b_vscrt=static_from_buildtype' ]
] else
target_options += [ 'b_vscrt=from_buildtype' ]
endif
endif endif
foreach def : defs_ccomp_win foreach def : defs_ccomp_win
if cpp_compiler.get_argument_syntax() == 'msvc' if cpp_compiler.get_argument_syntax() == 'msvc'

View File

@@ -5,6 +5,12 @@ option(
value: 'none', value: 'none',
description: 'Build statically using libraries present on the system (\'system\') or using prebuilt libraries official builds use (\'prebuilt\')' description: 'Build statically using libraries present on the system (\'system\') or using prebuilt libraries official builds use (\'prebuilt\')'
) )
option(
'lto',
type: 'boolean',
value: false,
description: 'Link-time optimization, mostly a wrapper around the b_lto built-in option'
)
option( option(
'beta', 'beta',
type: 'boolean', type: 'boolean',