Add link_early_args parameter to build targets

This parameter provides a way to specify linker arguments that are
inserted in the command line before any input files or libraries.

In the ninjabackend, this is done by adding these to the ARGS
parameter during linking as that is placed in the command line before
the input file and libraries are processed.

Signed-off-by: Keith Packard <keithp@keithp.com>
pull/14004/head
Keith Packard 3 months ago
parent df79a51571
commit 8044c95557
  1. 8
      docs/yaml/functions/_build_target_base.yaml
  2. 8
      mesonbuild/backend/ninjabackend.py
  3. 5
      mesonbuild/build.py
  4. 3
      mesonbuild/compilers/compilers.py
  5. 7
      mesonbuild/interpreter/type_checking.py

@ -103,6 +103,14 @@ kwargs:
Flags to use during linking. You can use UNIX-style
flags here for all platforms.
link_early_args:
type: list[str]
description: |
Flags to use during linking. These are just like link_args,
except that they are inserted into the linker command line
before any object files or libraries. You can use UNIX-style
flags here for all platforms.
link_depends:
type: str | file | custom_tgt | custom_idx
description: |

@ -3613,15 +3613,19 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
raise MesonException(f'Tried to link the target named \'{target.name}\' with a MIL archive without LTO enabled! This causes the compiler to ignore the archive.')
# Compiler args must be included in TI C28x linker commands.
compile_args = []
if linker.get_id() in {'c2000', 'c6000', 'ti'}:
compile_args = []
for for_machine in MachineChoice:
clist = self.environment.coredata.compilers[for_machine]
for langname, compiler in clist.items():
if langname in {'c', 'cpp'} and compiler.get_id() in {'c2000', 'c6000', 'ti'}:
compile_args += self.generate_basic_compiler_args(target, compiler)
elem.add_item('ARGS', compile_args)
# Add early arguments before any object files or libraries
if not isinstance(target, build.StaticLibrary):
compile_args += linker.get_target_link_early_args(target)
if compile_args:
elem.add_item('ARGS', compile_args)
elem.add_item('LINK_ARGS', commands)
self.create_target_linker_introspection(target, linker, commands)
return elem

@ -85,6 +85,7 @@ buildtarget_kwargs = {
'link_with',
'link_whole',
'link_args',
'link_early_args',
'link_depends',
'implicit_include_directories',
'include_directories',
@ -1128,6 +1129,10 @@ class BuildTarget(Target):
or build_rpath properties instead.
This will become a hard error in a future Meson release.
'''))
self.link_early_args = extract_as_list(kwargs, 'link_early_args')
for i in self.link_early_args:
if not isinstance(i, str):
raise InvalidArguments('link_early_args values must be strings.')
self.process_link_depends(kwargs.get('link_depends', []))
# Target-specific include dirs must be added BEFORE include dirs from
# internal deps (added inside self.add_deps()) to override them.

@ -1099,6 +1099,9 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
def get_target_link_args(self, target: 'BuildTarget') -> T.List[str]:
return target.link_args
def get_target_link_early_args(self, target: 'BuildTarget') -> T.List[str]:
return target.link_early_args
def get_dependency_compile_args(self, dep: 'Dependency') -> T.List[str]:
return dep.get_compile_args()

@ -634,6 +634,13 @@ _BUILD_TARGET_KWS: T.List[KwargInfo] = [
validator=in_set_validator(set(compilers.all_languages)),
since='0.51.0',
),
KwargInfo(
'link_early_args',
(ContainerTypeInfo(list, str), NoneType),
listify=True,
default=None,
since='1.7.0',
),
]
def _validate_win_subsystem(value: T.Optional[str]) -> T.Optional[str]:

Loading…
Cancel
Save