Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@
<_UseDynamicDependenciesForSmartEnumPreservation Condition="'$(_UseDynamicDependenciesForSmartEnumPreservation)' == ''">$(_UseDynamicDependenciesInsteadOfMarking)</_UseDynamicDependenciesForSmartEnumPreservation>
<_UseDynamicDependenciesForBlockCodePreservation Condition="'$(_UseDynamicDependenciesForBlockCodePreservation)' == ''">$(_UseDynamicDependenciesInsteadOfMarking)</_UseDynamicDependenciesForBlockCodePreservation>
<_UseDynamicDependenciesForGeneratedCodeOptimizations Condition="'$(_UseDynamicDependenciesForGeneratedCodeOptimizations)' == ''">$(_UseDynamicDependenciesInsteadOfMarking)</_UseDynamicDependenciesForGeneratedCodeOptimizations>
<_UseLinkDescriptionForApplyPreserveAttribute Condition="'$(_UseLinkDescriptionForApplyPreserveAttribute)' == '' And '$(_XamarinRuntime)' == 'NativeAOT'">true</_UseLinkDescriptionForApplyPreserveAttribute>
<_UseLinkDescriptionForApplyPreserveAttribute Condition="'$(_UseLinkDescriptionForApplyPreserveAttribute)' == ''">$(_UseDynamicDependenciesInsteadOfMarking)</_UseLinkDescriptionForApplyPreserveAttribute>
</PropertyGroup>

<PropertyGroup>
Expand Down Expand Up @@ -756,6 +758,7 @@
<_TrimmerCustomSteps Include="$(_AdditionalTaskAssembly)" BeforeStep="MarkStep" Type="Xamarin.Linker.Steps.PreserveSmartEnumConversionsStep" Condition="'$(_AreAnyAssembliesTrimmed)' == 'true' And '$(_UseDynamicDependenciesForSmartEnumPreservation)' == 'true'" />
<_TrimmerCustomSteps Include="$(_AdditionalTaskAssembly)" BeforeStep="MarkStep" Type="Xamarin.Linker.Steps.PreserveBlockCodeStep" Condition="'$(_AreAnyAssembliesTrimmed)' == 'true' And '$(_UseDynamicDependenciesForBlockCodePreservation)' == 'true'" />
<_TrimmerCustomSteps Include="$(_AdditionalTaskAssembly)" BeforeStep="MarkStep" Type="Xamarin.Linker.Steps.OptimizeGeneratedCodeStep" Condition="'$(_AreAnyAssembliesTrimmed)' == 'true' And '$(_UseDynamicDependenciesForGeneratedCodeOptimizations)' == 'true'" />
<_TrimmerCustomSteps Include="$(_AdditionalTaskAssembly)" BeforeStep="MarkStep" Type="Xamarin.Linker.Steps.ApplyPreserveAttributeStep" Condition="'$(_AreAnyAssembliesTrimmed)' == 'true' And '$(_UseLinkDescriptionForApplyPreserveAttribute)' == 'true'" />
<!-- The final decision to remove/keep the dynamic registrar must be done before the linking step -->
<_TrimmerCustomSteps Include="$(_AdditionalTaskAssembly)" BeforeStep="MarkStep" Type="MonoTouch.Tuner.RegistrarRemovalTrackingStep" />
<!-- TODO: these steps should probably run after mark. -->
Expand Down Expand Up @@ -1084,6 +1087,7 @@
<_LinkerItemFiles Include="$(_LinkerItemsDirectory)/_AssembliesToAOT.items" />
<_LinkerItemFiles Include="$(_LinkerItemsDirectory)/_FrameworkToPublish.items" />
<_LinkerItemFiles Include="$(_LinkerItemsDirectory)/_DynamicLibraryToPublish.items" />
<_LinkerItemFiles Include="$(_LinkerItemsDirectory)/TrimmerRootDescriptor.items" />
</ItemGroup>

