[Mono]: Library mode enhancements. (#84165)
Add support for direct pinvoke charset on Windows.
NativeAOT direct pinvoke support handles pinvoke charset on Windows,
this commit 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, 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.