Add support for DisableRuntimeMarshallingAttribute · Issue #15684 · dotnet/macios (original) (raw)
The runtime is adding an assembly-level DisableRuntimeMarshallingAttribute, which does a few things:
- Consider all unmanaged types as blittable.
- Disables support for runtime marshalling.
If all assemblies (with P/Invokes) have this attribute, then we don't need to include support for runtime marshalling into an app. Mono has removed this support into a component (dotnet/runtime#61685), which means that it should be fairly easy to shrink apps a bit by:
- Automatically detect whether all assemblies with P/Invokes have this attribute.
- Disable the inclusion of the runtime marshalling component.
A prerequisite would be to fix our platform assembly (Microsoft.iOS.dll, etc) to have the DisableRuntimeMarshalling attribute, which would need either:
a) Enable source-generated DllImports, or
b) Fix all our P/invokes to only use blittable types.
The solution forward is probably to do a) first, and then check each dll import the source-generator modified to see if we can modify the DllImport to use blittable types only (since I suspect most DllImports aren't blittable by accident, and can easily be made blittable to avoid the source generator add unnecessary code).
Note that b) would likely require us to write a (cecil) test to ensure that all P/Invokes only use blittable types, because we can't rely on the compiler (dotnet/roslyn#64086).
Ref: #15668
We've fixed all our P/Invokes to only use blittable types, but the task we want to use to detect if an assembly requires the marshal-ilgen component or not has several bugs, which we're now blocked on: