backends/ninja: run `ranlib -c $out` when using the apple ar

Apple's AR is old, and doesn't add externed symbols to the symbol table,
instead relying on the user calling ranlib with -c. We need to do that
for the user
pull/12226/head
Dylan Baker 2 years ago committed by Xavier Claessens
parent 84466b7359
commit 15811e362e
  1. 13
      mesonbuild/backend/ninjabackend.py
  2. 4
      mesonbuild/linkers/linkers.py

@ -2350,7 +2350,7 @@ class NinjaBackend(backends.Backend):
if static_linker is None:
continue
rule = 'STATIC_LINKER{}'.format(self.get_rule_suffix(for_machine))
cmdlist = []
cmdlist: T.List[T.Union[str, NinjaCommandArg]] = []
args = ['$in']
# FIXME: Must normalize file names with pathlib.Path before writing
# them out to fix this properly on Windows. See:
@ -2364,6 +2364,17 @@ class NinjaBackend(backends.Backend):
cmdlist += static_linker.get_exelist()
cmdlist += ['$LINK_ARGS']
cmdlist += NinjaCommandArg.list(static_linker.get_output_args('$out'), Quoting.none)
# The default ar on MacOS (at least through version 12), does not
# add extern'd variables to the symbol table by default, and
# requires that apple's ranlib be called with a special flag
# instead after linking
if static_linker.id == 'applear':
# This is a bit of a hack, but we assume that that we won't need
# an rspfile on MacOS, otherwise the arguments are passed to
# ranlib, not to ar
cmdlist.extend(args)
args = []
cmdlist.extend(['&&', 'ranlib', '-c', '$out'])
description = 'Linking static target $out'
if num_pools > 0:
pool = 'pool = link_pool'

@ -349,6 +349,8 @@ class VisualStudioLinker(VisualStudioLikeLinker, StaticLinker):
"""Microsoft's lib static linker."""
id = 'lib'
def __init__(self, exelist: T.List[str], machine: str):
StaticLinker.__init__(self, exelist)
VisualStudioLikeLinker.__init__(self, machine)
@ -358,6 +360,8 @@ class IntelVisualStudioLinker(VisualStudioLikeLinker, StaticLinker):
"""Intel's xilib static linker."""
id = 'xilib'
def __init__(self, exelist: T.List[str], machine: str):
StaticLinker.__init__(self, exelist)
VisualStudioLikeLinker.__init__(self, machine)

Loading…
Cancel
Save