Skip to content

Commit 520c2a3

Browse files
committed
Pass runtime library directories to nvcc in a form it accepts
distutils renders runtime_library_dirs as -Wl,--rpath=... inside the link call, so the flags never pass through forward_host_flags and reached nvcc bare, which rejects them. The device link drops them: it produces a relocatable device object, where a runtime search path has no meaning. The shared link passes the same directories as -Xlinker --rpath=..., preserving the rpath rather than discarding it.
1 parent 2f1f89a commit 520c2a3

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/pyjac/pywrap/pyjacob_cuda_setup.py.in

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,21 @@ def customize_linker_for_nvcc(self):
139139
self.linker_exe = forward_host_flags(self.linker_exe)
140140
self.compiler_cxx = forward_host_flags(self.compiler_cxx)
141141

142+
# Runtime library directories are rendered as -Wl,--rpath=... by
143+
# distutils itself, inside the call below, so they cannot be caught by
144+
# forward_host_flags above. nvcc rejects them. The device link has no
145+
# use for a runtime search path at all, and the shared link needs the
146+
# same thing expressed with -Xlinker.
147+
rpath = []
148+
for directory in runtime_library_dirs or []:
149+
rpath += ['-Xlinker', '--rpath=' + directory]
150+
142151
#some more shenanegains to generate the dlink
143152
linker_so_save = self.linker_so[:]
144153
self.linker_so = [x for x in self.linker_so if not '-shared' in x]
145154
obj_filt = [x for x in objects if 'pyjacob.o' in x]
146155
super('object', obj_filt + ['$libname'], 'cuda_link.o', build_temp,
147-
libraries, library_dirs, runtime_library_dirs, export_symbols,
156+
libraries, library_dirs, [], export_symbols,
148157
debug, ['-arch=$cudaarch', '--compiler-options', '"-fPIC"', '-dlink'],
149158
extra_postargs, build_temp, target_lang)
150159

@@ -153,8 +162,8 @@ def customize_linker_for_nvcc(self):
153162

154163
super(target_desc, objects + [os.path.join(build_temp, 'cuda_link.o'), '$libname'],
155164
output_filename, output_dir,
156-
libraries, library_dirs, runtime_library_dirs, export_symbols,
157-
debug, extra_preargs, extra_postargs, build_temp, target_lang)
165+
libraries, library_dirs, [], export_symbols,
166+
debug, extra_preargs, (extra_postargs or []) + rpath, build_temp, target_lang)
158167

159168
#restore
160169
self.linker_so = default_linker_so[:]

0 commit comments

Comments
 (0)