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

Add -public_exclusiveto flag to enable implementing exclusiveto interfaces in consuming projects #1670

Merged
merged 9 commits into from
Jul 13, 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: 2 additions & 0 deletions nuget/Microsoft.Windows.CsWinRT.targets
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<CsWinRTInternalProjection Condition="'$(CsWinRTPrivateProjection)' == 'true'">-internal</CsWinRTInternalProjection>
<CsWinRTEmbeddedProjection Condition="'$(CsWinRTEmbedded)' == 'true'">-embedded</CsWinRTEmbeddedProjection>
<CsWinRTEmbeddedEnums Condition="'$(CsWinRTEmbeddedPublicEnums)' == 'true'">-public_enums</CsWinRTEmbeddedEnums>
<CsWinRTPublicExclusiveTo Condition="'$(CsWinRTPublicExclusiveToInterfaces)' == 'true'">-public_exclusiveto</CsWinRTPublicExclusiveTo>

<CsWinRTParams Condition="'$(CsWinRTParams)' == ''">
$(CsWinRTCommandVerbosity)
Expand All @@ -252,6 +253,7 @@ $(CsWinRTFilters)
$(CsWinRTIncludeWinRTInterop)
$(CsWinRTEmbeddedProjection)
$(CsWinRTEmbeddedEnums)
$(CsWinRTPublicExclusiveTo)
</CsWinRTParams>

<CsWinRTPrivateParams Condition="'$(CsWinRTPrivateParams)' == ''">
Expand Down
31 changes: 31 additions & 0 deletions src/Projections/TestPublicExclusiveTo/TestPublicExclusiveTo.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(LibBuildTFMs)</TargetFrameworks>
<Platforms>x64;x86</Platforms>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Tests\TestComponentCSharp\TestComponentCSharp.vcxproj" />
<ProjectReference Include="..\..\TestWinRT\TestComponent\TestComponent.vcxproj" />
<ProjectReference Include="..\..\TestWinRT\test_component_base\test_component_base.vcxproj" />
<ProjectReference Include="..\..\TestWinRT\test_component_derived\test_component_derived.vcxproj" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
<ProjectReference Include="..\..\WinRT.Runtime\WinRT.Runtime.csproj" />
<ProjectReference Include="..\..\cswinrt\cswinrt.vcxproj" />
<ProjectReference Include="..\Windows\Windows.csproj" />
<ProjectReference Include="..\WinAppSDK\WinAppSDK.csproj" />
</ItemGroup>

<PropertyGroup>
<CsWinRTIncludes>TestComponentCSharp.TestPublicExclusiveTo;</CsWinRTIncludes>
<CsWinRTPublicExclusiveToInterfaces>true</CsWinRTPublicExclusiveToInterfaces>
<!--PkgMicrosoft_WindowsAppSDK is set in in obj\*.csproj.nuget.g.props with TargetFramework condition, doesn't support multi-targeting-->
<PkgMicrosoft_WindowsAppSDK>$([MSBuild]::NormalizeDirectory('$(NuGetPackageRoot)', 'microsoft.windowsappsdk', '$(MicrosoftWinAppSDKVersion)'))</PkgMicrosoft_WindowsAppSDK>
</PropertyGroup>
<ItemGroup>
<!--Explicitly reference WinAppSDK winmds from TFM uap10.0-->
<CsWinRTInputs Include="$(PkgMicrosoft_WindowsAppSDK)/**/*.winmd" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using TestComponentCSharp.TestPublicExclusiveTo;

namespace TestImplementExclusiveTo
{
public sealed partial class TestClass : INonUniqueClass, IRegularInterface, INonUniqueClassFactory
{
public int Type => throw new NotImplementedException();
public string Path => throw new NotImplementedException();
public int StaticProperty => throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<Platforms>x86;x64</Platforms>
<RuntimeIdentifiers>win-x86;win-x64</RuntimeIdentifiers>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Authoring\WinRT.SourceGenerator\WinRT.SourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" SetPlatform="Platform=x64"/>
<ProjectReference Include="..\..\..\Projections\TestPublicExclusiveTo\TestPublicExclusiveTo.csproj" />
<ProjectReference Include="..\..\..\Projections\Windows\Windows.csproj" />
</ItemGroup>

</Project>
21 changes: 21 additions & 0 deletions src/Tests/TestComponentCSharp/NonUniqueClass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "pch.h"
#include "NonUniqueClass.h"
#include "TestPublicExclusiveTo.NonUniqueClass.g.cpp"

using namespace winrt;

namespace winrt::TestComponentCSharp::TestPublicExclusiveTo::implementation
{
int32_t NonUniqueClass::StaticProperty()
{
throw hresult_not_implemented();
}
hstring NonUniqueClass::Path()
{
throw hresult_not_implemented();
}
int32_t NonUniqueClass::Type()
{
throw hresult_not_implemented();
}
}
21 changes: 21 additions & 0 deletions src/Tests/TestComponentCSharp/NonUniqueClass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once
#include "TestPublicExclusiveTo.NonUniqueClass.g.h"

namespace winrt::TestComponentCSharp::TestPublicExclusiveTo::implementation
{
struct NonUniqueClass : NonUniqueClassT<NonUniqueClass>
{
public:
NonUniqueClass();

static int32_t StaticProperty();
hstring Path();
int32_t Type();
};
}
namespace winrt::TestComponentCSharp::TestPublicExclusiveTo::factory_implementation
{
struct NonUniqueClass : NonUniqueClassT<NonUniqueClass, implementation::NonUniqueClass>
{
};
}
15 changes: 15 additions & 0 deletions src/Tests/TestComponentCSharp/TestComponentCSharp.idl
Original file line number Diff line number Diff line change
Expand Up @@ -701,4 +701,19 @@ And this is another one"
Int32 ReadWriteProperty{ set; };
}
}

