Skip to content

[Build] Fix UTF-8 and output paths for local C++ builds - #49575

Open
gavinzhangth wants to merge 2 commits into
microsoft:mainfrom
gavinzhangth:fix/local-build-reliability
Open

[Build] Fix UTF-8 and output paths for local C++ builds#49575
gavinzhangth wants to merge 2 commits into
microsoft:mainfrom
gavinzhangth:fix/local-build-reliability

Conversation

@gavinzhangth

@gavinzhangth gavinzhangth commented Jul 29, 2026

Copy link
Copy Markdown

Summary of the Pull Request

Fixes two local C++ build reliability problems:

  • Compiles all PowerToys C++ projects as UTF-8 through Cpp.Build.props, so builds do not depend on the active Windows code page. On code page 936, UTF-8 punctuation in BOM-less source files otherwise triggers C4819 and fails the build because warnings are treated as errors.
  • Uses $(RepoRoot) for Keyboard Manager repository paths and standardizes native/test output directories. This makes direct project builds find the resource conversion script and headers, places the Editor wrapper beside the WinUI app, and keeps the Engine test DLL under the repository test output directory.

No runtime logic, end-user strings, dependencies, or binaries are added.

PR Checklist

Detailed Description of the Pull Request / Additional comments

Directory.Build.props imports Cpp.Build.props for C++ projects. Defining /utf-8 %(AdditionalOptions) in its shared ClCompile settings makes source decoding deterministic across the native codebase and prevents future BOM-less UTF-8 source files from reintroducing the same locale-dependent failure. /utf-8 explicitly sets both the source and execution character sets instead of suppressing C4819 or replacing valid Unicode text.

$(SolutionDir) is only reliable when MSBuild is invoked through a solution. The repository's local build script builds .vcxproj files directly from their project directories, where $(RepoRoot) is the stable repository root property. The wrapper output now follows the existing $(RepoRoot)$(Platform)\$(Configuration)\WinUI3Apps\ pattern used by other native WinUI dependencies.

Validation Steps Performed

All successful builds used the repository build scripts with -Platform x64 -Configuration Debug.

  • Ran tools/build/build-essentials.cmd: solution restore, Runner, and Settings all succeeded with empty errors logs.
  • Built FancyZonesLib successfully after it had failed with a resource-related CL exit during a full parallel build.
  • Built WorkspacesModuleInterface successfully, validating that existing UTF-16 BOM headers remain compatible with the shared option.
  • Built ZoomItBreak and ZoomIt successfully.
  • Built KeyboardManagerEngineTest successfully.
  • Built KeyboardManagerEditor and KeyboardManagerEditorUI successfully after the documented essentials prerequisite.
  • Confirmed the successful native build logs contain /utf-8 compiler invocations and all corresponding build.debug.x64.errors.log files are empty.
  • Ran vstest.console.exe against the Keyboard Manager Engine test assembly: 103/103 passed.
  • Confirmed PowerToys.KeyboardManagerEditorLibraryWrapper.dll is emitted to x64/Debug/WinUI3Apps.
  • Confirmed KeyboardManager.Engine.UnitTests.dll is emitted to x64/Debug/tests/KeyboardManagerEngine.
  • Previously manually verified the x64 Debug PowerToys build can open Keyboard Manager Editor without 0x8007007E.

A full PowerToys.slnx x64 Debug build was attempted twice. The first attempt exhausted the remaining 62 MB of disk space. After clearing 52.46 GB of ignored build outputs, the second attempt still exceeded the machine's temporary disk/commit limits (CL.exe exit 0xC000012D and an out-of-space cppwinrt write). Before that resource failure, the log contained 4,642 /utf-8 command entries and no character-set diagnostics. The full configuration matrix is left to PR CI rather than bypassing normal build settings locally.

Compile ZoomIt and Keyboard Manager engine projects as UTF-8 so builds do not depend on the active Windows code page. Use RepoRoot-based paths and standard output directories for direct Keyboard Manager project builds.
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@daverayment

Copy link
Copy Markdown
Collaborator

The CP 936 issue is a good catch. cl.exe will use the current code page if it's not given /utf-8.

Is it better to add /utf-8 %(AdditionalOptions) to Cpp.build.props instead of to individual .vcxproj files? It would apply to every C++ project and mean we don't have to worry about the other projects potentially introducing incompatible characters in the future.

I don't know enough about the intricacies of the build to comment on the RepoRoot versus SolutionRoot issue, so I'll leave that for someone with a bigger brain.

@gavinzhangth

Copy link
Copy Markdown
Author

Thanks, agreed. I moved /utf-8 %(AdditionalOptions) to the shared Cpp.Build.props in 81d6b99 and removed the four project-level copies. I validated the shared setting with build-essentials plus FancyZonesLib, WorkspacesModuleInterface, ZoomIt/ZoomItBreak, and the Keyboard Manager projects; the successful native logs inherit /utf-8 and have empty errors logs. Keyboard Manager Engine tests pass 103/103. I also documented the full-solution attempts and their local disk/commit resource limits in the PR description rather than changing normal build settings to work around them. The RepoRoot/output-path changes are unchanged.

@moooyo

moooyo commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

<Error Condition="!Exists('$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.targets'))" />
</Target>
</Project> No newline at end of file
</Project>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the addtional line

@moooyo

moooyo commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Looks good overall

@moooyo moooyo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Keyboard Manager] Direct project builds use incorrect root and output paths [Build] C++ projects fail with C4819 on code page 936

3 participants