Skip to content

Support ReadyToRun, trimming and NativeAOT #255

Closed
3 of 3 issues completed
Closed

Description

PostSharp 2027.0 supports applications that are published with ReadyToRun, trimmed, or compiled ahead of time (NativeAOT). This issue groups the three issues that implement this support.

Issue Scope
#89 The aspect framework: PostSharp.dll and the code that the weaver generates. ReadyToRun is tested.
#252 The pattern libraries: Common, Aggregation, Model, Threading, Diagnostics and Caching.
#254 A new advice, InstantiateTypeAdviceInstance, with which an aspect requests the native code of a closed generic type. [Cache] and [Log] use it.

What is supported

  • ReadyToRun. A woven assembly is precompiled, and it behaves as without ReadyToRun. It needed no change.
  • Trimming and NativeAOT of a woven assembly. The serializers of the aspects are created by code that the weaver generates, not by reflection. The net10.0 build of PostSharp.dll is annotated (IsAotCompatible), and a publication reports no trimming or AOT warning.
  • Trimming and NativeAOT of the pattern libraries. The net10.0 builds of Common, Aggregation, Model, Threading, Diagnostics and Caching are annotated. The code that only the compiler runs is behind the feature switch PostSharp.Patterns.IsCompileTimeCodeSupported, so the trimmer removes it.
  • Generic types over value types under NativeAOT. An aspect returns InstantiateTypeAdviceInstance from IAdviceProvider for each closed generic type that it creates by reflection at run time. The weaver then makes the ahead-of-time compiler produce the native code of the type. The advice has no effect unless the MSBuild property PostSharpAotCompatibleWeaving is true. Its default is true when the project sets PublishAot, IsAotCompatible or EnableAotAnalyzer.

What the user does

  • An application sets PublishAot or PublishTrimmed, as for any .NET application. The packages set the feature switches.
  • A library that is published in a native application sets IsAotCompatible, so that its woven assembly requests the native code that its aspects need.

Limits

  • An adapter or a formatter over a value type that the application registers at run time has no native code under NativeAOT.
  • MemoryCachingBackend does not support trimming, because System.Runtime.Caching reads the configuration through System.Configuration. MemoryCacheBackend does.
  • The backends of the logging and caching libraries, PostSharp.Patterns.Diagnostics.Configuration, PostSharp.Patterns.Xaml and the Windows-specific parts of PostSharp.Patterns.Threading are not annotated.
  • NativeAOT was measured on win-x64 only.

The details, the measurements and the tests are in each issue. The implementation is in a single pull request of the source repository.

— Claude for Gael

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-PlatformsTarget frameworks, SDKs, reference packs, languages

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions