From c2338d112285381f430b7e584ae2da8b650ebde3 Mon Sep 17 00:00:00 2001 From: Jorijn van der Graaf Date: Wed, 11 Nov 2026 19:34:52 +0100 Subject: [PATCH] fix(cuda): rebuild a .cu when a header it includes changes A .cu was compiled again only when it was newer than its object, so one whose header changed kept the object built from the old header. The C and C++ paths ask the compiler for a depfile and check every prerequisite in it; nvcc was left out because its -MD and -MF had never been run here. They work with CUDA 13.4 as they do with clang: the depfile lists the .cu and every header it read, the toolkit's and the system's included. nvcc puts a space before the rule's colon, which NewestPrerequisite reads as a target token like any other. An object from before has no depfile and is compiled once more. --- implementations/Crafter.Build-Clang.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/implementations/Crafter.Build-Clang.cpp b/implementations/Crafter.Build-Clang.cpp index e7e04a1..254a4e5 100644 --- a/implementations/Crafter.Build-Clang.cpp +++ b/implementations/Crafter.Build-Clang.cpp @@ -1142,12 +1142,14 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map fs::last_write_time(objPath))) { + // nvcc writes the depfile clang writes for a C source (-MD -MF): the + // .cu and every header it read, the toolkit's and the system's among + // them, as a Make rule NewestPrerequisite reads as it reads clang's, + // although nvcc puts a space before the colon. Without it, a .cu + // whose header changed kept its old object. cfg.cudaArch needs no + // check: it is part of VariantId, so another one builds in another + // directory. + if (!fs::exists(objPath) || (fs::exists(srcPath) && fs::last_write_time(srcPath) > fs::last_write_time(objPath)) || NewestPrerequisite(std::format("{}.d", objPath)) > fs::last_write_time(objPath)) { const Toolchain& toolchain = GetToolchain(); if (toolchain.nvcc.empty()) { bool expected = false; @@ -1160,7 +1162,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map