From c0fd20f164609b8c3be516b5be3d70a4b9ff6f49 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 16 Dec 2019 10:41:13 -0800 Subject: compilers/d: Remove CompilerIsLInkerMixin This was never really true of the D compilers, it made them more complicated than necessary and was incorrect in many cases. Removing it causes no regressions on Linux, at least in our rather limited test cases). --- mesonbuild/compilers/d.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'mesonbuild/compilers/d.py') diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py index b974504..99889b0 100644 --- a/mesonbuild/compilers/d.py +++ b/mesonbuild/compilers/d.py @@ -28,7 +28,6 @@ from .compilers import ( CompilerArgs, ) from .mixins.gnu import GnuCompiler -from .mixins.islinker import LinkerEnvVarsMixin, BasicLinkerIsCompilerMixin if T.TYPE_CHECKING: from ..envconfig import MachineInfo @@ -69,7 +68,7 @@ dmd_optimization_args = {'0': [], class DmdLikeCompilerMixin: - LINKER_PREFIX = '-L' + LINKER_PREFIX = '-L=' def get_output_args(self, target): return ['-of=' + target] @@ -214,7 +213,7 @@ class DmdLikeCompilerMixin: return [] def gen_import_library_args(self, implibname): - return ['-Wl,--out-implib=' + implibname] + return self.linker.import_library_args(implibname) def build_rpath_args(self, env, build_dir, from_dir, rpath_paths, build_rpath, install_rpath): if self.info.is_windows(): @@ -392,16 +391,10 @@ class DmdLikeCompilerMixin: # LDC and DMD actually do use a linker, but they proxy all of that with # their own arguments soargs = [] - for arg in Compiler.get_soname_args(self, *args, **kwargs): + for arg in super().get_soname_args(*args, **kwargs): soargs.append('-L=' + arg) return soargs - def get_allow_undefined_link_args(self) -> T.List[str]: - args = [] - for arg in self.linker.get_allow_undefined_args(): - args.append('-L=' + arg) - return args - class DCompiler(Compiler): mscrt_args = { @@ -600,7 +593,7 @@ class DCompiler(Compiler): return [] def thread_link_flags(self, env): - return ['-pthread'] + return self.linker.thread_flags(env) def name_string(self): return ' '.join(self.exelist) @@ -658,7 +651,7 @@ class GnuDCompiler(DCompiler, GnuCompiler): return self.linker.get_allow_undefined_args() -class LLVMDCompiler(DmdLikeCompilerMixin, LinkerEnvVarsMixin, BasicLinkerIsCompilerMixin, DCompiler): +class LLVMDCompiler(DmdLikeCompilerMixin, DCompiler): def __init__(self, exelist, version, for_machine: MachineChoice, info: 'MachineInfo', arch, **kwargs): @@ -687,9 +680,6 @@ class LLVMDCompiler(DmdLikeCompilerMixin, LinkerEnvVarsMixin, BasicLinkerIsCompi def get_pic_args(self): return ['-relocation-model=pic'] - def get_std_shared_lib_link_args(self): - return ['-shared'] - def get_crt_link_args(self, crt_val, buildtype): return self.get_crt_args(crt_val, buildtype) @@ -700,7 +690,7 @@ class LLVMDCompiler(DmdLikeCompilerMixin, LinkerEnvVarsMixin, BasicLinkerIsCompi return ldc_optimization_args[optimization_level] -class DmdDCompiler(DmdLikeCompilerMixin, LinkerEnvVarsMixin, BasicLinkerIsCompilerMixin, DCompiler): +class DmdDCompiler(DmdLikeCompilerMixin, DCompiler): def __init__(self, exelist, version, for_machine: MachineChoice, info: 'MachineInfo', arch, **kwargs): -- cgit v1.1 From f404c679cf292e6a7cf3886cd94511602c1c09f9 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 16 Dec 2019 11:31:24 -0800 Subject: compilers/d: Fix get_allow_undefined_link_args on macOS DMD and LDC are a real pain to use as linkers. On Unices they invoke the C compiler as the linker, just like meson does. This means we have to figure out what C compiler they're using and try to pass valid arguments to that compiler if the D compiler doesn't understand the linker arguments we want to pass. In this case that means gcc or clang. We can use-the -Xcc to pass arguments directly to the C compiler without dmd/ldc getting involved, so we'll use that. --- mesonbuild/compilers/d.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'mesonbuild/compilers/d.py') diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py index 99889b0..5759f33 100644 --- a/mesonbuild/compilers/d.py +++ b/mesonbuild/compilers/d.py @@ -395,6 +395,17 @@ class DmdLikeCompilerMixin: soargs.append('-L=' + arg) return soargs + def get_allow_undefined_link_args(self) -> T.List[str]: + args = self.linker.get_allow_undefined_args() + if self.info.is_darwin(): + # On macOS we're passing these options to the C compiler, but + # they're linker options and need -Wl, so clang/gcc knows what to + # do with them. I'm assuming, but don't know for certain, that + # ldc/dmd do some kind of mapping internally for arguments they + # understand, but pass arguments they don't understand directly. + args = [a.replace('-L=', '-Xcc=-Wl,') for a in args] + return args + class DCompiler(Compiler): mscrt_args = { -- cgit v1.1 From 1fe153a3a5ae235aa9b51cc4ff74e49fd339c858 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 6 Mar 2020 15:37:56 -0800 Subject: Allow invoking link.exe and lld-link.exe through ldc2 Like it wants --- mesonbuild/compilers/d.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'mesonbuild/compilers/d.py') diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py index 5759f33..293a2ae 100644 --- a/mesonbuild/compilers/d.py +++ b/mesonbuild/compilers/d.py @@ -700,6 +700,10 @@ class LLVMDCompiler(DmdLikeCompilerMixin, DCompiler): def get_optimization_args(self, optimization_level): return ldc_optimization_args[optimization_level] + @classmethod + def use_linker_args(cls, linker: str) -> T.List[str]: + return ['-linker={}'.format(linker)] + class DmdDCompiler(DmdLikeCompilerMixin, DCompiler): -- cgit v1.1 From fe86c594c6a3b5f99d2150ae165c951e7a41955a Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 6 Mar 2020 16:00:32 -0800 Subject: Allow invoking the linker directly through dmd DMD is awful in a lot of ways. To change the linker you set an environment variable, which is pretty much impossible for us. --- mesonbuild/compilers/d.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'mesonbuild/compilers/d.py') diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py index 293a2ae..a026e83 100644 --- a/mesonbuild/compilers/d.py +++ b/mesonbuild/compilers/d.py @@ -765,3 +765,6 @@ class DmdDCompiler(DmdLikeCompilerMixin, DCompiler): def get_optimization_args(self, optimization_level): return dmd_optimization_args[optimization_level] + + def can_linker_accept_rsp(self) -> bool: + return False -- cgit v1.1 From f13608460959af6c17081e7ee82f45c4a7541feb Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 10 Mar 2020 08:31:41 -0700 Subject: compilers/d: Fix rpath generation with LDC and DMD --- mesonbuild/compilers/d.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'mesonbuild/compilers/d.py') diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py index a026e83..52126e3 100644 --- a/mesonbuild/compilers/d.py +++ b/mesonbuild/compilers/d.py @@ -219,20 +219,24 @@ class DmdLikeCompilerMixin: if self.info.is_windows(): return [] - # This method is to be used by LDC and DMD. - # GDC can deal with the verbatim flags. - if not rpath_paths and not install_rpath: - return [] - paths = ':'.join([os.path.join(build_dir, p) for p in rpath_paths]) - if build_rpath != '': - paths += ':' + build_rpath - if len(paths) < len(install_rpath): - padding = 'X' * (len(install_rpath) - len(paths)) - if not paths: - paths = padding - else: - paths = paths + ':' + padding - return ['-Wl,-rpath,{}'.format(paths)] + # GNU ld, solaris ld, and lld acting like GNU ld + if self.linker.id.startswith('ld'): + # The way that dmd and ldc pass rpath to gcc is different than we would + # do directly, each argument -rpath and the value to rpath, need to be + # split into two separate arguments both prefaced with the -L=. + args = [] + for r in super().build_rpath_args( + env, build_dir, from_dir, rpath_paths, build_rpath, install_rpath): + if ',' in r: + a, b = r.split(',', maxsplit=1) + args.append(a) + args.append(self.LINKER_PREFIX + b) + else: + args.append(r) + return args + + return super().build_rpath_args( + env, build_dir, from_dir, rpath_paths, build_rpath, install_rpath) def translate_args_to_nongnu(self, args): dcargs = [] -- cgit v1.1 From 92e80d54e531dbf89b8cb74b2e54ee6f8f9f896b Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 10 Mar 2020 10:13:03 -0700 Subject: compilers/d: Properly pass -soname args --- mesonbuild/compilers/d.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'mesonbuild/compilers/d.py') diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py index 52126e3..9a46a4e 100644 --- a/mesonbuild/compilers/d.py +++ b/mesonbuild/compilers/d.py @@ -394,10 +394,23 @@ class DmdLikeCompilerMixin: def get_soname_args(self, *args, **kwargs) -> T.List[str]: # LDC and DMD actually do use a linker, but they proxy all of that with # their own arguments - soargs = [] - for arg in super().get_soname_args(*args, **kwargs): - soargs.append('-L=' + arg) - return soargs + if self.linker.id.startswith('ld.'): + soargs = [] + for arg in super().get_soname_args(*args, **kwargs): + a, b = arg.split(',', maxsplit=1) + soargs.append(a) + soargs.append(self.LINKER_PREFIX + b) + return soargs + elif self.linker.id.startswith('ld64'): + soargs = [] + for arg in super().get_soname_args(*args, **kwargs): + if not arg.startswith(self.LINKER_PREFIX): + soargs.append(self.LINKER_PREFIX + arg) + else: + soargs.append(arg) + return soargs + else: + return super().get_soname_args(*args, **kwargs) def get_allow_undefined_link_args(self) -> T.List[str]: args = self.linker.get_allow_undefined_args() -- cgit v1.1