diff --git a/mesonbuild/compilers/cuda.py b/mesonbuild/compilers/cuda.py index 3bcabf56a..0a26bedb8 100644 --- a/mesonbuild/compilers/cuda.py +++ b/mesonbuild/compilers/cuda.py @@ -34,7 +34,7 @@ class CudaCompiler(Compiler): super().__init__(exelist, version, for_machine, **kwargs) self.is_cross = is_cross self.exe_wrapper = exe_wrapper - self.id = 'nvcc' + self.id = CudaCompiler.cuda_id() default_warn_args = [] self.warn_args = {'0': [], '1': default_warn_args, @@ -42,6 +42,10 @@ class CudaCompiler(Compiler): '3': default_warn_args + ['-Xcompiler=-Wextra', '-Xcompiler=-Wpedantic']} + @staticmethod + def cuda_id(): + return 'nvcc' + def needs_static_linker(self): return False diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index 738696540..b53c6f5c2 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -55,6 +55,7 @@ from .linkers import ( XildAppleDynamicLinker, XildLinuxDynamicLinker, XilinkDynamicLinker, + CudaLinker, ) from functools import lru_cache from .compilers import ( @@ -696,6 +697,9 @@ class Environment: `-Xlinker=--version`) you must pass as a list. :extra_args: Any addtional arguments rquired (such as a source file) """ + if CudaCompiler.cuda_id() in compiler: + return CudaLinker(compiler, for_machine, 'nvlink', prefix, version=CudaLinker.parse_version()) + extra_args = typing.cast(typing.List[str], extra_args or []) if isinstance(prefix, str): check_args = [prefix + '--version'] + extra_args diff --git a/mesonbuild/linkers.py b/mesonbuild/linkers.py index 272f927ca..7db7d09a2 100644 --- a/mesonbuild/linkers.py +++ b/mesonbuild/linkers.py @@ -909,3 +909,32 @@ class OptlinkDynamicLinker(VisualStudioLikeLinkerMixin, DynamicLinker): def get_allow_undefined_args(self) -> typing.List[str]: return [] + +class CudaLinker(DynamicLinker): + """Cuda linker (nvlink)""" + @staticmethod + def parse_version(): + version_cmd = ['nvlink', '--version'] + try: + _, out, _ = mesonlib.Popen_safe(version_cmd) + except OSError: + return 'unknown version' + # Output example: + # nvlink: NVIDIA (R) Cuda linker + # Copyright (c) 2005-2018 NVIDIA Corporation + # Built on Sun_Sep_30_21:09:22_CDT_2018 + # Cuda compilation tools, release 10.0, V10.0.166 + # we need the most verbose version output. Luckily starting with V + return out.strip().split('V')[-1] + + def get_output_args(self, outname: str) -> typing.List[str]: + return ['-o', outname] + + def get_search_args(self, dirname: str) -> typing.List[str]: + return ['-L', dirname] + + def fatal_warnings(self) -> typing.List[str]: + return ['--warning-as-error'] + + def get_allow_undefined_args(self) -> typing.List[str]: + return []