Skip to content

Commit f955a51

Browse files
author
unknown
committed
Support device linking on Windows
1 parent 5006f0c commit f955a51

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

SConstruct

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ gnu_linker_flags = {
7979
'workarounds' : []
8080
}
8181

82+
nv_linker_flags = gnu_linker_flags
83+
8284
clang_linker_flags = {
8385
'debug' : [],
8486
'release' : [],
@@ -88,12 +90,13 @@ clang_linker_flags = {
8890
msvc_linker_flags = {
8991
'debug' : ['/debug'],
9092
'release' : [],
91-
'workarounds' : []
93+
'workarounds' : ['/nologo']
9294
}
9395

9496
linker_to_flags = {
9597
'gcc' : gnu_linker_flags,
9698
'link' : msvc_linker_flags,
99+
'nvcc' : nv_linker_flags,
97100
'clang++' : clang_linker_flags
98101
}
99102

@@ -248,7 +251,7 @@ def libs(env, CCX, host_backend, device_backend):
248251
return result
249252

250253

251-
def linker_flags(LINK, mode, platform, device_backend):
254+
def linker_flags(LINK, mode, platform, device_backend, arch):
252255
"""Returns a list of command line flags needed by the linker"""
253256
result = []
254257

@@ -324,6 +327,7 @@ def nv_compiler_flags(mode, device_backend, arch, cdp):
324327
# the weird -gencode flag is formatted like this:
325328
# -gencode=arch=compute_10,code=\"sm_20,compute_20\"
326329
result.append('-gencode=arch={0},\\"code={1},{2}\\"'.format(virtual_arch, machine_arch, virtual_arch))
330+
327331
if mode == 'debug':
328332
# turn on debug mode
329333
# XXX make this work when we've debugged nvcc -G
@@ -435,16 +439,25 @@ for (host,device) in itertools.product(host_backends, device_backends):
435439

436440
env.Append(NVCCFLAGS = nv_compiler_flags(env['mode'], device, env['arch'], env['cdp']))
437441

438-
env.Append(LINKFLAGS = linker_flags(env.subst('$LINK'), env['mode'], env['PLATFORM'], device))
439-
440-
env.Append(LIBPATH = lib_paths(env, host, device))
441-
442442
env.Append(LIBS = libs(env, env.subst('$CXX'), host, device))
443443

444444
# XXX this probably doesn't belong here
445+
# XXX ideally we'd integrate this into site_scons
445446
if 'cudadevrt' in env['LIBS']:
446447
# nvcc is required to link against cudadevrt
447448
env.Replace(LINK = 'nvcc')
449+
450+
if os.name == 'nt':
451+
# the nv linker uses the same command line as the gnu linker
452+
env['LIBDIRPREFIX'] = '-L'
453+
env['LIBLINKPREFIX'] = '-l'
454+
env['LIBLINKSUFFIX'] = ''
455+
env.Replace(LINKCOM = '$LINK -o $TARGET $LINKFLAGS $__RPATH $SOURCES $_LIBDIRFLAGS $_LIBFLAGS')
456+
457+
# we Replace instead of Append, to avoid picking-up MSVC-specific flags on Windows
458+
env.Replace(LINKFLAGS = linker_flags(env.subst('$LINK'), env['mode'], env['PLATFORM'], device, env['arch']))
459+
460+
env.Append(LIBPATH = lib_paths(env, host, device))
448461

449462
# assemble the name of this configuration's targets directory
450463
targets_dir = 'targets/{0}_host_{1}_device_{2}'.format(host, device, env['mode'])

0 commit comments

Comments
 (0)