aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/backend
diff options
context:
space:
mode:
authorwrvsrx <wrvsrx@outlook.com>2023-12-24 20:47:13 +0800
committerEli Schwartz <eschwartz93@gmail.com>2023-12-26 23:37:27 -0500
commitd4fb2d693d01bc65790140a6ebb9221f0f1ed7dc (patch)
tree11af8025a38c3611adaee343d5fa6b3aaaef2b81 /mesonbuild/backend
parente2458c6f943ad9f3640036a0c48497759edee585 (diff)
downloadmeson-d4fb2d693d01bc65790140a6ebb9221f0f1ed7dc.zip
meson-d4fb2d693d01bc65790140a6ebb9221f0f1ed7dc.tar.gz
meson-d4fb2d693d01bc65790140a6ebb9221f0f1ed7dc.tar.bz2
ninja backend: manually escape cuda target name
Nvcc doesn't support `-MQ` flag, so we have to manually escape cuda target name. This commit escape `$out` to `$CUDA_ESCAPED_TARGET`, so now we can just use `-MT` flag in nvcc to generate header dependencies.
Diffstat (limited to 'mesonbuild/backend')
-rw-r--r--mesonbuild/backend/ninjabackend.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index d675882..9acc39c 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -2448,7 +2448,11 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
# See also: https://github.com/ninja-build/ninja/pull/2275
options['extra'] = 'restat = 1'
rule = self.compiler_to_rule_name(compiler)
- depargs = NinjaCommandArg.list(compiler.get_dependency_gen_args('$out', '$DEPFILE'), Quoting.none)
+ if langname == 'cuda':
+ # for cuda, we manually escape target name ($out) as $CUDA_ESCAPED_TARGET because nvcc doesn't support `-MQ` flag
+ depargs = NinjaCommandArg.list(compiler.get_dependency_gen_args('$CUDA_ESCAPED_TARGET', '$DEPFILE'), Quoting.none)
+ else:
+ depargs = NinjaCommandArg.list(compiler.get_dependency_gen_args('$out', '$DEPFILE'), Quoting.none)
command = compiler.get_exelist()
args = ['$ARGS'] + depargs + NinjaCommandArg.list(compiler.get_output_args('$out'), Quoting.none) + compiler.get_compile_only_args() + ['$in']
description = f'Compiling {compiler.get_display_language()} object $out'
@@ -3003,6 +3007,28 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
element.add_orderdep(i)
if dep_file:
element.add_item('DEPFILE', dep_file)
+ if compiler.get_language() == 'cuda':
+ # for cuda, we manually escape target name ($out) as $CUDA_ESCAPED_TARGET because nvcc doesn't support `-MQ` flag
+ def quote_make_target(targetName: str) -> str:
+ # this escape implementation is taken from llvm
+ result = ''
+ for (i, c) in enumerate(targetName):
+ if c in {' ', '\t'}:
+ # Escape the preceding backslashes
+ for j in range(i - 1, -1, -1):
+ if targetName[j] == '\\':
+ result += '\\'
+ else:
+ break
+ # Escape the space/tab
+ result += '\\'
+ elif c == '$':
+ result += '$'
+ elif c == '#':
+ result += '\\'
+ result += c
+ return result
+ element.add_item('CUDA_ESCAPED_TARGET', quote_make_target(rel_obj))
element.add_item('ARGS', commands)
self.add_dependency_scanner_entries_to_element(target, compiler, element, src)