Skip to content

Commit 0d93515

Browse files
authored
Merge pull request #17 from rgommers/aix-linker-issue
linkers: Fix linker detection with clang on Solaris
2 parents 3f28c54 + 4ee834f commit 0d93515

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

mesonbuild/linkers/detect.py

+27-21
Original file line numberDiff line numberDiff line change
@@ -177,27 +177,6 @@ def guess_nix_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
177177
v = search_version(o)
178178

179179
linker = linkers.LLVMDynamicLinker(compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v)
180-
# detect xtools first, bug #10805
181-
elif 'xtools-' in o.split('\n', maxsplit=1)[0]:
182-
xtools = o.split(' ', maxsplit=1)[0]
183-
v = xtools.split('-', maxsplit=2)[1]
184-
linker = linkers.AppleDynamicLinker(compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v)
185-
# First might be apple clang, second is for real gcc, the third is icc.
186-
# Note that "ld: unknown option: " sometimes instead is "ld: unknown options:".
187-
elif e.endswith('(use -v to see invocation)\n') or 'macosx_version' in e or 'ld: unknown option' in e:
188-
if isinstance(comp_class.LINKER_PREFIX, str):
189-
cmd = compiler + [comp_class.LINKER_PREFIX + '-v'] + extra_args
190-
else:
191-
cmd = compiler + comp_class.LINKER_PREFIX + ['-v'] + extra_args
192-
_, newo, newerr = Popen_safe_logged(cmd, msg='Detecting Apple linker via')
193-
194-
for line in newerr.split('\n'):
195-
if 'PROJECT:ld' in line or 'PROJECT:dyld' in line:
196-
v = line.split('-')[1]
197-
break
198-
else:
199-
__failed_to_detect_linker(compiler, check_args, o, e)
200-
linker = linkers.AppleDynamicLinker(compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v)
201180
elif 'GNU' in o or 'GNU' in e:
202181
gnu_cls: T.Type[GnuDynamicLinker]
203182
# this is always the only thing on stdout, except for swift
@@ -227,6 +206,33 @@ def guess_nix_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
227206
linker = linkers.AIXDynamicLinker(
228207
compiler, for_machine, comp_class.LINKER_PREFIX, override,
229208
version=search_version(e))
209+
elif o.startswith('zig ld'):
210+
linker = linkers.ZigCCDynamicLinker(
211+
compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v)
212+
# detect xtools first, bug #10805
213+
elif 'xtools-' in o.split('\n', maxsplit=1)[0]:
214+
xtools = o.split(' ', maxsplit=1)[0]
215+
v = xtools.split('-', maxsplit=2)[1]
216+
linker = linkers.AppleDynamicLinker(compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v)
217+
# detect linker on MacOS - must be after other platforms because the
218+
# "(use -v to see invocation)" will match clang on other platforms,
219+
# but the rest of the checks will fail and call __failed_to_detect_linker.
220+
# First might be apple clang, second is for real gcc, the third is icc.
221+
# Note that "ld: unknown option: " sometimes instead is "ld: unknown options:".
222+
elif e.endswith('(use -v to see invocation)\n') or 'macosx_version' in e or 'ld: unknown option' in e:
223+
if isinstance(comp_class.LINKER_PREFIX, str):
224+
cmd = compiler + [comp_class.LINKER_PREFIX + '-v'] + extra_args
225+
else:
226+
cmd = compiler + comp_class.LINKER_PREFIX + ['-v'] + extra_args
227+
_, newo, newerr = Popen_safe_logged(cmd, msg='Detecting Apple linker via')
228+
229+
for line in newerr.split('\n'):
230+
if 'PROJECT:ld' in line or 'PROJECT:dyld' in line:
231+
v = line.split('-')[1]
232+
break
233+
else:
234+
__failed_to_detect_linker(compiler, check_args, o, e)
235+
linker = linkers.AppleDynamicLinker(compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v)
230236
else:
231237
__failed_to_detect_linker(compiler, check_args, o, e)
232238
return linker

unittests/allplatformstests.py

+2
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,8 @@ def test_compiler_detection(self):
11271127
# ld-like linker of link.exe-like linker (usually the
11281128
# former for msys2, the latter otherwise)
11291129
self.assertIsInstance(cc.linker, (linkers.MSVCDynamicLinker, linkers.GnuLikeDynamicLinkerMixin))
1130+
elif is_sunos():
1131+
self.assertIsInstance(cc.linker, (linkers.SolarisDynamicLinker, linkers.GnuLikeDynamicLinkerMixin))
11301132
else:
11311133
self.assertIsInstance(cc.linker, linkers.GnuLikeDynamicLinkerMixin)
11321134
if isinstance(cc, intel):

0 commit comments

Comments
 (0)