Skip to content

Commit

Permalink
backends/ninja: run ranlib -c $out when using the apple ar
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dcbaker authored and nirbheek committed Aug 8, 2022
1 parent ee16f01 commit 77e589c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions mesonbuild/backend/ninjabackend.py
Expand Up @@ -42,7 +42,7 @@
PGICCompiler,
VisualStudioLikeCompiler,
)
from ..linkers import ArLinker, RSPFileSyntax
from ..linkers import ArLinker, AppleArLinker, RSPFileSyntax
from ..mesonlib import (
File, LibType, MachineChoice, MesonException, OrderedSet, PerMachine,
ProgressBar, quote_arg
Expand Down Expand Up @@ -2028,7 +2028,7 @@ def generate_static_link_rules(self):
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:
Expand All @@ -2042,6 +2042,17 @@ def generate_static_link_rules(self):
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 isinstance(static_linker, AppleArLinker):
# 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'
Expand Down

0 comments on commit 77e589c

Please sign in to comment.