<ItemGroup>
Expand All @@ -1108,7 +1112,17 @@
<_AssembliesToAOT Include="@(_AllLinkerItems)" Condition="'%(_AllLinkerItems.SourceFile)' == '_AssembliesToAOT.items'" />
<_FrameworkToPublish Include="@(_AllLinkerItems)" Condition="'%(_AllLinkerItems.SourceFile)' == '_FrameworkToPublish.items'" />
<_DynamicLibraryToPublish Include="@(_AllLinkerItems)" Condition="'%(_AllLinkerItems.SourceFile)' == '_DynamicLibraryToPublish.items'" />
<_TrimmerRootDescriptorFromCustomLinkerSteps Include="@(_AllLinkerItems)" Condition="'%(_AllLinkerItems.SourceFile)' == 'TrimmerRootDescriptor.items'" />

<TrimmerRootDescriptor Include="@(_TrimmerRootDescriptorFromCustomLinkerSteps)" />
</ItemGroup>
<PropertyGroup Condition="'$(RunILLink)' == 'true' And '$(_UseNativeAot)' == 'true' And @(_TrimmerRootDescriptorFromCustomLinkerSteps->Count()) &gt; 0">
<!-- When the custom linker steps produce xml root descriptors, those xml root descriptors may refer to types and members that are removed
during linking (for members that are conditionally preserved). If we then pass those xml root descriptors to ilc, ilc will show
a IL2008 warning about those members that have been trimmed away. So ignore any IL2008 warnings when we add trimmer root descriptors
from a custom linker step. This will become unnecessary when we stop using custom linker steps. -->
<NoWarn>$(NoWarn);IL2008</NoWarn> <!-- Could not resolve type '...' -->
</PropertyGroup>
</Target>

