Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify WUX feature switch property #1658

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nuget/Microsoft.Windows.CsWinRT.Authoring.targets
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<CompilerVisibleProperty Include="CsWinRTWindowsMetadata" />
<CompilerVisibleProperty Include="CsWinRTGenerateProjection" />
<CompilerVisibleProperty Include="CsWinRTAuthoringInputs" />
<CompilerVisibleProperty Include="CsWinRTUIXamlProjections" />
<CompilerVisibleProperty Include="CsWinRTUseWindowsUIXamlProjections" />
</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
14 changes: 5 additions & 9 deletions nuget/Microsoft.Windows.CsWinRT.targets
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ $(CsWinRTInternalProjection)
<CsWinRTEnableICustomPropertyProviderSupport Condition="'$(CsWinRTEnableICustomPropertyProviderSupport)' == ''">true</CsWinRTEnableICustomPropertyProviderSupport>
<CsWinRTEnableIReferenceSupport Condition="'$(CsWinRTEnableIReferenceSupport)' == ''">true</CsWinRTEnableIReferenceSupport>
<CsWinRTEnableIDynamicInterfaceCastableSupport Condition="'$(CsWinRTEnableIDynamicInterfaceCastableSupport)' == ''">true</CsWinRTEnableIDynamicInterfaceCastableSupport>
<CsWinRTUseWindowsUIXamlProjections Condition="'$(CsWinRTUseWindowsUIXamlProjections)' == ''">false</CsWinRTUseWindowsUIXamlProjections>
</PropertyGroup>

<!-- Default values for all other CsWinRT properties (without feature switches) -->
Expand Down Expand Up @@ -369,15 +370,10 @@ $(CsWinRTInternalProjection)
Value="$(CsWinRTEnableIDynamicInterfaceCastableSupport)"
Trim="true" />

<!-- CSWINRT_USE_WINDOWS_UI_XAML_PROJECTIONS switch-->
<RuntimeHostConfigurationOption Include="CSWINRT_USE_WINDOWS_UI_XAML_PROJECTIONS" Condition="'$(CsWinRTUIXamlProjections)' == 'WindowsUIXaml'">
<Value>true</Value>
<Trim>true</Trim>
</RuntimeHostConfigurationOption>
<RuntimeHostConfigurationOption Include="CSWINRT_USE_WINDOWS_UI_XAML_PROJECTIONS" Condition="'$(CsWinRTUIXamlProjections)' != 'WindowsUIXaml'">
<Value>false</Value>
<Trim>true</Trim>
</RuntimeHostConfigurationOption>
<!-- CSWINRT_USE_WINDOWS_UI_XAML_PROJECTIONS switch -->
<RuntimeHostConfigurationOption Include="CSWINRT_USE_WINDOWS_UI_XAML_PROJECTIONS"
Value="$(CsWinRTUseWindowsUIXamlProjections)"
Trim="true" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Authoring/WinRT.SourceGenerator/AotOptimizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
var properties = context.AnalyzerConfigOptionsProvider.Select(static (provider, _) =>
(provider.IsCsWinRTAotOptimizerEnabled(), provider.IsCsWinRTComponent(), provider.IsCsWinRTCcwLookupTableGeneratorEnabled()));

var typeMapper = context.AnalyzerConfigOptionsProvider.Select((options, ct) => options.GlobalOptions.GetUIXamlProjectionsMode()).Select((mode, ct) => new TypeMapper(mode));
var typeMapper = context.AnalyzerConfigOptionsProvider.Select((options, ct) => options.GetCsWinRTUseWindowsUIXamlProjections()).Select((mode, ct) => new TypeMapper(mode));

