Skip to content

Commit

Permalink
cuda: disable thin archives when 'cuda' is enabled globally
Browse files Browse the repository at this point in the history
Bug: mesonbuild/pull/9453
Bug: mesonbuild/issues/9479#issuecomment-953485040
  • Loading branch information
SoapGentoo committed May 7, 2024
1 parent 620db36 commit e704937
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2077,6 +2077,7 @@ class StaticLibrary(BuildTarget):
known_kwargs = known_stlib_kwargs

typename = 'static library'
allow_thin_archives = True

def __init__(
self,
Expand All @@ -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)

Expand Down

0 comments on commit e704937

Please sign in to comment.