-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to keep/remove COM interfaces (#101087)
Adds an illink option that can be used to remove COM interfaces (the existing behavior is to preserve COM interfaces on marked types). If a type implements a COM interface that is also marked elsewhere, it will still be kept even with `--keep-com-interfaces false`. This includes windows runtime interfaces under the same option name. This eliminates some trim warnings in winforms due to trim-incompatible code in Control's implementations of COM interfaces like IPersistPropertyBag. Experimentally, this still produces a working app for the scenario we've been testing (https://github.com/dotnet/winforms/tree/main/src/System.Windows.Forms/tests/IntegrationTests/TrimTest). For now, this just introduces the option without setting it by default anywhere (or exposing it in MSBuild) so that we can opt in from the winforms scenario. We might consider setting it wherever `BuiltInComInteropSupport` is false.
- Loading branch information
Showing
6 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
....Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedComInterfaceIsRemoved.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Runtime.InteropServices; | ||
using Mono.Linker.Tests.Cases.Expectations.Assertions; | ||
using Mono.Linker.Tests.Cases.Expectations.Metadata; | ||
|
||
namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType | ||
{ | ||
/// <summary> | ||
/// With --keep-com-interfaces false, we apply the unused interface rules also to com interfaces. | ||
/// </summary> | ||
[SetupLinkerArgument ("--keep-com-interfaces", "false")] | ||
public class UnusedComInterfaceIsRemoved | ||
{ | ||
public static void Main () | ||
{ | ||
var i = new A (); | ||
i.Foo (); | ||
} | ||
|
||
[ComImport] | ||
[Guid ("D7BB1889-3AB7-4681-A115-60CA9158FECA")] | ||
interface IBar | ||
{ | ||
void Bar (); | ||
} | ||
|
||
[Kept] | ||
[KeptMember (".ctor()")] | ||
class A : IBar | ||
{ | ||
[Kept] | ||
public void Foo () | ||
{ | ||
} | ||
|
||
public void Bar () | ||
{ | ||
} | ||
} | ||
} | ||
} |