Open jkotas opened 1 year ago
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
Steer people towards P/Invoke source generator by the warning text
If we tell people to use the source generator for AsAny/LayoutClass/System.Delegate marshalling, the source generator will then tell them it's unsupported. It will shift the blame, but the end result for the user is the same if we don't send them on a hike first.
Yes, it is the case with retrofitting existing AOT unsafe code.
Steering people towards source generated interop is more interesting for new code. Source generated interop has natural AOT safety guiderails and prevents the AOT unsafe code to be written in the first place.
towards P/Invoke source generator
Do source generated P/Invokes support direct P/Invoke and static linking?
If not then I think it's not a replacement of current P/Invokes.
Do source generated P/Invokes support direct P/Invoke and static linking?
Yes. This aspect is not different between source generated and built-in marshalling.
All P/Invokes (except a few outliers) in this repo have been switched to be source generated, and native aot publishing uses direct P/Invokes and static linking extensively.
Use actual marshaller kind to produce the warning instead of the approximation at
This logic is shared with IL Linker and IL Linker doesn't have access to this unfortunately.
Warnings for AOT unsafe interop are incomplete best effort currently: https://github.com/dotnet/runtime/pull/74630#discussion_r955966809