[Mono]: Library mode enhancements. #84165
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR does a couple of enhancements to library mode builds.
Add support for direct pinvoke charset on Windows.
NativeAOT direct pinvoke support handles pinvoke charset on Windows:
runtime/src/coreclr/tools/aot/ILCompiler/ConfigurablePInvokePolicy.cs
Line 101 in b69b359
This PR adds the same logic to Mono when targeting Windows, so it will follow the same charset rules as NativeAOT.
direct pinvoke wrappers on none full AOT builds.
Library mode builds will have option to create a self contained static or shared library, including all needed resources, embedding assemblies and static link all external dependencies (using direct pinvoke). Library mode also exports UnamangedCallersOnly methods that can be called by application loading the library. Currently the wrappers needed for UnmanagedCallersOnly methods will be generated when doing none full AOT builds (741fa51), but not pinvoke wrappers. This PR adds support to generate the pinvoke wrappers, but only for the methods described by direct pinvoke AOT compiler arguments, so for none full AOT builds not using direct pinvoke arguments, no pinvoke wrappers will be generated, inline with current none full AOT behavior.
direct pinvoke wrappers on profiled AOT builds.
Enhanced the profile-only option doing profile AOT to emit managed-to-native and native-to-managed wrappers. Needed in order for library build to work together with profiled AOT builds.
wrappers-only AOT option.
On platforms like Android, we still run majority of code using JIT. Since library mode should produce a self contained library, including pinvokes (for all direct pinvoked functions) as well as UnmanagedCallersOnly wrappers, Android would need to at least run none full AOT build of all used assemblies. By default, that will AOT a lot more methods that is really needed and there is no way to reduce the AOT:ed code and still run as much as possible using JIT. The profile-only option opens up ability to reduce what managed methods that will be AOT:ed, but still generates a number of inflated methods not needed by UnmanagedCallersOnly and direct pinvoke wrappers and piggy back on an existing option with additional functionality is not optimal. This PR adds an undocumented AOT option intended to be used by library builder,
wrappers-only
, and that will only include wrappers in AOT object giving library builder the ability to build a self contained library on Android that still runs majority of managed code using JIT.