Skip to content

Ninja: Write msvc_deps_prefix as UTF-8 when console codepage is UTF-8

Ninja has an issue where it fails to track dependencies from MSVC in international languages. In short, the issue that when Visual Studio runs cl.exe with the console code page set to 65001 (UTF-8) to support international languages, the result of /showIncludes will also be UTF-8 encoded. Ninja build files, however, are always ANSI encoded on Windows, so it becomes impossible if the ANSI code page is not equal to the console code page to correctly specify the msvc_deps_prefix (if certain characters are used).

There's a solution in-progress to Ninja to add support for the new MSVC /sourceDependencies JSON format which will resolve this issue, but it's unclear when the project maintainers will merge the PR and Microsoft would like to have a fix available sooner if possible.

The solution in this merge request only requires changes in CMake is to produce Ninja files that are almost entirely ANSI encoded, but encode the msvc_deps_prefix as UTF-8. Ninja will happily consume such a file and successfully do a byte-by-byte comparison between the UTF-8 msvc_deps_prefix and the UTF-8 result of /showIncludes.

Topic-rename: ninja-msvc-deps-prefix

Edited by Brad King

Merge request reports