microsoft / microsoft/react-native-windows

View managers libraries should be able to autolink into an app's pch.h

Open
#8,256 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area: Autolinking Developer First Experience enhancement Workstream: Module Support
Dominant language
C++
Stars
17.3k
Forks
1.2k
Avg merge
1d 13h
Merged PRs (30d)
33

Description

If a view manager exposes a usercontrol or any IDL type, the xaml type info needs to be added to the consuming app's pch.h. This is standard for XAML and is a pain that developers often run into (if you don't manually add the include in the pch.h you get cryptic errors in a generated file XamlTypeInfo.g.cpp).

Proposal
  1. app template's pch.h should include a new file, AutolinkedXamlTypeInfo.g.h
  2. AutolinkedXamlTypeInfo.g.h would be generated via autolinking, inspecting the module and extracting metadata from the WinMD to determine which namespaces have any XAML-derived types. Then the contents of the AutolinkedXamlTypeInfo.g.h is simply a series of #include <winrt/NameOfTheDiscoveredNamespaces.h>

This however poses a problem, because the winmd is only generted after MIDL runs, so we need the build to autolink, but we need autolink to build. No good.

An alternate "good enough" approach, is to assume that any module's IDLs will be in the project's RootNamespace, and so we can use

#if __has_include(<winrt/TheProjectRootNamespace.h>)
#include <winrt/TheProjectRootNamespace.h>)
#endif

to include the cppwinrt-projected header for that namespace. If it has XAML types, great, we've solved the problem!
If it doesn't, it won't impact anything (since importing the header doesn't pollute the global namespace anyway).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the app template's pch.h and the build/autolinking steps around MIDL and WinMD generation. Compare the proposed AutolinkedXamlTypeInfo.g.h approach with the RootNamespace and __has_include alternative. Done means consuming apps automatically include the needed WinRT namespace header for view-manager XAML or IDL types without manual pch.h edits.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, react-native
Domain
build-system, desktop
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.