Merge pull request #4132 from GoaLitiuM/d-manyfixes

D: Various improvements to argument translation
pull/2393/head
Jussi Pakkanen 6 years ago committed by GitHub
commit f2bde320ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      mesonbuild/backend/backends.py
  2. 90
      mesonbuild/compilers/d.py

@ -591,12 +591,12 @@ class Backend:
for d in deps: for d in deps:
if not (d.is_linkable_target()): if not (d.is_linkable_target()):
raise RuntimeError('Tried to link with a non-library target "%s".' % d.get_basename()) raise RuntimeError('Tried to link with a non-library target "%s".' % d.get_basename())
d_arg = self.get_target_filename_for_linking(d) arg = self.get_target_filename_for_linking(d)
if not d_arg: if not arg:
continue continue
if isinstance(compiler, (compilers.LLVMDCompiler, compilers.DmdDCompiler)): if compiler.get_language() == 'd':
d_arg = '-L' + d_arg arg = '-Wl,' + arg
args.append(d_arg) args.append(arg)
return args return args
def get_mingw_extra_paths(self, target): def get_mingw_extra_paths(self, target):

@ -122,9 +122,8 @@ class DCompiler(Compiler):
def get_linker_search_args(self, dirname): def get_linker_search_args(self, dirname):
# -L is recognized as "add this to the search path" by the linker, # -L is recognized as "add this to the search path" by the linker,
# while the compiler recognizes it as "pass to linker". So, the first # while the compiler recognizes it as "pass to linker".
# -L is for the compiler, telling it to pass the second -L to the linker. return ['-Wl,-L' + dirname]
return ['-L=-L' + dirname]
def get_coverage_args(self): def get_coverage_args(self):
return ['-cov'] return ['-cov']
@ -151,12 +150,15 @@ class DCompiler(Compiler):
def get_soname_args(self, *args): def get_soname_args(self, *args):
# FIXME: Make this work for cross-compiling # FIXME: Make this work for cross-compiling
gcc_type = GCC_STANDARD
if is_windows(): if is_windows():
gcc_type = GCC_CYGWIN return []
if is_osx(): elif is_osx():
gcc_type = GCC_OSX soname_args = get_gcc_soname_args(GCC_OSX, *args)
return get_gcc_soname_args(gcc_type, *args) if soname_args:
return ['-Wl,' + ','.join(soname_args)]
return []
return get_gcc_soname_args(GCC_STANDARD, *args)
def get_feature_args(self, kwargs, build_to_src): def get_feature_args(self, kwargs, build_to_src):
res = [] res = []
@ -231,7 +233,7 @@ class DCompiler(Compiler):
paths = padding paths = padding
else: else:
paths = paths + ':' + padding paths = paths + ':' + padding
return ['-L=-rpath={}'.format(paths)] return ['-Wl,-rpath,{}'.format(paths)]
def _get_compiler_check_args(self, env, extra_args, dependencies, mode='compile'): def _get_compiler_check_args(self, env, extra_args, dependencies, mode='compile'):
if extra_args is None: if extra_args is None:
@ -287,20 +289,25 @@ class DCompiler(Compiler):
# The flags might have been added by pkg-config files, # The flags might have been added by pkg-config files,
# and are therefore out of the user's control. # and are therefore out of the user's control.
for arg in args: for arg in args:
# Translate OS specific arguments first.
osargs = []
if is_windows():
osargs = cls.translate_arg_to_windows(arg)
elif is_osx():
osargs = cls.translate_arg_to_osx(arg)
if osargs:
dcargs.extend(osargs)
continue
# Translate common D arguments here.
if arg == '-pthread': if arg == '-pthread':
continue continue
if arg.startswith('-Wl,'): if arg.startswith('-Wl,'):
# Translate linker arguments here.
linkargs = arg[arg.index(',') + 1:].split(',') linkargs = arg[arg.index(',') + 1:].split(',')
for la in linkargs: for la in linkargs:
if la.startswith('--out-implib='):
# Import library name for MSVC targets
dcargs.append('-L=/IMPLIB:' + la[13:].strip())
continue
dcargs.append('-L=' + la.strip()) dcargs.append('-L=' + la.strip())
continue continue
elif arg.startswith('-install_name'):
dcargs.append('-L=' + arg)
continue
elif arg.startswith('-link-defaultlib') or arg.startswith('-linker'): elif arg.startswith('-link-defaultlib') or arg.startswith('-linker'):
# these are special arguments to the LDC linker call, # these are special arguments to the LDC linker call,
# arguments like "-link-defaultlib-shared" do *not* # arguments like "-link-defaultlib-shared" do *not*
@ -313,7 +320,7 @@ class DCompiler(Compiler):
# translate library link flag # translate library link flag
dcargs.append('-L=' + arg) dcargs.append('-L=' + arg)
continue continue
elif arg.startswith('-L/') or arg.startswith('-L./'): elif arg.startswith('-L'):
# we need to handle cases where -L is set by e.g. a pkg-config # we need to handle cases where -L is set by e.g. a pkg-config
# setting to select a linker search path. We can however not # setting to select a linker search path. We can however not
# unconditionally prefix '-L' with '-L' because the user might # unconditionally prefix '-L' with '-L' because the user might
@ -321,33 +328,56 @@ class DCompiler(Compiler):
# compiler (pass flag through to the linker) # compiler (pass flag through to the linker)
# Hence, we guess here whether the flag was intended to pass # Hence, we guess here whether the flag was intended to pass
# a linker search path. # a linker search path.
dcargs.append('-L=' + arg)
# Make sure static library files are passed properly to the linker.
if arg.endswith('.a') or arg.endswith('.lib'):
if arg.startswith('-L='):
farg = arg[3:]
else:
farg = arg[2:]
if len(farg) > 0 and not farg.startswith('-'):
dcargs.append('-L=' + farg)
continue continue
elif arg.startswith('/') or arg.startswith('./'):
# absolute (or relative) paths passed to the linker may be static libraries
# or other objects that we need to link.
dcargs.append('-L=' + arg) dcargs.append('-L=' + arg)
continue continue
dcargs.append(arg)
return dcargs
@classmethod
def translate_arg_to_windows(cls, arg):
args = []
if arg.startswith('-Wl,'):
# Translate linker arguments here.
linkargs = arg[arg.index(',') + 1:].split(',')
for la in linkargs:
if la.startswith('--out-implib='):
# Import library name
args.append('-L=/IMPLIB:' + la[13:].strip())
elif arg.startswith('-mscrtlib='): elif arg.startswith('-mscrtlib='):
args.append(arg)
mscrtlib = arg[10:].lower() mscrtlib = arg[10:].lower()
if cls is LLVMDCompiler: if cls is LLVMDCompiler:
# Default crt libraries for LDC2 must be excluded for other # Default crt libraries for LDC2 must be excluded for other
# selected crt options. # selected crt options.
if mscrtlib != 'libcmt': if mscrtlib != 'libcmt':
dcargs.append('-L=/NODEFAULTLIB:libcmt') args.append('-L=/NODEFAULTLIB:libcmt')
dcargs.append('-L=/NODEFAULTLIB:libvcruntime') args.append('-L=/NODEFAULTLIB:libvcruntime')
# Fixes missing definitions for printf-functions in VS2017 # Fixes missing definitions for printf-functions in VS2017
if mscrtlib.startswith('msvcrt'): if mscrtlib.startswith('msvcrt'):
dcargs.append('-L=/DEFAULTLIB:legacy_stdio_definitions.lib') args.append('-L=/DEFAULTLIB:legacy_stdio_definitions.lib')
dcargs.append(arg) return args
continue
dcargs.append(arg)
return dcargs @classmethod
def translate_arg_to_osx(cls, arg):
args = []
if arg.startswith('-install_name'):
args.append('-L=' + arg)
return args
def get_debug_args(self, is_debug): def get_debug_args(self, is_debug):
return clike_debug_args[is_debug] return clike_debug_args[is_debug]

Loading…
Cancel
Save