Skip to content

Commit

Permalink
Start prototype with TODOs on supporting build-time/runtime-startup s…
Browse files Browse the repository at this point in the history
…elected WUX vs MUX mode.

Implement the base TODO-WuxMux items that must be completed to support a runtime configuration WUX/MUX switch.

Add WUX test projection and fix bug with ICommand special-casing.

Inline MUX guids.

Add CsWinRT SDK support

Add tests for authoring components with WUX APIs (also validates some of the consumption logic in the process)

Remove Debug.Breaks

Change approach so WUX/MUX works for delegates

Use Xaml Islands and a custom main to enable writing GTest tests with INPC and types that need the XAML engine initialized on the thread.

Add AuthoringWuxComsumptionTest to the CI

Change IIDOptimizer to fall back to GuidGenerator for WUX/MUX types.

Fix IList ABI type to implement WUX and MUX

Add breaks

PR feedback and fix unit test failures.

Fix configurations for new projects.

Fix configuration for Windows.UI.Xaml projection
  • Loading branch information
jkoritzinsky committed Jan 18, 2024
1 parent 0e1d586 commit 21b99e5
Show file tree
Hide file tree
Showing 61 changed files with 5,957 additions and 1,813 deletions.
12 changes: 12 additions & 0 deletions build/AzurePipelineTemplates/CsWinRT-BuildAndTest-Stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ stages:
script: |
dir _build\$(BuildPlatform)\$(BuildConfiguration)\AuthoringConsumptionTest\bin
_build\$(BuildPlatform)\$(BuildConfiguration)\AuthoringConsumptionTest\bin\AuthoringConsumptionTest.exe --gtest_output=xml:AUTHORINGTEST-$(Build.BuildNumber).xml
exit /b 0
# Run WUX Tests
- task: CmdLine@2
displayName: Run WUX Tests
condition: and(succeeded(), or(eq(variables['BuildPlatform'], 'x86'), eq(variables['BuildPlatform'], 'x64')))
continueOnError: True
inputs:
workingDirectory: $(Build.SourcesDirectory)\src
script: |
dir _build\$(BuildPlatform)\$(BuildConfiguration)\AuthoringWuxConsumptionTest\bin
_build\$(BuildPlatform)\$(BuildConfiguration)\AuthoringWuxConsumptionTest\bin\AuthoringWuxConsumptionTest.exe --gtest_output=xml:AUTHORINGWUXTEST-$(Build.BuildNumber).xml
exit /b 0
# Run Functional Tests
Expand Down
1 change: 1 addition & 0 deletions nuget/Microsoft.Windows.CsWinRT.Authoring.targets
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<CompilerVisibleProperty Include="CsWinRTWindowsMetadata" />
<CompilerVisibleProperty Include="CsWinRTGenerateProjection" />
<CompilerVisibleProperty Include="CsWinRTAuthoringInputs" />
<CompilerVisibleProperty Include="CsWinRTUiXamlMode" />
</ItemGroup>

<!-- Note this runs before the msbuild editor config file is generated because that is what is used to pass properties to the source generator. -->
Expand Down
7 changes: 7 additions & 0 deletions nuget/Microsoft.Windows.CsWinRT.targets
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ $(CsWinRTInternalProjection)
</ItemGroup>
</Target>

<ItemGroup>
<RuntimeHostConfigurationOption Include="CsWinRT.UiXamlMode" Condition="'$(CsWinRTUiXamlMode)' != ''">
<Value>$(CsWinRTUiXamlMode)</Value>
<Trim>true</Trim>
</RuntimeHostConfigurationOption>
</ItemGroup>

