|
| 1 | +# C++/WinRT Codebase — Agent Instructions |
| 2 | + |
| 3 | +## Repository Structure |
| 4 | + |
| 5 | +- `cppwinrt/` — The cppwinrt.exe code generator (C++ source) |
| 6 | + - `main.cpp` — CLI parsing, namespace iteration, SCC detection, .ixx orchestration |
| 7 | + - `file_writers.h` — All file generation functions (headers, .ixx modules, component stubs) |
| 8 | + - `code_writers.h` — Code-level writing utilities (guards, namespace wrappers, type writers) |
| 9 | + - `type_writers.h` — Type formatting (ABI signatures, names, GUIDs) |
| 10 | + - `component_writers.h` — Component authoring code generation |
| 11 | + - `helpers.h` — Metadata reading helpers |
| 12 | + - `settings.h` — Global settings populated from CLI args |
| 13 | + - `text_writer.h` — Core text writer infrastructure |
| 14 | +- `strings/` — String literal `.h` files embedded by the prebuild step. Changes require: delete prebuild.exe → rebuild solution |
| 15 | +- `nuget/` — MSBuild targets, props, and NuGet packaging |
| 16 | + - `Microsoft.Windows.CppWinRT.targets` — Main MSBuild integration (projections, module support) |
| 17 | +- `test/` — Test projects |
| 18 | + - `test/test_cpp20_module/` — Standalone module test (in main solution) |
| 19 | + - `test/nuget/` — NuGet integration tests (multi-project module chain) |
| 20 | +- `docs/` — Documentation |
| 21 | +- `natvis/` — Visual Studio debug visualizer (includes strings/*.h in its pch.h — add new files there too) |
| 22 | + |
| 23 | +## Build Process |
| 24 | + |
| 25 | +- Use VS Developer Shell for correct toolset environment |
| 26 | +- `cmake --build build --config Release --target cppwinrt` for cppwinrt.exe (or MSBuild: `msbuild cppwinrt\cppwinrt.vcxproj /p:Configuration=Release /p:Platform=x64`) |
| 27 | +- NuGet tests: `msbuild test\nuget\NuGetTest.sln /p:Configuration=Release /p:Platform=x64` |
| 28 | +- Module test projects require v145 toolset (VS 2026). Directory.Build.Props sets v143 by default — override with `<PlatformToolset>v145</PlatformToolset>` in Configuration PropertyGroup |
| 29 | + |
| 30 | +## Key Patterns |
| 31 | + |
| 32 | +### Prebuild Embedding |
| 33 | +The `strings/*.h` files are embedded as string literals by the prebuild step. If you modify any `strings/*.h` file, you must delete `prebuild.exe` and rebuild the entire solution for changes to take effect. |
| 34 | + |
| 35 | +### Module Guard Macros |
| 36 | +- `WINRT_IMPL_BUILD_MODULE` — Defined in .ixx global fragment. Makes `WINRT_EXPORT` expand to `export extern "C++"` and suppresses `#include` of dependencies |
| 37 | +- `WINRT_IMPORT_MODULE` — Defined by consumers who import modules. Makes namespace headers and base.h no-op (types come from module import) |
| 38 | +- `WINRT_EXPORT` — Empty in header mode, `export extern "C++"` in module mode. Defined in `winrt/base_macros.h` |
| 39 | +- `WINRT_IMPL_STD_EXPORT` — Empty in header mode, `extern "C++"` (without export) in module mode. Used for `namespace std` specializations |
| 40 | + |
| 41 | +### Generated Header Structure |
| 42 | +Each namespace produces four header files: |
| 43 | +- `impl/<ns>.0.h` — Forward declarations, ABIs, GUIDs, categories |
| 44 | +- `impl/<ns>.1.h` — Interface definitions |
| 45 | +- `impl/<ns>.2.h` — Delegates, structs, class implementations |
| 46 | +- `<ns>.h` — Public API surface (consume definitions, class wrappers, operators) |
| 47 | + |
| 48 | +### Dependency Collection |
| 49 | +When generating headers with `-modules`, writer.depends is inspected after each header to build a namespace dependency graph. This graph drives SCC detection and module import lists. |
| 50 | + |
| 51 | +## Common Gotchas |
| 52 | + |
| 53 | +- Module IFCs are NOT compatible across toolset versions — always clean rebuild when switching |
| 54 | +- PCH and modules can coexist but PCH should NOT include winrt headers when using modules |
| 55 | +- `/ifcSearchDir` works for the module dependency scanner to find IFCs, but cross-component modules may need explicit `/reference "name=path.ifc"` flags |
| 56 | +- `import std;` requires `BuildStlModules=true` |
| 57 | +- `strings/base_macros.h` is the single source of truth for shared macros (generated as `winrt/base_macros.h`). New macros go in `base_macros.h` only |
| 58 | +- When adding, removing, or heavily refactoring `strings/*.h` files, always rebuild the natvis project (`natvis/cppwinrtvisualizer.sln`) to verify — it includes strings/*.h directly in its pch.h |
0 commit comments