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

## 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

- [x] Closes: #49573
- [x] Closes: #49574
- [x] **Communication:** Discussed the shared UTF-8 policy with a
PowerToys collaborator in this PR
- [x] **Tests:** Existing Keyboard Manager Engine tests pass; no new
tests are needed for project-only changes
- [x] **Localization:** No end-user-facing strings are changed
- [x] **Dev docs:** No documentation changes are required for project
configuration fixes
- [x] **New binaries:** No new binaries are added
- [x] **Documentation updated:** No user documentation changes are
required

## 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.

---------

Co-authored-by: Yu Leng (from Dev Box) <yuleng@microsoft.com>
This commit is contained in:
Gavin 北稱
2026-08-05 04:10:36 -04:00
committed by GitHub
parent 6bb16d014b
commit 1703e7ac09
5 changed files with 10 additions and 8 deletions

View File

@@ -65,6 +65,7 @@
<TreatWarningAsError>true</TreatWarningAsError> <TreatWarningAsError>true</TreatWarningAsError>
<LanguageStandard>stdcpplatest</LanguageStandard> <LanguageStandard>stdcpplatest</LanguageStandard>
<BuildStlModules>false</BuildStlModules> <BuildStlModules>false</BuildStlModules>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<!-- TODO: _SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING for compatibility with VS 17.8. Check if we can remove. --> <!-- TODO: _SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING for compatibility with VS 17.8. Check if we can remove. -->
<!-- TODO: _SILENCE_EXPERIMENTAL_COROUTINE_DEPRECATION_WARNINGS for VS 2026 (MSVC 14.51+). The STL turned <!-- TODO: _SILENCE_EXPERIMENTAL_COROUTINE_DEPRECATION_WARNINGS for VS 2026 (MSVC 14.51+). The STL turned
<experimental/coroutine> into a hard error (STL1011), and C++/WinRT's base.h still falls back to it when <experimental/coroutine> into a hard error (STL1011), and C++/WinRT's base.h still falls back to it when

View File

@@ -87,22 +87,22 @@
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'"> <ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
<ClCompile> <ClCompile>
<AdditionalIncludeDirectories>./;$(SolutionDir)src\modules\;$(SolutionDir)src\modules\KeyboardManager\KeyboardManagerEditorLibrary\;$(SolutionDir)src\common\Display;$(SolutionDir)src\common\inc;$(SolutionDir)src\common\Telemetry;$(SolutionDir)src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>./;$(RepoRoot)src\modules\;$(RepoRoot)src\modules\KeyboardManager\KeyboardManagerEditorLibrary\;$(RepoRoot)src\common\Display;$(RepoRoot)src\common\inc;$(RepoRoot)src\common\Telemetry;$(RepoRoot)src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<AdditionalDependencies>Display.lib;shcore.lib;Dbghelp.lib;dwmapi.lib;uxtheme.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>Display.lib;shcore.lib;Dbghelp.lib;dwmapi.lib;uxtheme.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)$(Platform)\$(ConfigurationName);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>$(RepoRoot)$(Platform)\$(ConfigurationName);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'"> <ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
<ClCompile> <ClCompile>
<AdditionalIncludeDirectories>./;$(SolutionDir)src\modules\;$(SolutionDir)src\modules\KeyboardManager\KeyboardManagerEditorLibrary\;$(SolutionDir)src\common\Display;$(SolutionDir)src\common\inc;$(SolutionDir)src\common\Telemetry;$(SolutionDir)src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>./;$(RepoRoot)src\modules\;$(RepoRoot)src\modules\KeyboardManager\KeyboardManagerEditorLibrary\;$(RepoRoot)src\common\Display;$(RepoRoot)src\common\inc;$(RepoRoot)src\common\Telemetry;$(RepoRoot)src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>Display.lib;shcore.lib;Dbghelp.lib;dwmapi.lib;uxtheme.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>Display.lib;shcore.lib;Dbghelp.lib;dwmapi.lib;uxtheme.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)$(Platform)\$(ConfigurationName);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>$(RepoRoot)$(Platform)\$(ConfigurationName);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
@@ -167,7 +167,7 @@
</ImportGroup> </ImportGroup>
<Import Project="..\..\..\..\deps\spdlog.props" /> <Import Project="..\..\..\..\deps\spdlog.props" />
<Target Name="GenerateResourceFiles" BeforeTargets="PrepareForBuild"> <Target Name="GenerateResourceFiles" BeforeTargets="PrepareForBuild">
<Exec LogStandardErrorAsError="false" Command="powershell -NonInteractive -executionpolicy Unrestricted -NoProfile $(SolutionDir)tools\build\convert-resx-to-rc.ps1 $(MSBuildThisFileDirectory) resource.base.h resource.h KeyboardManagerEditor.base.rc KeyboardManagerEditor.rc" /> <Exec LogStandardErrorAsError="false" Command="powershell -NonInteractive -executionpolicy Unrestricted -NoProfile $(RepoRoot)tools\build\convert-resx-to-rc.ps1 $(MSBuildThisFileDirectory) resource.base.h resource.h KeyboardManagerEditor.base.rc KeyboardManagerEditor.rc" />
</Target> </Target>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup> <PropertyGroup>