var vtablesToAddFromClassTypes = context.SyntaxProvider.CreateSyntaxProvider(
static (n, _) => NeedVtableAttribute(n),
Expand Down
2 changes: 1 addition & 1 deletion src/Authoring/WinRT.SourceGenerator/DiagnosticUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public WinRTComponentScanner(GeneratorExecutionContext context, string assemblyN
_assemblyName = assemblyName;
_context = context;
_flag = false;
_typeMapper = new TypeMapper(context.AnalyzerConfigOptions.GlobalOptions.GetUIXamlProjectionsMode());
_typeMapper = new TypeMapper(context.AnalyzerConfigOptions.GetCsWinRTUseWindowsUIXamlProjections());
}

private readonly string _assemblyName;
Expand Down
2 changes: 1 addition & 1 deletion src/Authoring/WinRT.SourceGenerator/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ComponentGenerator(GeneratorExecutionContext context)
{
this.context = context;
Logger = new Logger(context);
mapper = new(context.AnalyzerConfigOptions.GlobalOptions.GetUIXamlProjectionsMode());
mapper = new(context.AnalyzerConfigOptions.GetCsWinRTUseWindowsUIXamlProjections());
// TODO-WuxMux: output a module initializer that validates the MUX/WUX projection mode to ensure that things don't get out of sync.
}

Expand Down
10 changes: 10 additions & 0 deletions src/Authoring/WinRT.SourceGenerator/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ public static bool IsCsWinRTCcwLookupTableGeneratorEnabled(this AnalyzerConfigOp
return false;
}

public static bool GetCsWinRTUseWindowsUIXamlProjections(this AnalyzerConfigOptionsProvider provider)
{
if (provider.GlobalOptions.TryGetValue("build_property.CsWinRTUseWindowsUIXamlProjections", out var csWinRTUseWindowsUIXamlProjections))
{
return bool.TryParse(csWinRTUseWindowsUIXamlProjections, out var isCsWinRTUseWindowsUIXamlProjectionsEnabled) && isCsWinRTUseWindowsUIXamlProjectionsEnabled;
}

return false;
}

public static int GetCsWinRTAotWarningLevel(this AnalyzerConfigOptionsProvider provider)
{
if (provider.GlobalOptions.TryGetValue("build_property.CsWinRTAotWarningLevel", out var csWinRTAotWarningLevelStr) &&
Expand Down
4 changes: 2 additions & 2 deletions src/Authoring/WinRT.SourceGenerator/TypeMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ private static (string, string, string, bool, bool) GetSystemTypeCustomMapping(I
("Windows.UI.Xaml.Interop", "TypeName", "Windows.Foundation.UniversalApiContract", false, true);
}

public TypeMapper(UIXamlProjectionsMode xamlMode)
public TypeMapper(bool useWindowsUIXamlProjections)
{
// This should be in sync with the reverse mapping from WinRT.Runtime/Projections.cs and cswinrt/helpers.h.
if (xamlMode == UIXamlProjectionsMode.WindowsUIXaml)
if (useWindowsUIXamlProjections)
{
typeMapping = new(StringComparer.Ordinal)
{
Expand Down
26 changes: 0 additions & 26 deletions src/Authoring/WinRT.SourceGenerator/UIXamlProjectionsMode.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Authoring/WinRT.SourceGenerator/WinRTAotCodeFixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public override void Initialize(AnalysisContext context)
return;
}

var typeMapper = new TypeMapper(context.Options.AnalyzerConfigOptionsProvider.GlobalOptions.GetUIXamlProjectionsMode());
var typeMapper = new TypeMapper(context.Options.AnalyzerConfigOptionsProvider.GetCsWinRTUseWindowsUIXamlProjections());
var csWinRTAotWarningLevel = context.Options.AnalyzerConfigOptionsProvider.GetCsWinRTAotWarningLevel();

context.RegisterSymbolAction(context =>
Expand Down
3 changes: 2 additions & 1 deletion src/Tests/AuthoringWuxTest/AuthoringWuxTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<Platforms>x64;x86</Platforms>
<CsWinRTComponent>true</CsWinRTComponent>
<IsTrimmable>true</IsTrimmable>
<CsWinRTUIXamlProjections>WindowsUIXaml</CsWinRTUIXamlProjections>
<UseUwp>true</UseUwp>
<CsWinRTUseWindowsUIXamlProjections>true</CsWinRTUseWindowsUIXamlProjections>
<!-- CsWinRTEnableLogging helps to diagnose generation issues -->
<!-- <CsWinRTEnableLogging>true</CsWinRTEnableLogging> -->
<!--<CsWinRTKeepGeneratedSources>true</CsWinRTKeepGeneratedSources>-->
Expand Down
Loading