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

Support for trimmable (ILLink) assemblies #982

Closed
trympet opened this issue Sep 3, 2021 · 2 comments
Closed

Support for trimmable (ILLink) assemblies #982

trympet opened this issue Sep 3, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@trympet
Copy link
Member

trympet commented Sep 3, 2021

Proposal: Support for trimmable (ILLink) assemblies

Summary

Trimming is a great feature introduced with .NET 5, but CsWinRT does not support it. This should be fixed, so assembly sizes can be reduced.

Rationale

Trimming with ILLink provides great results when publishing self contained applications. I have reduced the size of the Microsoft.Windows.SDK.NET assembly by a factor of 45, taking it from 25mb to 0.55mb! I see the same great result in other projected libraries as well.

Since WinUI is using CoreCLR, trimming will be an important tool to keep assemblies small. Same goes for Xamarin apps using the desktop SDK.

Important Notes

Issues I have encountered so far:

  • Internal constructors, used by internal factories, are incorrectly trimmed.
  • Missing interfaces and types in the ABI namespace. Perhaps an explicit interface implementation could fix this.

As you can expect, the reflection-based factories in the ABI namespace quickly break, however, these types can manually be preserved by whitelisting them using a TrimmerRootDescriptor.

ILLink can be enabled by specifying the following properties:

<PublishTrimmed>true</PublishTrimmed>
<TrimMode>link</TrimMode>

To whitelist the Windows SDK for trimming:

<ItemGroup>
    <ManagedAssemblyToLink Condition="'%(Filename)' == 'Microsoft.Windows.SDK.NET'">
        <IsTrimmable>true</IsTrimmable>
    </ManagedAssemblyToLink>
</ItemGroup>

Further reading: https://github.com/mono/linker/blob/main/docs/data-formats.md

@trympet trympet added the enhancement New feature or request label Sep 3, 2021
@manodasanW
Copy link
Member

Thanks for opening this @trympet. We are aware of some of the issues that you mention and are tracking this with #373 which also has some changes we are considering to address them.

@trympet
Copy link
Member Author

trympet commented Sep 4, 2021

@manodasanW, awesome! I'll close this issue, since it's already being tracked.

@trympet trympet closed this as completed Sep 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants