Fallback to LDC as static linker when not in MSVC build environment

pull/3981/head
GoaLitiuM 6 years ago
parent 79f05b189a
commit 82b38b6071
  1. 10
      mesonbuild/environment.py
  2. 49
      mesonbuild/linkers.py

@ -15,7 +15,7 @@
import configparser, os, platform, re, shlex, shutil, subprocess import configparser, os, platform, re, shlex, shutil, subprocess
from . import coredata from . import coredata
from .linkers import ArLinker, ArmarLinker, VisualStudioLinker from .linkers import ArLinker, ArmarLinker, VisualStudioLinker, LDCLinker
from . import mesonlib from . import mesonlib
from .mesonlib import EnvironmentException, Popen_safe from .mesonlib import EnvironmentException, Popen_safe
from . import mlog from . import mlog
@ -341,6 +341,7 @@ class Environment:
self.vs_static_linker = ['lib'] self.vs_static_linker = ['lib']
self.gcc_static_linker = ['gcc-ar'] self.gcc_static_linker = ['gcc-ar']
self.clang_static_linker = ['llvm-ar'] self.clang_static_linker = ['llvm-ar']
self.ldc2_static_linker = ['ldc2']
# Various prefixes and suffixes for import libraries, shared libraries, # Various prefixes and suffixes for import libraries, shared libraries,
# static libraries, and executables. # static libraries, and executables.
@ -881,6 +882,11 @@ This is probably wrong, it should always point to the native compiler.''' % evar
elif isinstance(compiler, compilers.ClangCompiler): elif isinstance(compiler, compilers.ClangCompiler):
# Use llvm-ar if available; needed for LTO # Use llvm-ar if available; needed for LTO
linkers = [self.clang_static_linker, self.default_static_linker] linkers = [self.clang_static_linker, self.default_static_linker]
elif isinstance(compiler, compilers.DCompiler):
if mesonlib.is_windows():
linkers = [self.vs_static_linker, self.ldc2_static_linker]
else:
linkers = [self.default_static_linker, self.ldc2_static_linker]
else: else:
linkers = [self.default_static_linker] linkers = [self.default_static_linker]
popen_exceptions = {} popen_exceptions = {}
@ -898,6 +904,8 @@ This is probably wrong, it should always point to the native compiler.''' % evar
return VisualStudioLinker(linker) return VisualStudioLinker(linker)
if p.returncode == 0 and ('armar' in linker or 'armar.exe' in linker): if p.returncode == 0 and ('armar' in linker or 'armar.exe' in linker):
return ArmarLinker(linker) return ArmarLinker(linker)
if 'LDC - the LLVM D compiler' in out:
return LDCLinker(linker)
if p.returncode == 0: if p.returncode == 0:
return ArLinker(linker) return ArLinker(linker)
if p.returncode == 1 and err.startswith('usage'): # OSX if p.returncode == 1 and err.startswith('usage'): # OSX

@ -137,3 +137,52 @@ class ArmarLinker(ArLinker):
def can_linker_accept_rsp(self): def can_linker_accept_rsp(self):
# armar cann't accept arguments using the @rsp syntax # armar cann't accept arguments using the @rsp syntax
return False return False
class LDCLinker(StaticLinker):
def __init__(self, exelist):
self.exelist = exelist
self.id = 'ldc2'
def can_linker_accept_rsp(self):
return mesonlib.is_windows()
def build_rpath_args(self, build_dir, from_dir, rpath_paths, build_rpath, install_rpath):
return []
def get_exelist(self):
return self.exelist[:]
def get_std_link_args(self):
return ['-lib']
def get_output_args(self, target):
return ['-of=' + target]
def get_buildtype_linker_args(self, buildtype):
return []
def get_linker_always_args(self):
return []
def get_coverage_link_args(self):
return []
def get_always_args(self):
return []
def thread_link_flags(self, env):
return []
def openmp_flags(self):
return []
def get_option_link_args(self, options):
return []
@classmethod
def unix_args_to_native(cls, args):
return args[:]
def get_link_debugfile_args(self, targetfile):
return []

Loading…
Cancel
Save