<!-- Native code -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
AppBundleSize: 2,450,516 bytes (2,393.1 KB = 2.3 MB)
AppBundleSize: 2,599,110 bytes (2,538.2 KB = 2.5 MB)
# The following list of files and their sizes is just informational / for review, and isn't used in the test:
Contents/_CodeSignature/CodeResources: 2,358 bytes (2.3 KB = 0.0 MB)
Contents/Info.plist: 1,094 bytes (1.1 KB = 0.0 MB)
Contents/MacOS/SizeTestApp: 2,445,248 bytes (2,387.9 KB = 2.3 MB)
Contents/Info.plist: 1,128 bytes (1.1 KB = 0.0 MB)
Contents/MacOS/SizeTestApp: 2,593,808 bytes (2,533.0 KB = 2.5 MB)
Contents/MonoBundle/runtimeconfig.bin: 1,808 bytes (1.8 KB = 0.0 MB)
Contents/PkgInfo: 8 bytes (0.0 KB = 0.0 MB)
6 changes: 3 additions & 3 deletions tests/dotnet/UnitTests/expected/MacOSX-NativeAOT-size.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
AppBundleSize: 8,094,981 bytes (7,905.3 KB = 7.7 MB)
AppBundleSize: 8,440,007 bytes (8,242.2 KB = 8.0 MB)
# The following list of files and their sizes is just informational / for review, and isn't used in the test:
Contents/_CodeSignature/CodeResources: 3,489 bytes (3.4 KB = 0.0 MB)
Contents/Info.plist: 725 bytes (0.7 KB = 0.0 MB)
Contents/MacOS/SizeTestApp: 5,101,408 bytes (4,981.8 KB = 4.9 MB)
Contents/Info.plist: 759 bytes (0.7 KB = 0.0 MB)
Contents/MacOS/SizeTestApp: 5,446,400 bytes (5,318.8 KB = 5.2 MB)
Contents/MonoBundle/libSystem.Globalization.Native.dylib: 252,176 bytes (246.3 KB = 0.2 MB)
Contents/MonoBundle/libSystem.IO.Compression.Native.dylib: 2,005,440 bytes (1,958.4 KB = 1.9 MB)
Contents/MonoBundle/libSystem.Native.dylib: 292,176 bytes (285.3 KB = 0.3 MB)
Expand Down
6 changes: 3 additions & 3 deletions tests/dotnet/UnitTests/expected/TVOS-NativeAOT-size.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
AppBundleSize: 2,450,669 bytes (2,393.2 KB = 2.3 MB)
AppBundleSize: 2,616,495 bytes (2,555.2 KB = 2.5 MB)
# The following list of files and their sizes is just informational / for review, and isn't used in the test:
_CodeSignature/CodeResources: 2,589 bytes (2.5 KB = 0.0 MB)
archived-expanded-entitlements.xcent: 384 bytes (0.4 KB = 0.0 MB)
Info.plist: 1,112 bytes (1.1 KB = 0.0 MB)
Info.plist: 1,146 bytes (1.1 KB = 0.0 MB)
PkgInfo: 8 bytes (0.0 KB = 0.0 MB)
runtimeconfig.bin: 1,808 bytes (1.8 KB = 0.0 MB)
SizeTestApp: 2,444,768 bytes (2,387.5 KB = 2.3 MB)
SizeTestApp: 2,610,560 bytes (2,549.4 KB = 2.5 MB)
6 changes: 3 additions & 3 deletions tests/dotnet/UnitTests/expected/iOS-NativeAOT-size.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
AppBundleSize: 2,437,189 bytes (2,380.1 KB = 2.3 MB)
AppBundleSize: 2,602,055 bytes (2,541.1 KB = 2.5 MB)
# The following list of files and their sizes is just informational / for review, and isn't used in the test:
_CodeSignature/CodeResources: 2,589 bytes (2.5 KB = 0.0 MB)
archived-expanded-entitlements.xcent: 384 bytes (0.4 KB = 0.0 MB)
Info.plist: 1,136 bytes (1.1 KB = 0.0 MB)
Info.plist: 1,170 bytes (1.1 KB = 0.0 MB)
PkgInfo: 8 bytes (0.0 KB = 0.0 MB)
runtimeconfig.bin: 1,808 bytes (1.8 KB = 0.0 MB)
SizeTestApp: 2,431,264 bytes (2,374.3 KB = 2.3 MB)
SizeTestApp: 2,596,096 bytes (2,535.2 KB = 2.5 MB)
2 changes: 2 additions & 0 deletions tools/common/DerivedLinkContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class DerivedLinkContext : LinkContext {
// so we need a second dictionary
Dictionary<TypeDefinition, LinkedAwayTypeReference> LinkedAwayTypeMap = new Dictionary<TypeDefinition, LinkedAwayTypeReference> ();

public bool DidRunApplyPreserveAttributeStep { get; set; }

public DerivedLinkContext (LinkerConfiguration configuration, Application app)
#if !LEGACY_TOOLS
: base (configuration)
Expand Down
16 changes: 14 additions & 2 deletions tools/dotnet-linker/AppBundleRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
Comment thread
rolfbjarne marked this conversation as resolved.

using Mono.Cecil;
using Mono.Cecil.Cil;
Expand Down Expand Up @@ -1384,7 +1385,7 @@ public bool AddAttributeToStaticConstructor (TypeDefinition onType, CustomAttrib
return modified;
}

MethodDefinition GetOrCreateStaticConstructor (TypeDefinition type, out bool modified)
public MethodDefinition GetOrCreateStaticConstructor (TypeDefinition type, out bool modified)
{
modified = false;

Expand All @@ -1408,7 +1409,7 @@ MethodDefinition GetOrCreateStaticConstructor (TypeDefinition type, out bool mod
/// <param name="provider">The provider to which the attribute should be added.</param>
/// <param name="attribute">The attribute to add.</param>
/// <returns>Whether the attribute was added or not.</returns>
bool AddAttributeOnlyOnce (ICustomAttributeProvider provider, CustomAttribute attribute)
public bool AddAttributeOnlyOnce (ICustomAttributeProvider provider, CustomAttribute attribute)
{
if (provider.HasCustomAttributes) {
foreach (var ca in provider.CustomAttributes) {
Expand Down Expand Up @@ -1460,7 +1461,18 @@ bool AddAttributeOnlyOnce (ICustomAttributeProvider provider, CustomAttribute at
}
}
provider.CustomAttributes.Add (attribute);
if (DebugAttributes)
Console.WriteLine ($"Added {attribute.RenderAttribute ()} to {provider}");
return true;
}

static bool? debug_attributes;
static bool DebugAttributes {
get {
if (!debug_attributes.HasValue)
debug_attributes = !string.IsNullOrEmpty (Environment.GetEnvironmentVariable ("PRINT_ATTRIBUTES"));
return debug_attributes.Value;
}
}
}
}
Loading
Loading