<Import Project="$(MSBuildThisFileDirectory)Microsoft.Windows.CsWinRT.Prerelease.targets" Condition="Exists('$(MSBuildThisFileDirectory)Microsoft.Windows.CsWinRT.Prerelease.targets')"/>
<Import Project="$(MSBuildThisFileDirectory)Microsoft.Windows.CsWinRT.Authoring.targets" Condition="'$(CsWinRTComponent)' == 'true'"/>
<Import Project="$(MSBuildThisFileDirectory)Microsoft.Windows.CsWinRT.IIDOptimizer.targets" Condition="'$(CsWinRTIIDOptimizerOptOut)' != 'true'"/>
Expand Down
103 changes: 57 additions & 46 deletions src/Authoring/WinRT.SourceGenerator/AotOptimizer.cs

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions src/Authoring/WinRT.SourceGenerator/DiagnosticUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ public WinRTComponentScanner(GeneratorExecutionContext context, string assemblyN
_assemblyName = assemblyName;
_context = context;
_flag = false;
_typeMapper = new TypeMapper(context.AnalyzerConfigOptions.GlobalOptions.GetUiXamlMode());
}

private readonly string _assemblyName;
private readonly GeneratorExecutionContext _context;
private bool _flag;
private readonly TypeMapper _typeMapper;

public bool Found() { return _flag; }

Expand Down Expand Up @@ -105,7 +107,7 @@ private void CheckDeclarations()
var props = @class.DescendantNodes().OfType<PropertyDeclarationSyntax>().Where(IsPublic);

// filter out methods and properties that will be replaced with our custom type mappings
IgnoreCustomTypeMappings(classSymbol, ref publicMethods, ref props);
IgnoreCustomTypeMappings(classSymbol, _typeMapper, ref publicMethods, ref props);

if (!classSymbol.IsSealed && !classSymbol.IsStatic)
{
Expand Down Expand Up @@ -137,7 +139,7 @@ private void CheckDeclarations()
var props = @interface.DescendantNodes().OfType<PropertyDeclarationSyntax>().Where(IsPublic);

// filter out methods and properties that will be replaced with our custom type mappings
IgnoreCustomTypeMappings(interfaceSym, ref methods, ref props);
IgnoreCustomTypeMappings(interfaceSym, _typeMapper, ref methods, ref props);

if (interfaceSym.IsGenericType)
{
Expand Down Expand Up @@ -206,6 +208,7 @@ private bool IsMethodImpl(IMethodSymbol m, IMethodSymbol interfaceMethod)
}

private void IgnoreCustomTypeMappings(INamedTypeSymbol typeSymbol,
TypeMapper typeMapper,
ref IEnumerable<MethodDeclarationSyntax> methods,
ref IEnumerable<PropertyDeclarationSyntax> properties)
{
Expand All @@ -217,7 +220,7 @@ string QualifiedName(INamedTypeSymbol sym)
HashSet<ISymbol> classMethods = new();

foreach (var @interface in typeSymbol.AllInterfaces.
Where(symbol => GeneratorHelper.MappedCSharpTypes.ContainsKey(QualifiedName(symbol)) ||
Where(symbol => typeMapper.HasMappingForType(QualifiedName(symbol)) ||
WinRTTypeWriter.ImplementedInterfacesWithoutMapping.Contains(QualifiedName(symbol))))
{
foreach (var interfaceMember in @interface.GetMembers())
Expand Down
8 changes: 6 additions & 2 deletions src/Authoring/WinRT.SourceGenerator/Generator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
Expand All @@ -20,11 +20,14 @@ public class ComponentGenerator
private Logger Logger { get; }
private readonly GeneratorExecutionContext context;
private string tempFolder;
private readonly TypeMapper mapper;

public ComponentGenerator(GeneratorExecutionContext context)
{
this.context = context;
Logger = new Logger(context);
mapper = new(context.AnalyzerConfigOptions.GlobalOptions.GetUiXamlMode());
// TODO-WuxMux: output a module initializer that validates the MUX/WUX projection mode to ensure that things don't get out of sync.
}

private string GetTempFolder(bool clearSourceFilesFromFolder = false)
Expand Down Expand Up @@ -152,7 +155,8 @@ public void Generate()
assembly,
version,
metadataBuilder,
Logger);
Logger,
mapper);

WinRTSyntaxReceiver syntaxReceiver = (WinRTSyntaxReceiver)context.SyntaxReceiver;
Logger.Log("Found " + syntaxReceiver.Declarations.Count + " types");
Expand Down
Loading

0 comments on commit 21b99e5

Please sign in to comment.