View File

@@ -28,7 +28,7 @@
<ItemDefinitionGroup> <ItemDefinitionGroup>
<ClCompile> <ClCompile>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<AdditionalIncludeDirectories>./;$(SolutionDir)src\modules\;$(SolutionDir)src\common\Display;$(SolutionDir)src\common\inc;$(SolutionDir)src\common\Telemetry;$(SolutionDir)src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>./;$(RepoRoot)src\modules\;$(RepoRoot)src\common\Display;$(RepoRoot)src\common\inc;$(RepoRoot)src\common\Telemetry;$(RepoRoot)src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile> </ClCompile>
@@ -116,6 +116,6 @@
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Web.WebView2.1.0.4022.49\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Web.WebView2.1.0.4022.49\build\native\Microsoft.Web.WebView2.targets'))" /> <Error Condition="!Exists('..\..\..\..\packages\Microsoft.Web.WebView2.1.0.4022.49\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Web.WebView2.1.0.4022.49\build\native\Microsoft.Web.WebView2.targets'))" />
</Target> </Target>
<Target Name="GenerateResourceFiles" BeforeTargets="PrepareForBuild"> <Target Name="GenerateResourceFiles" BeforeTargets="PrepareForBuild">
<Exec LogStandardErrorAsError="false" Command="powershell -NonInteractive -executionpolicy Unrestricted -NoProfile $(SolutionDir)tools\build\convert-resx-to-rc.ps1 $(MSBuildThisFileDirectory)\..\KeyboardManagerEditor\ resource.base.h resource.h KeyboardManagerEditor.base.rc KeyboardManagerEditor.rc" /> <Exec LogStandardErrorAsError="false" Command="powershell -NonInteractive -executionpolicy Unrestricted -NoProfile $(RepoRoot)tools\build\convert-resx-to-rc.ps1 $(MSBuildThisFileDirectory)\..\KeyboardManagerEditor\ resource.base.h resource.h KeyboardManagerEditor.base.rc KeyboardManagerEditor.rc" />
</Target> </Target>
</Project> </Project>

View File

@@ -37,6 +37,7 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<TargetName>PowerToys.KeyboardManagerEditorLibraryWrapper</TargetName> <TargetName>PowerToys.KeyboardManagerEditorLibraryWrapper</TargetName>
<OutDir>$(RepoRoot)$(Platform)\$(Configuration)\WinUI3Apps\</OutDir>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>

View File

@@ -26,7 +26,7 @@
</ImportGroup> </ImportGroup>
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup> <PropertyGroup>
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\tests\KeyboardManagerEngine\</OutDir> <OutDir>$(RepoRoot)$(Platform)\$(Configuration)\tests\KeyboardManagerEngine\</OutDir>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup> <ItemDefinitionGroup>
<ClCompile> <ClCompile>