From e7049374ecffcee54ac478a414ff063e938a8330 Mon Sep 17 00:00:00 2001 From: David Seifert Date: Tue, 7 May 2024 17:19:21 +0200 Subject: [PATCH] cuda: disable thin archives when 'cuda' is enabled globally Bug: mesonbuild/meson/pull/9453 Bug: mesonbuild/meson/issues/9479#issuecomment-953485040 --- mesonbuild/backend/ninjabackend.py | 3 ++- mesonbuild/build.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index e394c60fcc30..f5755b433f77 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -3255,7 +3255,8 @@ def get_target_type_link_args(self, target, linker): if target.import_filename: commands += linker.gen_import_library_args(self.get_import_filename(target)) elif isinstance(target, build.StaticLibrary): - commands += linker.get_std_link_args(self.environment, not target.should_install()) + produce_thin_archive = build.StaticLibrary.allow_thin_archives and not target.should_install() + commands += linker.get_std_link_args(self.environment, produce_thin_archive) else: raise RuntimeError('Unknown build target type.') return commands diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 6f0d6a2ddaac..368b082b8256 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -2077,6 +2077,7 @@ class StaticLibrary(BuildTarget): known_kwargs = known_stlib_kwargs typename = 'static library' + allow_thin_archives = True def __init__( self, @@ -2091,6 +2092,15 @@ def __init__( compilers: T.Dict[str, 'Compiler'], kwargs): self.prelink = T.cast('bool', kwargs.get('prelink', False)) + if StaticLibrary.allow_thin_archives and 'cuda' in environment.coredata.compilers[for_machine]: + # nvcc chokes on thin archives: + # nvlink fatal : Could not open input file 'libfoo.a.p' + # nvlink fatal : elfLink internal error + # hence we disable them if 'cuda' is enabled globally. See also + # - https://github.com/mesonbuild/meson/pull/9453 + # - https://github.com/mesonbuild/meson/issues/9479#issuecomment-953485040 + mlog.debug('cuda enabled globally, disabling thin archives, since nvcc/nvlink cannot handle thin archives natively') + StaticLibrary.allow_thin_archives = False super().__init__(name, subdir, subproject, for_machine, sources, structured_sources, objects, environment, compilers, kwargs)