Skip to content

C++/WinRT provider wrapper includes pch.h when ClCompile uses PrecompiledHeader=NotUsing #30

Open
microsoft/cppwinrt
#1626

Description

@hoshiizumiya

Current disposition (2026-10-14)

The XamlC source has been prepared for upstream review, but this remains a C++/WinRT-owned provider-wrapper report. Integrated x64/PCH-free consumers passed using the scoped package mitigation in run 38447022302, and the external package sample passed in run 38565042317. These are workaround evidence, not a verified fix to Microsoft's provider package. Keep this external defect open; do not fold provider-generation ownership into XamlC.

Historical diagnosis and evidence

Current disposition (2026-10-01)

Remains an external C++/WinRT provider-wrapper defect. Fork module fixtures/sample pin CppWinRTPlus; the product dependency/defaults stay upstream-aligned. Run 36811821254 passed the native PCH-free/module/header chain with that mitigation. Rebased verification is #40. No fix in Microsoft's provider package is established, so this issue stays open for microsoft/cppwinrt disposition.


Historical diagnosis and development evidence

The material below records earlier commits and runs. Its checkpoint statuses, source counts and pending items are historical; use the current disposition above for the rebased branches.

Scope/status: newly verified C++/WinRT MSBuild integration defect. The failure was exposed by WinUI's PCH-free module regression. The emitting target is also present in current C++/WinRT upstream source. The Microsoft package remains affected; the WinUI validation dependency now uses CppWinRTPlus, with Windows CI now confirming the PCH-free compile/link path.

Suggested upstream destination: microsoft/cppwinrt. Track the WinUI integration/reproduction here; do not attribute this wrapper emission to the XamlC Page/App templates.

First real error

PR Build 36665332238 / job 109742675435, head f6d7989fd921233f1d23a2214e5e8aeb6441eae4, passed all six product builds, successfully executed CreateWinMD, then failed in CompileXamlGeneratedFiles:

XamlMetaDataProvider.cpp(2,10): error C1083:
Cannot open include file: 'pch.h': No such file or directory

This differs from the earlier authored smoke's C1010 PCH compile-option error.

Exact emitter and causal evidence

The imported Microsoft.Windows.CppWinRT.3.0.260818.1/build/native/Microsoft.Windows.CppWinRT.targets is embedded in the workflow's binlogs-cppwinrt-modules artifact. Target CppWinRTAddXamlMetaDataProviderCpp contains:

<_PCH>@(ClCompile->Metadata('PrecompiledHeaderFile')->Distinct())</_PCH>
<XamlMetaDataProviderPch Condition="'$(_PCH)'!=''">#include "$(_PCH)"</XamlMetaDataProviderPch>

The target writes a wrapper whose body includes:

// This file is generated by the build to support Xaml apps
#include "pch.h"
#include "XamlMetaDataProvider.h"
#include "XamlMetaDataProvider.g.cpp"

The binlog contains both the property expansion and these generated wrapper lines. The target aggregates the filename metadata from all ClCompile items without testing whether those items use PCH. A default filename such as pch.h therefore counts even when PrecompiledHeader=NotUsing.

The same target exists in pinned upstream C++/WinRT source, revision 856eaff70a48d6b053c2ad3dffec15b81ca34b10.

SimpleCppWinRTModules.vcxproj sets PrecompiledHeader=NotUsing and has no pch.h/pch.cpp. Component projection's -pch . handling does not fix this separate wrapper-emission target.

Important ownership distinction

The failing file is the C++/WinRT-generated wrapper XamlMetaDataProvider.cpp. It textually includes the component-generated XamlMetaDataProvider.g.cpp.

XamlC's CppWinRT_XamlMetaDataProviderPass2.tt separately consumes its scalar PrecompiledHeaderFile input. WinUI's GetPrecompiledHeaderFile is related PCH-selection code, but neither is established as the emitter of this failing wrapper. Clearing only XamlC's scalar input would leave the C++/WinRT target's full item-metadata aggregation unchanged.

Reproduction

Use a C++/WinRT XAML project with the provider IDL/CPP generation path enabled, all authored sources using PrecompiledHeader=NotUsing, the normal default PrecompiledHeaderFile filename still present in item metadata, and no physical PCH header.

Run the failing fixture at the cited head, or invoke the provider-wrapper target in such a project. Inspect _PCH, XamlMetaDataProviderPch and XamlMetaDataProviderCppLines. The real native failure is established on VS2026/v145/SDK26100/x64 Debug; identical header-mode execution is an additional validation case, not claimed as already run.

Expected behavior and acceptance

Select a provider PCH from items that actually use one; a filename alone must not enable a textual include. Preserve PCH-enabled projects and ensure disabling PCH removes stale wrapper includes, including when a prior target invocation set the helper property.

Validate clean PCH-free, normal PCH-enabled, and incremental PCH-enabled → disabled builds. Consider multiple item groups with different PCH-use metadata. Do not restore dummy pch.h, inject a preamble or special-case the fixture.

Tracking/index: #3. Authored fixture cleanup: #27. Related WinUI module integration: microsoft#11524. The run clears the Store/Spectre blocker in #6 but has not accepted the full regression chain.

Integration mitigation: CppWinRTPlus

31443d2 switches the three module regression projects and repo-local sample to YexuanXiao.CppWinRTPlus 3.1.260928.1. Package manifests, native imports and focused restore now agree on that package; the product dependency is unchanged.

The actual published NuGet archive's build/native/YexuanXiao.CppWinRTPlus.targets contains:

<_PCH Condition="'%(CLCompile.PrecompiledHeader)' != 'NotUsing'">@(ClCompile->Metadata('PrecompiledHeaderFile')->Distinct())</_PCH>

CppWinRTPlus source at c14749f contains the same guard. This addresses the observed all-NotUsing selection mechanism. Package inspection is verified. Run 36676884870 also compiled the PCH-free provider wrapper and linked SimpleModules. The mixed-PCH/incremental acceptance cases above are not yet verified. Keep this report open for the original Microsoft package defect.

Validation run for this package-switch head: PR Build 36676884870, started at 31443d231e1642dd8fb8a442c434706ae5cfe359. It completed: late generated compilation and SimpleModules linking succeeded, then AppX recipe validation failed with APPX0703 (#31). No end-to-end acceptance is claimed.

The next owning-layer failure is #31, an omitted local runtime-copy opt-in. f3f1cd3 enables that existing build configuration; follow-up run 36685051922 is in progress. Keep this C++/WinRT report separate from the packaging configuration fix.

Activity

  1. changed the title [-]PCH-free XamlC builds still generate an include of pch.h in XamlMetaDataProvider.cpp[/-] [+]C++/WinRT provider wrapper includes pch.h when ClCompile uses PrecompiledHeader=NotUsing[/+] on Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions