[illink][ios] Explicitly setting `PublishTrimmed=true` changes the default feature switch configuration
#108.269 aperta il 26 set 2024
Metriche repository
- Star
- (17.886 star)
- Metriche merge PR
- (Merge medio 12g 11h) (661 PR mergiate in 30 g)
Descrizione
Description
As called out in: https://github.com/dotnet/runtime/issues/108108#issuecomment-2375220090 iOS apps built with PublishTrimmed=true set on a project level end up with different set of feature switches configured during the build.
For example consider the difference in the input to the trimmer with and without setting the property value explicitly:
--feature Microsoft.Extensions.DependencyInjection.VerifyOpenGenericServiceTrimmability false->true
--feature System.ComponentModel.DefaultValueAttribute.IsSupported ->false
--feature System.ComponentModel.Design.IDesignerHost.IsSupported ->false
--feature System.Resources.UseSystemResourceKeys true->false
--feature System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported false->true
--feature System.Runtime.InteropServices.Marshalling.EnableGeneratedComInterfaceComImportInterop ->false
Problem
The problem comes from the order of importing MSBuild targets and property evaluation:
-
if it is not set on the project level, we will use feature switch configuration as set in the Xamarin SDK early in
Xamarin.Shared.Sdk.targets: https://github.com/xamarin/xamarin-macios/blob/ec50934897ef1b98c1cd73ca780cdf5a3750faaa/dotnet/targets/Xamarin.Shared.Sdk.targets#L121-L158 The SDK later sets:PublishTrimmedtotrueso that we run the linker in: https://github.com/xamarin/xamarin-macios/blob/ec50934897ef1b98c1cd73ca780cdf5a3750faaa/dotnet/targets/Xamarin.Shared.Sdk.targets#L298 -
if it is set on project level,
Microsoft.NET.ILLink.targetswill set its own feature switch configuration in: https://github.com/dotnet/runtime/blob/a16e0d58e92fe5f3bcda9e75e9afd1ee0f766967/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets#L34-L61 as it is imported beforeXamarin.Shared.Sdk.targetsThis is specifically problematic in case of for example:
DynamicCodeSupport, which should not betrueon iOS platforms if interpreter is not enabled.
Proposal
We should investigate setting the feature switch defaults (and possibly other trimmer setting) in an MSBuild target so that mobile SDKs can provide different defaults earlier in the build.