Fixes #1619.
<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
xmlns:asmv3="urn:schemas-microsoft-com:asm.v3"
xmlns:ws2016="http://schemas.microsoft.com/SMI/2016/WindowsSettings"
+ xmlns:ws2019="http://schemas.microsoft.com/SMI/2019/WindowsSettings"
manifestVersion="1.0">
<asmv3:application>
<asmv3:windowsSettings>
<ws2016:longPathAware>true</ws2016:longPathAware>
+ <ws2019:activeCodePage>UTF-8</ws2019:activeCodePage>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
// compilers that don't exit with a proper status on write error to stdout.
// See also <https://github.com/llvm/llvm-project/issues/56499>.
if (ctx.config.is_compiler_group_msvc()) {
+ args.push_back("-utf-8"); // Avoid garbling filenames in output
args.push_back("-P");
args.push_back(FMT("-Fi{}", preprocessed_path));
} else {
cpp_stderr_data = result->stderr_data;
cpp_stdout_data = result->stdout_data;
+
+ if (ctx.config.is_compiler_group_msvc()) {
+ // Check that usage of -utf-8 didn't garble the preprocessor output.
+ static constexpr char warning_c4828[] =
+ "warning C4828: The file contains a character starting at offset";
+ if (util::to_string_view(cpp_stderr_data).find(warning_c4828)
+ != std::string_view::npos) {
+ LOG_RAW("Non-UTF-8 source code unsupported in preprocessor mode");
+ return tl::unexpected(Statistic::unsupported_source_encoding);
+ }
+ }
}
if (is_clang_cu) {
-// Copyright (C) 2021-2024 Joel Rosdahl and other contributors
+// Copyright (C) 2021-2025 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
disabled = 81,
bad_input_file = 82,
modified_input_file = 83,
- END = 84
+ unsupported_source_encoding = 84,
+
+ END = 85,
};
enum class StatisticsFormat {
"Unsupported environment variable",
FLAG_UNCACHEABLE),
+ // Source file (or an included header) has unsupported encoding. ccache
+ // currently requires UTF-8-encoded source code for MSVC.
+ FIELD(unsupported_source_encoding,
+ "Unsupported source encoding",
+ FLAG_UNCACHEABLE),
+
// A source language e.g. specified with -x was unsupported by ccache.
FIELD(unsupported_source_language,
"Unsupported source language",