-
Notifications
You must be signed in to change notification settings - Fork 0
/
Reloaded.Trimming.targets
149 lines (126 loc) · 6.63 KB
/
Reloaded.Trimming.targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
<!--
Originally inspired by https://github.com/space-wizards/RobustToolbox , under the MIT License
Modified by Sewer56 to include support for .NET6 IsTrimmable property.
-->
<!--
Stuff for using ILLink trimming without self-contained deployments.
This is not something officially supported by the .NET SDK currently, but we can simply run ILLink ourselves.
A lot of stuff taken from Microsoft.NET.ILLink.targets in the SDK files.
-->
<ItemDefinitionGroup>
<ReloadedLinkRoots>
<Visible>false</Visible>
</ReloadedLinkRoots>
<ReloadedLinkAssemblies>
<Visible>false</Visible>
</ReloadedLinkAssemblies>
</ItemDefinitionGroup>
<Target Name="ReloadedILLink"
BeforeTargets="ILLink"
Condition="'$(PublishTrimmed)' != 'true' And
'$(ReloadedILLink)' == 'true'"
DependsOnTargets="_ComputeAssembliesToPostprocessOnPublish">
<!-- Original Target: ComputeManagedAssemblyToLink -->
<ComputeManagedAssemblies Assemblies="@(ResolvedFileToPublish->WithMetadataValue('PostprocessAssembly', 'true'))">
<Output TaskParameter="ManagedAssemblies" ItemName="ManagedAssemblyToLink" />
</ComputeManagedAssemblies>
<ItemGroup>
<!-- The linker implicitly picks up PDBs next to input assemblies. We will filter these out of the publish set. -->
<__PDBToLink Include="@(ResolvedFileToPublish)" Exclude="@(ManagedAssemblyToLink->'%(RelativeDir)%(Filename).pdb')" />
<_PDBToLink Include="@(ResolvedFileToPublish)" Exclude="@(__PDBToLink)" />
</ItemGroup>
<ItemGroup>
<_LinkedResolvedFileToPublishCandidate Include="@(ManagedAssemblyToLink->'$(IntermediateLinkDir)%(Filename)%(Extension)')" />
<_LinkedResolvedFileToPublishCandidate Include="@(_PDBToLink->'$(IntermediateLinkDir)%(Filename)%(Extension)')" />
</ItemGroup>
<!-- Original Target: PrepareForILLink -->
<!-- Set IsTrimmable for any assemblies that already have customized TrimMode. -->
<ItemGroup>
<ManagedAssemblyToLink Condition=" '%(ManagedAssemblyToLink.TrimMode)' != '' ">
<IsTrimmable>true</IsTrimmable>
</ManagedAssemblyToLink>
</ItemGroup>
<PropertyGroup>
<TrimMode Condition=" '$(TrimMode)' == '' ">link</TrimMode>
<!-- For .NET 6+, assemblies without IsTrimmable attribute get the "copy" action. -->
<TrimmerDefaultAction Condition=" '$(TrimmerDefaultAction)' == '' ">copy</TrimmerDefaultAction>
<ILLinkTreatWarningsAsErrors Condition=" '$(ILLinkTreatWarningsAsErrors)' == '' ">$(TreatWarningsAsErrors)</ILLinkTreatWarningsAsErrors>
<_ExtraTrimmerArgs>--skip-unresolved true $(_ExtraTrimmerArgs)</_ExtraTrimmerArgs>
<TrimmerSingleWarn Condition=" '$(TrimmerSingleWarn)' == '' ">true</TrimmerSingleWarn>
</PropertyGroup>
<!-- SetIsTrimmable for any assemblies listed in TrimmableAssembly.
TrimmableAssembly -> ReloadedLinkAssemblies
-->
<JoinItems Left="@(ManagedAssemblyToLink)" LeftKey="FileName" LeftMetadata="*"
Right="@(ReloadedLinkAssemblies)"
ItemSpecToUse="Left">
<Output TaskParameter="JoinResult" ItemName="_TrimmableManagedAssemblyToLink" />
</JoinItems>
<ItemGroup>
<!-- Set trimmable for assemblies which we wish to trim. -->
<ManagedAssemblyToLink Remove="@(_TrimmableManagedAssemblyToLink)" />
<ManagedAssemblyToLink Include="@(_TrimmableManagedAssemblyToLink)" IsTrimmable="true" />
</ItemGroup>
<!-- Root the main assembly, whether or not it has IsTrimmable set. -->
<ItemGroup>
<ReloadedLinkRoots Include="@(IntermediateAssembly)" />
</ItemGroup>
<!-- In .NET6+, set the action explicitly for any with IsTrimmable MSBuild metadata -->
<ItemGroup>
<ManagedAssemblyToLink Condition=" '%(ManagedAssemblyToLink.IsTrimmable)' == 'false' And '%(ManagedAssemblyToLink.TrimMode)' == '' ">
<TrimMode>$(TrimmerDefaultAction)</TrimMode>
</ManagedAssemblyToLink>
<ManagedAssemblyToLink Condition=" '%(ManagedAssemblyToLink.IsTrimmable)' == 'true' And '%(ManagedAssemblyToLink.TrimMode)' == '' ">
<TrimMode>$(TrimMode)</TrimMode>
</ManagedAssemblyToLink>
</ItemGroup>
<!-- Custom: Print assemblies for trimming. -->
<ItemGroup>
<TrimmingItemsToPrint Include="@(ManagedAssemblyToLink)">
<Text>Input Assembly: %(filename) [Mode: %(ManagedAssemblyToLink.TrimMode)]</Text>
</TrimmingItemsToPrint>
</ItemGroup>
<Message Text="%(TrimmingItemsToPrint.Text)" Importance="high" />
<!-- Do the trimming. -->
<Delete Files="@(_LinkedResolvedFileToPublishCandidate)" />
<ILLink AssemblyPaths="@(ManagedAssemblyToLink)"
ReferenceAssemblyPaths="@(ReferencePath)"
RootAssemblyNames="@(ReloadedLinkRoots)"
TrimMode="$(TrimMode)"
DefaultAction="$(TrimmerDefaultAction)"
RemoveSymbols="false"
FeatureSettings="@(_TrimmerFeatureSettings)"
CustomData="@(_TrimmerCustomData)"
BeforeFieldInit="$(_TrimmerBeforeFieldInit)"
OverrideRemoval="$(_TrimmerOverrideRemoval)"
UnreachableBodies="$(_TrimmerUnreachableBodies)"
UnusedInterfaces="$(_TrimmerUnusedInterfaces)"
IPConstProp="$(_TrimmerIPConstProp)"
Sealer="$(_TrimmerSealer)"
Warn="$(ILLinkWarningLevel)"
NoWarn="$(NoWarn)"
TreatWarningsAsErrors="$(ILLinkTreatWarningsAsErrors)"
WarningsAsErrors="$(WarningsAsErrors)"
WarningsNotAsErrors="$(WarningsNotAsErrors)"
SingleWarn="$(TrimmerSingleWarn)"
CustomSteps="@(_TrimmerCustomSteps)"
RootDescriptorFiles="@(TrimmerRootDescriptor)"
OutputDirectory="$(IntermediateLinkDir)"
DumpDependencies="$(_TrimmerDumpDependencies)"
ExtraArgs="$(_ExtraTrimmerArgs)"
ToolExe="$(_DotNetHostFileName)"
ToolPath="$(_DotNetHostDirectory)"
ContinueOnError="ErrorAndContinue">
<Output TaskParameter="ExitCode" PropertyName="_ILLinkExitCode" />
</ILLink>
<Touch Files="$(_LinkSemaphore)" AlwaysCreate="true" Condition=" '$(_ILLinkExitCode)' == '0' " />
<!-- Original Target: ILLink -->
<ItemGroup>
<_LinkedResolvedFileToPublish Include="@(_LinkedResolvedFileToPublishCandidate)" Condition="Exists('%(Identity)')" />
<ResolvedFileToPublish Remove="@(ManagedAssemblyToLink)" />
<ResolvedFileToPublish Remove="@(_PDBToLink)" />
<ResolvedFileToPublish Include="@(_LinkedResolvedFileToPublish)" />
</ItemGroup>
</Target>
</Project>