From b08165b40cb4e4ebdfa534b919d616fe8cc64086 Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Sun, 21 Dec 2025 17:07:37 +0100 Subject: [PATCH] fix: Handle NVCC long option alternatives to -M/-MD/-MF/-MM/-MMD/-MT Fixes #1663. --- src/ccache/argprocessing.cpp | 27 ++++++++++++++++++++------- src/ccache/ccache.cpp | 35 +++++++++++++++-------------------- src/ccache/compopt.cpp | 4 ++++ 3 files changed, 39 insertions(+), 27 deletions(-) diff --git a/src/ccache/argprocessing.cpp b/src/ccache/argprocessing.cpp index de6ece91..7d1f83cc 100644 --- a/src/ccache/argprocessing.cpp +++ b/src/ccache/argprocessing.cpp @@ -818,18 +818,26 @@ process_option_arg(const Context& ctx, // These options require special handling, because they behave differently // with gcc -E, when the output file is not specified. - if ((arg == "-MD" || arg == "-MMD") && !config.is_compiler_group_msvc()) { + if (!config.is_compiler_group_msvc() + && (arg == "-MD" + || arg == "-MMD" + // nvcc -MD: + || arg == "--generate-dependencies-with-compile" + // nvcc -MMD: + || arg == "--generate-nonsystem-dependencies-with-compile")) { state.found_md_or_mmd_opt = true; args_info.generating_dependencies = true; state.add_compiler_only_arg(args[i]); return Statistic::none; } - if (util::starts_with(arg, "-MF")) { + if (util::starts_with(arg, "-MF") + // nvcc -MF: + || arg == "--dependency-output") { state.found_mf_opt = true; std::string dep_file; - bool separate_argument = (arg.size() == 3); + bool separate_argument = (arg.size() == 3 || arg == "--dependency-output"); if (separate_argument) { // -MF arg if (i == args.size() - 1) { @@ -857,12 +865,15 @@ process_option_arg(const Context& ctx, return Statistic::none; } - if ((util::starts_with(arg, "-MQ") || util::starts_with(arg, "-MT")) - && !config.is_compiler_group_msvc()) { + if (!config.is_compiler_group_msvc() + && (util::starts_with(arg, "-MQ") + || util::starts_with(arg, "-MT") + // nvcc -MT: + || arg == "--dependency-target-name")) { const bool is_mq = arg[2] == 'Q'; std::string_view dep_target; - if (arg.size() == 3) { + if (arg.size() == 3 || arg == "--dependency-target-name") { // -MQ arg or -MT arg if (i == args.size() - 1) { LOG("Missing argument to {}", args[i]); @@ -1067,7 +1078,9 @@ process_option_arg(const Context& ctx, return Statistic::none; } - if (arg == "-MP") { + if (arg == "-MP" + // nvcc -MP: + || arg == "--generate-dependency-targets") { state.add_compiler_only_arg(args[i]); return Statistic::none; } diff --git a/src/ccache/ccache.cpp b/src/ccache/ccache.cpp index 7aa40c65..41324251 100644 --- a/src/ccache/ccache.cpp +++ b/src/ccache/ccache.cpp @@ -2254,9 +2254,6 @@ hash_argument(const Context& ctx, } if (ctx.args_info.generating_dependencies) { - std::optional option; - std::optional value; - if (util::starts_with(args[i], "-Wp,")) { // Skip the dependency filename since it doesn't impact the output. if (util::starts_with(args[i], "-Wp,-MD,") @@ -2268,23 +2265,21 @@ hash_argument(const Context& ctx, hash.hash(args[i].data(), 9); return {}; } - } else if (std::tie(option, value) = get_option_and_value("-MF", args, i); - option) { - // Skip the dependency filename since it doesn't impact the output. - hash.hash(*option); - return {}; - } else if (std::tie(option, value) = get_option_and_value("-MQ", args, i); - option) { - hash.hash(*option); - // No need to hash the dependency target since we always calculate it on - // a cache hit. - return {}; - } else if (std::tie(option, value) = get_option_and_value("-MT", args, i); - option) { - hash.hash(*option); - // No need to hash the dependency target since we always calculate it on - // a cache hit. - return {}; + } else { + static std::array skip_options = { + "-MF", // dependency filename doesn't impact the output + "-MQ", // dependency target is calculated on cache hit + "-MT", // dependency target is calculated on cache hit + "--dependency-output", // nvcc version of -MF + "--dependency-target-name", // nvcc version of -MT + }; + for (auto opt : skip_options) { + if (const auto [option, _value] = get_option_and_value(opt, args, i); + option) { + hash.hash(*option); + return {}; + } + } } } diff --git a/src/ccache/compopt.cpp b/src/ccache/compopt.cpp index 81c42170..8db5fea9 100644 --- a/src/ccache/compopt.cpp +++ b/src/ccache/compopt.cpp @@ -49,6 +49,7 @@ struct CompOpt int type; }; +// clang-format off const CompOpt compopts[] = { {"--Werror", TAKES_ARG | AFFECTS_COMP }, // nvcc {"--analyzer-output", TOO_HARD }, // Clang @@ -57,6 +58,8 @@ const CompOpt compopts[] = { {"--config", TAKES_ARG }, // Clang {"--em-config", TAKES_ARG }, // emcc {"--gcc-toolchain=", TAKES_CONCAT_ARG | TAKES_PATH }, // Clang + {"--generate-dependencies", TOO_HARD }, // nvcc (-M) + {"--generate-nonsystem-dependencies", TOO_HARD }, // nvcc (-MM) {"--include", AFFECTS_CPP | TAKES_ARG | TAKES_CONCAT_ARG | TAKES_PATH}, {"--libdevice-directory", AFFECTS_CPP | TAKES_ARG }, // nvcc {"--offload-compress", AFFECTS_COMP }, // Clang @@ -177,6 +180,7 @@ const CompOpt compopts[] = { {"-wrapper", TAKES_ARG | TOO_HARD }, {"-z", TAKES_ARG | TAKES_CONCAT_ARG | AFFECTS_COMP }, }; +// clang-format on static int compare_compopts(const void* key1, const void* key2) -- 2.47.3