diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2019-08-27 14:50:10 -0700 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2019-08-30 00:01:32 +0300 |
commit | 0efab591da210418e0d618449be2f9462d5d58e8 (patch) | |
tree | b2fb1641b336c8262b1ec2e4da5d6cec12046241 /mesonbuild/compilers | |
parent | 3256e7ea63edb8508d1a2aac45da02e5c452df2c (diff) | |
download | meson-0efab591da210418e0d618449be2f9462d5d58e8.zip meson-0efab591da210418e0d618449be2f9462d5d58e8.tar.gz meson-0efab591da210418e0d618449be2f9462d5d58e8.tar.bz2 |
compilers: Move the compiler argument to proxy linker flags to the compiler class
Instead of the DynamicLinker returning a hardcoded value like
`-Wl,-foo`, it now is passed a value that could be '-Wl,', or could be
something '-Xlinker='
This makes a few things cleaner, and will make it possible to fix using
clang (not clang-cl) on windows, where it invokes either link.exe or
lld-link.exe instead of a gnu-ld compatible linker.
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r-- | mesonbuild/compilers/compilers.py | 2 | ||||
-rw-r--r-- | mesonbuild/compilers/cuda.py | 16 | ||||
-rw-r--r-- | mesonbuild/compilers/d.py | 6 | ||||
-rw-r--r-- | mesonbuild/compilers/fortran.py | 6 | ||||
-rw-r--r-- | mesonbuild/compilers/mixins/gnu.py | 4 | ||||
-rw-r--r-- | mesonbuild/compilers/swift.py | 3 |
6 files changed, 26 insertions, 11 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index f16e447..4218775 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -650,6 +650,8 @@ class Compiler: # manually searched. internal_libs = () + LINKER_PREFIX = None # type: typing.Union[None, str, typing.List[str]] + def __init__(self, exelist, version, for_machine: MachineChoice, linker: typing.Optional['DynamicLinker'] = None, **kwargs): if isinstance(exelist, str): diff --git a/mesonbuild/compilers/cuda.py b/mesonbuild/compilers/cuda.py index b6bafe7..3bcabf5 100644 --- a/mesonbuild/compilers/cuda.py +++ b/mesonbuild/compilers/cuda.py @@ -25,6 +25,9 @@ if typing.TYPE_CHECKING: class CudaCompiler(Compiler): + + LINKER_PREFIX = '-Xlinker=' + def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs): if not hasattr(self, 'language'): self.language = 'cuda' @@ -162,17 +165,8 @@ class CudaCompiler(Compiler): @staticmethod def _cook_link_args(args: typing.List[str]) -> typing.List[str]: - """ - Converts GNU-style arguments -Wl,-arg,-arg - to NVCC-style arguments -Xlinker=-arg,-arg - """ - cooked = [] # type: typing.List[str] - for arg in args: - if arg.startswith('-Wl,'): - arg = arg.replace('-Wl,', '-Xlinker=', 1) - arg = arg.replace(' ', '\\') - cooked.append(arg) - return cooked + """Fixup arguments.""" + return [a.replace(' ', '\\') for a in args] def name_string(self): return ' '.join(self.exelist) diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py index 18e3bf9..5e0c173 100644 --- a/mesonbuild/compilers/d.py +++ b/mesonbuild/compilers/d.py @@ -67,6 +67,8 @@ dmd_optimization_args = {'0': [], class DmdLikeCompilerMixin: + LINKER_PREFIX = '-L' + def get_output_args(self, target): return ['-of=' + target] @@ -577,6 +579,10 @@ class DCompiler(Compiler): class GnuDCompiler(DCompiler, GnuCompiler): + + # we mostly want DCompiler, but that gives us the Compiler.LINKER_PREFIX instead + LINKER_PREFIX = GnuCompiler.LINKER_PREFIX + def __init__(self, exelist, version, for_machine: MachineChoice, arch, **kwargs): DCompiler.__init__(self, exelist, version, for_machine, arch, **kwargs) self.id = 'gcc' diff --git a/mesonbuild/compilers/fortran.py b/mesonbuild/compilers/fortran.py index 30ec6fe..fd7b91a 100644 --- a/mesonbuild/compilers/fortran.py +++ b/mesonbuild/compilers/fortran.py @@ -185,6 +185,9 @@ class ElbrusFortranCompiler(GnuFortranCompiler, ElbrusCompiler): ElbrusCompiler.__init__(self, compiler_type, defines) class G95FortranCompiler(FortranCompiler): + + LINKER_PREFIX = '-Wl,' + def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwags): FortranCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwags) self.id = 'g95' @@ -203,6 +206,9 @@ class G95FortranCompiler(FortranCompiler): class SunFortranCompiler(FortranCompiler): + + LINKER_PREFIX = '-Wl,' + def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwags): FortranCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwags) self.id = 'sun' diff --git a/mesonbuild/compilers/mixins/gnu.py b/mesonbuild/compilers/mixins/gnu.py index d4318b6..998b86c 100644 --- a/mesonbuild/compilers/mixins/gnu.py +++ b/mesonbuild/compilers/mixins/gnu.py @@ -128,6 +128,9 @@ class GnuLikeCompiler(metaclass=abc.ABCMeta): and ICC. Certain functionality between them is different and requires that the actual concrete subclass define their own implementation. """ + + LINKER_PREFIX = '-Wl,' + def __init__(self, compiler_type: 'CompilerType'): self.compiler_type = compiler_type self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage', @@ -298,6 +301,7 @@ class GnuCompiler(GnuLikeCompiler): GnuCompiler represents an actual GCC in its many incarnations. Compilers imitating GCC (Clang/Intel) should use the GnuLikeCompiler ABC. """ + def __init__(self, compiler_type: 'CompilerType', defines: typing.Dict[str, str]): super().__init__(compiler_type) self.id = 'gcc' diff --git a/mesonbuild/compilers/swift.py b/mesonbuild/compilers/swift.py index 6c639fd..e429056 100644 --- a/mesonbuild/compilers/swift.py +++ b/mesonbuild/compilers/swift.py @@ -27,6 +27,9 @@ swift_optimization_args = {'0': [], } class SwiftCompiler(Compiler): + + LINKER_PREFIX = ['-Xlinker'] + def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, **kwargs): self.language = 'swift' super().__init__(exelist, version, for_machine, **kwargs) |