namespace TestPublicExclusiveTo
{
interface IRegularInterface
{
Int32 Type { get; };
}

// This is a test for runtimeclass which can be have its interfaces implemented by other consumers
unsealed runtimeclass NonUniqueClass : IRegularInterface
{
String Path{ get; };
static Int32 StaticProperty { get; };
}
}
}
2 changes: 2 additions & 0 deletions src/Tests/TestComponentCSharp/TestComponentCSharp.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<DependentUpon>TestComponentCSharp.idl</DependentUpon>
</ClInclude>
<ClInclude Include="NonAgileClass.h" />
<ClInclude Include="NonUniqueClass.h" />
<ClInclude Include="ComImports.h" />
<ClInclude Include="Singleton.h" />
<ClInclude Include="WarningClass.h" />
Expand All @@ -111,6 +112,7 @@
<DependentUpon>TestComponentCSharp.idl</DependentUpon>
</ClCompile>
<ClCompile Include="NonAgileClass.cpp" />
<ClCompile Include="NonUniqueClass.cpp" />
<ClCompile Include="ComImports.cpp" />
<ClCompile Include="ManualProjectionTestClasses.cpp" />
<ClCompile Include="Singleton.cpp" />
Expand Down
30 changes: 30 additions & 0 deletions src/cswinrt.sln
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AuthoringWuxTest", "Tests\A
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AuthoringWuxConsumptionTest", "Tests\AuthoringWuxConsumptionTest\AuthoringWuxConsumptionTest.vcxproj", "{A04A0416-5E35-4DD0-8226-63D941B28467}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestPublicExclusiveTo", "Projections\TestPublicExclusiveTo\TestPublicExclusiveTo.csproj", "{0B3A0096-5131-441B-935B-5E8A56343869}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestImplementExclusiveTo", "Tests\FunctionalTests\TestImplementExclusiveTo\TestImplementExclusiveTo.csproj", "{30EE902C-C1D3-40E0-B63C-59FFB4503633}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
Expand Down Expand Up @@ -786,6 +790,30 @@ Global
{A04A0416-5E35-4DD0-8226-63D941B28467}.Release|x64.Build.0 = Release|x64
{A04A0416-5E35-4DD0-8226-63D941B28467}.Release|x86.ActiveCfg = Release|Win32
{A04A0416-5E35-4DD0-8226-63D941B28467}.Release|x86.Build.0 = Release|Win32
{0B3A0096-5131-441B-935B-5E8A56343869}.Debug|ARM.ActiveCfg = Debug|x64
{0B3A0096-5131-441B-935B-5E8A56343869}.Debug|ARM64.ActiveCfg = Debug|x64
{0B3A0096-5131-441B-935B-5E8A56343869}.Debug|x64.ActiveCfg = Debug|x64
{0B3A0096-5131-441B-935B-5E8A56343869}.Debug|x64.Build.0 = Debug|x64
{0B3A0096-5131-441B-935B-5E8A56343869}.Debug|x86.ActiveCfg = Debug|x86
{0B3A0096-5131-441B-935B-5E8A56343869}.Debug|x86.Build.0 = Debug|x86
{0B3A0096-5131-441B-935B-5E8A56343869}.Release|ARM.ActiveCfg = Release|x64
{0B3A0096-5131-441B-935B-5E8A56343869}.Release|ARM64.ActiveCfg = Release|x64
{0B3A0096-5131-441B-935B-5E8A56343869}.Release|x64.ActiveCfg = Release|x64
{0B3A0096-5131-441B-935B-5E8A56343869}.Release|x64.Build.0 = Release|x64
{0B3A0096-5131-441B-935B-5E8A56343869}.Release|x86.ActiveCfg = Release|x86
{0B3A0096-5131-441B-935B-5E8A56343869}.Release|x86.Build.0 = Release|x86
{30EE902C-C1D3-40E0-B63C-59FFB4503633}.Debug|ARM.ActiveCfg = Debug|x64
{30EE902C-C1D3-40E0-B63C-59FFB4503633}.Debug|ARM64.ActiveCfg = Debug|x64
{30EE902C-C1D3-40E0-B63C-59FFB4503633}.Debug|x64.ActiveCfg = Debug|x64
{30EE902C-C1D3-40E0-B63C-59FFB4503633}.Debug|x64.Build.0 = Debug|x64
{30EE902C-C1D3-40E0-B63C-59FFB4503633}.Debug|x86.ActiveCfg = Debug|x86
{30EE902C-C1D3-40E0-B63C-59FFB4503633}.Debug|x86.Build.0 = Debug|x86
{30EE902C-C1D3-40E0-B63C-59FFB4503633}.Release|ARM.ActiveCfg = Release|x64
{30EE902C-C1D3-40E0-B63C-59FFB4503633}.Release|ARM64.ActiveCfg = Release|x64
{30EE902C-C1D3-40E0-B63C-59FFB4503633}.Release|x64.ActiveCfg = Release|x64
{30EE902C-C1D3-40E0-B63C-59FFB4503633}.Release|x64.Build.0 = Release|x64
{30EE902C-C1D3-40E0-B63C-59FFB4503633}.Release|x86.ActiveCfg = Release|x86
{30EE902C-C1D3-40E0-B63C-59FFB4503633}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -834,6 +862,8 @@ Global
{E85F3614-79B6-4652-BDB0-64AF68874CE0} = {6D41796B-9904-40B8-BBCB-40B2D1BAE44B}
{D60CFCAD-4A13-4047-91C8-9D7DF4753493} = {CFB651EC-DAA4-4A11-ABCD-C77F90602EB5}
{A04A0416-5E35-4DD0-8226-63D941B28467} = {CFB651EC-DAA4-4A11-ABCD-C77F90602EB5}
{0B3A0096-5131-441B-935B-5E8A56343869} = {6D41796B-9904-40B8-BBCB-40B2D1BAE44B}
{30EE902C-C1D3-40E0-B63C-59FFB4503633} = {5ECC38F0-16FD-47E1-B8DC-8C474008AD55}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5AE8C9D7-2613-4E1A-A4F2-579BAC28D0A2}
Expand Down
6 changes: 3 additions & 3 deletions src/cswinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -7325,7 +7325,7 @@ IInspectableVftbl = global::WinRT.IInspectable.Vftbl.AbiToProjectionVftable,
bind<write_guid_attribute>(type),
bind<write_winrt_helper_type_attribute>(type),
bind<write_type_custom_attributes>(type, false),
is_exclusive_to(type) || (is_projection_internal(type) || (settings.internal || settings.embedded)) ? "internal" : "public",
(is_exclusive_to(type) && !settings.public_exclusiveto) || (is_projection_internal(type) || (settings.internal || settings.embedded)) ? "internal" : "public",
type_name,
bind<write_type_inheritance>(type, object_type{}, false, false),
bind<write_interface_member_signatures>(type)
Expand Down Expand Up @@ -7590,7 +7590,7 @@ internal static global::System.Guid IID { get; } = new Guid(new byte[] { % });
else
{
// Derived classes need access to the vftbl ptr if they are extending unsealed types.
auto write_vftable_ptr = !is_exclusive_to(iface);
auto write_vftable_ptr = !is_exclusive_to(iface) || settings.public_exclusiveto;
if (!write_vftable_ptr)
{
// Also write for both overridable interfaces and for default interfaces of authored types.
Expand Down Expand Up @@ -8029,7 +8029,7 @@ NativeMemory.Free((void*)abiToProjectionVftablePtr);
// we do not need any of the Do_Abi functions or the vtable logic as we will not create CCWs for them.
// But we are still keeping the interface itself for any helper type lookup that may happen for like GUID lookup.
if (!is_generic &&
is_exclusive_to(type) &&
(is_exclusive_to(type) && !settings.public_exclusiveto) &&
// check for !authored type
!(settings.component && settings.filter.includes(type)))
{
Expand Down
2 changes: 2 additions & 0 deletions src/cswinrt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace cswinrt
{ "internal", 0, 0, {}, "Generates a private projection."},
{ "embedded", 0, 0, {}, "Generates an embedded projection."},
{ "public_enums", 0, 0, {}, "Used with embedded option to generate enums as public"},
{ "public_exclusiveto", 0, 0, {}, "Make exclusiveto interfaces public in the projection (default is internal)"},
{ "help", 0, option::no_max, {}, "Show detailed help" },
{ "?", 0, option::no_max, {}, {} },
};
Expand Down Expand Up @@ -102,6 +103,7 @@ Where <spec> is one or more of:
settings.internal = args.exists("internal");
settings.embedded = args.exists("embedded");
settings.public_enums = args.exists("public_enums");
settings.public_exclusiveto = args.exists("public_exclusiveto");
settings.input = args.files("input", database::is_database);

for (auto && include : args.values("include"))
Expand Down
1 change: 1 addition & 0 deletions src/cswinrt/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace cswinrt
bool internal{};
bool embedded{};
bool public_enums{};
bool public_exclusiveto{};
};

extern settings_type settings;
Expand Down