-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
illink.targets
302 lines (262 loc) · 17.4 KB
/
illink.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<Project>
<PropertyGroup>
<IsTrimmable Condition="'$(IsTrimmable)' == ''">true</IsTrimmable>
<!-- Don't use SDK's trimming functionality.
TODO: Remove this once we build using preview 6 SDK. -->
<_IsTrimmingEnabled>false</_IsTrimmingEnabled>
<!-- Same fix for preview 6 SDK. -->
<_RequiresILLinkPack>false</_RequiresILLinkPack>
<PrepareResourcesDependsOn>_EmbedILLinkXmls;$(PrepareResourcesDependsOn)</PrepareResourcesDependsOn>
<TargetsTriggeredByCompilation Condition="'$(DesignTimeBuild)' != 'true'">$(TargetsTriggeredByCompilation);ILLinkTrimAssembly</TargetsTriggeredByCompilation>
<ILLinkDirectory Condition="'$(ILLinkDirectory)' == ''">$(MSBuildProjectDirectory)\ILLink\</ILLinkDirectory>
<ILLinkTrimAssemblyPath>$(IntermediateOutputPath)$(TargetName)$(TargetExt)</ILLinkTrimAssemblyPath>
<ILLinkTrimAssemblySymbols>$(IntermediateOutputPath)$(TargetName).pdb</ILLinkTrimAssemblySymbols>
<ILLinkTrimInputPath>$(IntermediateOutputPath)PreTrim/</ILLinkTrimInputPath>
<ILLinkTrimInputAssembly>$(ILLinkTrimInputPath)$(TargetName)$(TargetExt)</ILLinkTrimInputAssembly>
<ILLinkTrimInputSymbols>$(ILLinkTrimInputPath)$(TargetName).pdb</ILLinkTrimInputSymbols>
<ILLinkTrimOutputPath>$(IntermediateOutputPath)</ILLinkTrimOutputPath>
<ILLinkDescriptorsXml Condition="'$(ILLinkDescriptorsXml)' == '' and Exists('$(ILLinkDirectory)ILLink.Descriptors.xml')">$(ILLinkDirectory)ILLink.Descriptors.xml</ILLinkDescriptorsXml>
<!-- ILLink.Descriptors.LibraryBuild.xml files are only used during building the library, not an app. They shouldn't be embedded into the assembly. -->
<ILLinkDescriptorsLibraryBuildXml Condition="'$(ILLinkDescriptorsLibraryBuildXml)' == '' and Exists('$(ILLinkDirectory)ILLink.Descriptors.LibraryBuild.xml')">$(ILLinkDirectory)ILLink.Descriptors.LibraryBuild.xml</ILLinkDescriptorsLibraryBuildXml>
<ILLinkDescriptorsXmlIntermediatePath>$(IntermediateOutputPath)ILLink.Descriptors.xml</ILLinkDescriptorsXmlIntermediatePath>
<ILLinkSubstitutionsXmlIntermediatePath>$(IntermediateOutputPath)ILLink.Substitutions.xml</ILLinkSubstitutionsXmlIntermediatePath>
<ILLinkLinkAttributesXmlIntermediatePath>$(IntermediateOutputPath)ILLink.LinkAttributes.xml</ILLinkLinkAttributesXmlIntermediatePath>
<ILLinkSuppressionsXmlFilePrefix>$(ILLinkDirectory)ILLink.Suppressions</ILLinkSuppressionsXmlFilePrefix>
<ILLinkSuppressionsXmlFile>$(ILLinkSuppressionsXmlFilePrefix).xml</ILLinkSuppressionsXmlFile>
<ILLinkSuppressionsConfigurationSpecificXmlFile>$(ILLinkSuppressionsXmlFilePrefix).$(Configuration).xml</ILLinkSuppressionsConfigurationSpecificXmlFile>
<ILLinkSuppressionsLibraryBuildXmlFile>$(ILLinkSuppressionsXmlFilePrefix).LibraryBuild.xml</ILLinkSuppressionsLibraryBuildXmlFile>
<!-- Only run the trim analyzer on libraries which have been annotated. -->
<EnableTrimAnalyzer Condition="'$(EnableTrimAnalyzer)' == '' And (Exists('$(ILLinkSuppressionsXmlFile)') Or Exists('$(ILLinkSuppressionsConfigurationSpecificXmlFile)'))">false</EnableTrimAnalyzer>
<!-- if building a PDB, tell illink to rewrite the symbols file -->
<ILLinkRewritePDBs Condition="'$(ILLinkRewritePDBs)' == '' and '$(DebugSymbols)' != 'false'">true</ILLinkRewritePDBs>
<ILLinkResourcesSubstitutionIntermediatePath>$(IntermediateOutputPath)ILLink.Resources.Substitutions.xml</ILLinkResourcesSubstitutionIntermediatePath>
<GenerateResourcesSubstitutions Condition="'$(GenerateResourcesSubstitutions)' == '' and '$(StringResourcesPath)' != ''">true</GenerateResourcesSubstitutions>
</PropertyGroup>
<ItemGroup>
<ILLinkSuppressionsXmls Include="$(ILLinkSuppressionsXmlFile)"
Condition="Exists('$(ILLinkSuppressionsXmlFile)')" />
<ILLinkSuppressionsXmls Include="$(ILLinkSuppressionsConfigurationSpecificXmlFile)"
Condition="Exists('$(ILLinkSuppressionsConfigurationSpecificXmlFile)')" />
<ILLinkSuppressionsXmls Include="$(ILLinkSuppressionsLibraryBuildXmlFile)"
Condition="Exists('$(ILLinkSuppressionsLibraryBuildXmlFile)')" />
<ILLinkSuppressionsXmls Update="@(ILLinkSuppressionsXmls)"
TargetPath="%(FileName).$(AssemblyName).xml" />
</ItemGroup>
<ItemGroup>
<ILLinkSubstitutionsXmls Include="$(ILLinkResourcesSubstitutionIntermediatePath)"
Condition="'$(GenerateResourcesSubstitutions)' == 'true'" />
<None Include="@(ILLinkSubstitutionsXmls)" />
<None Include="$(ILLinkDescriptorsLibraryBuildXml)"
Condition="'$(ILLinkDescriptorsLibraryBuildXml)' != ''" />
</ItemGroup>
<!-- Flow the IsTrimmable property down to consuming projects, in order for oob.proj
to exclude non trimmable assemblies. -->
<ItemDefinitionGroup>
<TargetPathWithTargetPlatformMoniker>
<IsTrimmable>$(IsTrimmable)</IsTrimmable>
</TargetPathWithTargetPlatformMoniker>
</ItemDefinitionGroup>
<!-- Flow the ILLinkSuppressionsXmls item list down to consuming projects, in order for sfx.proj and oob.proj to
receive the suppression files. -->
<Target Name="AnnotateTargetPathWithILLinkSuppressionsXmlsProp"
AfterTargets="GetTargetPathWithTargetPlatformMoniker">
<ItemGroup>
<TargetPathWithTargetPlatformMoniker ILLinkSuppressionsXmls="@(ILLinkSuppressionsXmls->Metadata('FullPath'))" />
</ItemGroup>
</Target>
<Target Name="_EmbedILLinkXmls"
DependsOnTargets="_CombineILLinkDescriptorsXmls;
_CombineILLinkSubstitutionsXmls;
_CombineILLinkLinkAttributesXmls">
<ItemGroup>
<EmbeddedResource Include="$(ILLinkDescriptorsXml)"
LogicalName="ILLink.Descriptors.xml"
Condition="'$(ILLinkDescriptorsXml)' != ''" />
<EmbeddedResource Include="$(ILLinkSubstitutionsXml)"
LogicalName="ILLink.Substitutions.xml"
Condition="'$(ILLinkSubstitutionsXml)' != ''" />
<EmbeddedResource Include="$(ILLinkLinkAttributesXml)"
LogicalName="ILLink.LinkAttributes.xml"
Condition="'$(ILLinkLinkAttributesXml)' != ''" />
</ItemGroup>
</Target>
<UsingTask TaskName="CombineLinkerXmlFiles" AssemblyFile="$(ILLinkTasksAssembly)" Condition="'$(ILLinkTasksAssembly)' != ''" />
<Target Name="_CombineILLinkDescriptorsXmls"
Condition="'@(ILLinkDescriptorsXmls)' != ''"
Inputs="@(ILLinkDescriptorsXmls)"
Outputs="$(ILLinkDescriptorsXmlIntermediatePath)">
<PropertyGroup>
<ILLinkDescriptorsXml>$(ILLinkDescriptorsXmlIntermediatePath)</ILLinkDescriptorsXml>
</PropertyGroup>
<CombineLinkerXmlFiles LinkerXmlFiles="@(ILLinkDescriptorsXmls)"
CombinedLinkerXmlFile="$(ILLinkDescriptorsXml)" />
<ItemGroup>
<FileWrites Include="$(ILLinkDescriptorsXml)" />
</ItemGroup>
</Target>
<!-- If a library uses string resources, the following target generates a substitution xml that will be embedded on the
library so that if a consumer wants to run the linker they can specify a feature switch to strip out all resources
from the assembly. -->
<Target Name="GenerateResourcesSubstitutionFile"
Condition="'$(GenerateResourcesSubstitutions)' == 'true'"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(ILLinkResourcesSubstitutionIntermediatePath)">
<PropertyGroup>
<ILLinkResourcesSubstitutionTemplate>$(MSBuildThisFileDirectory)ILLink.Substitutions.Resources.template</ILLinkResourcesSubstitutionTemplate>
</PropertyGroup>
<WriteLinesToFile File="$(ILLinkResourcesSubstitutionIntermediatePath)"
Lines="$([System.IO.File]::ReadAllText('$(ILLinkResourcesSubstitutionTemplate)')
.Replace('{AssemblyName}', '$(AssemblyName)')
.Replace('{StringResourcesName}', '$(StringResourcesName)'))"
Overwrite="true" />
<ItemGroup>
<FileWrites Include="$(ILLinkResourcesSubstitutionIntermediatePath)" />
</ItemGroup>
</Target>
<Target Name="_CombineILLinkSubstitutionsXmls"
DependsOnTargets="GenerateResourcesSubstitutionFile"
Condition="'@(ILLinkSubstitutionsXmls)' != ''"
Inputs="@(ILLinkSubstitutionsXmls)"
Outputs="$(ILLinkSubstitutionsXmlIntermediatePath)">
<PropertyGroup>
<ILLinkSubstitutionsXml>$(ILLinkSubstitutionsXmlIntermediatePath)</ILLinkSubstitutionsXml>
</PropertyGroup>
<CombineLinkerXmlFiles LinkerXmlFiles="@(ILLinkSubstitutionsXmls)"
CombinedLinkerXmlFile="$(ILLinkSubstitutionsXml)" />
<ItemGroup>
<FileWrites Include="$(ILLinkSubstitutionsXml)" />
</ItemGroup>
</Target>
<Target Name="_CombineILLinkLinkAttributesXmls"
Condition="'@(ILLinkLinkAttributesXmls)' != ''"
Inputs="@(ILLinkLinkAttributesXmls)"
Outputs="$(ILLinkLinkAttributesXmlIntermediatePath)">
<PropertyGroup>
<ILLinkLinkAttributesXml>$(ILLinkLinkAttributesXmlIntermediatePath)</ILLinkLinkAttributesXml>
</PropertyGroup>
<CombineLinkerXmlFiles LinkerXmlFiles="@(ILLinkLinkAttributesXmls)"
CombinedLinkerXmlFile="$(ILLinkLinkAttributesXml)" />
<ItemGroup>
<FileWrites Include="$(ILLinkLinkAttributesXml)" />
</ItemGroup>
</Target>
<Target Name="PrepareForAssembliesTrim">
<!-- ILLink.Tasks arguments common to runs for both individual libraries and for the entire runtime pack -->
<PropertyGroup>
<!-- don't remove attributes after build, our tooling is not ready for that -->
<ILLinkArgs>$(ILLinkArgs) --ignore-link-attributes true</ILLinkArgs>
<!-- ignore unresolved references -->
<ILLinkArgs>$(ILLinkArgs) --skip-unresolved true</ILLinkArgs>
</PropertyGroup>
<!-- When running from Desktop MSBuild, DOTNET_HOST_PATH is not set.
In this case, explicitly specify the path to the dotnet host. -->
<PropertyGroup Condition="'$(DOTNET_HOST_PATH)' == ''">
<!-- This is defined when building in Visual Studio. -->
<_DotNetHostDirectory>$(NetCoreRoot)</_DotNetHostDirectory>
<_DotNetHostFileName>$([System.IO.Path]::GetFileName('$(DotNetTool)'))</_DotNetHostFileName>
</PropertyGroup>
</Target>
<!-- Examines the "input assembly" for IL that is unreachable from public API and trims that,
rewriting the assembly to an "output assembly" -->
<UsingTask TaskName="ILLink" AssemblyFile="$(ILLinkTasksAssembly)" Condition="'$(ILLinkTasksAssembly)' != ''" />
<Target Name="ILLinkTrimAssembly"
Condition="'$(ILLinkTrimAssembly)' == 'true'"
DependsOnTargets="PrepareForAssembliesTrim">
<PropertyGroup>
<!-- default action for assemblies with IsTrimmable attribute -->
<ILLinkArgs>$(ILLinkArgs) --trim-mode skip</ILLinkArgs>
<!-- default action for assemblies without IsTrimmable attribute -->
<ILLinkArgs>$(ILLinkArgs) --action skip</ILLinkArgs>
<!-- trim the target assembly -->
<ILLinkArgs>$(ILLinkArgs) --action link $(TargetName)</ILLinkArgs>
<ILLinkArgs Condition="'$(ILLinkRewritePDBs)' == 'true' and Exists('$(ILLinkTrimAssemblySymbols)')">$(ILLinkArgs) -b true</ILLinkArgs>
<!-- pass the non-embedded descriptors xml file on the command line -->
<ILLinkArgs Condition="'$(ILLinkDescriptorsLibraryBuildXml)' != ''">$(ILLinkArgs) -x "$(ILLinkDescriptorsLibraryBuildXml)"</ILLinkArgs>
<ILLinkArgs Condition="'$(ILLinkSubstitutionsLibraryBuildXml)' != ''">$(ILLinkArgs) --substitutions "$(ILLinkSubstitutionsLibraryBuildXml)"</ILLinkArgs>
<!-- suppress warnings with the following codes:
IL2008: Could not find type A specified in resource B
IL2009: Could not find method A in type B specified in resource C
IL2012: Could not find field A in type B specified in resource C
IL2025: Duplicate preserve of A in B
IL2026: Calling A which has B can break functionality when trimming application code. The target method might be removed.
IL2035: Unresolved assembly A in DynamicDependencyAttribute on B
IL2050: P/invoke method A declares a parameter with COM marshalling. Correctness of COM interop
cannot be guaranteed after trimming. Interfaces and interface members might be removed.
-->
<LinkerNoWarn>IL2008;IL2009;IL2012;IL2025;IL2026;IL2035;IL2050</LinkerNoWarn>
<!-- IL2032,IL2055,IL2057-IL2061: Reflection intrinsics with unknown arguments -->
<LinkerNoWarn>$(LinkerNoWarn);IL2032;IL2055;IL2057;IL2058;IL2059;IL2060;IL2061</LinkerNoWarn>
<!-- IL2062-IL2066: Unknown values passed to locations with DynamicallyAccessedMemberTypes -->
<LinkerNoWarn>$(LinkerNoWarn);IL2062;IL2063;IL2064;IL2065;IL2066</LinkerNoWarn>
<!-- IL2067-IL2091: Unsatisfied DynamicallyAccessedMembers requirements -->
<LinkerNoWarn>$(LinkerNoWarn);IL2067;IL2068;IL2069;IL2070;IL2071;IL2072;IL2073;IL2074;IL2075;IL2076;IL2077;IL2078;IL2079;IL2080;IL2081;IL2082;IL2083;IL2084;IL2085;IL2086;IL2087;IL2088;IL2089;IL2090;IL2091</LinkerNoWarn>
<!-- IL2121: Unnecessary UnconditionalSuppressMessage attribute -->
<LinkerNoWarn>$(LinkerNoWarn);IL2121</LinkerNoWarn>
<ILLinkArgs>$(ILLinkArgs) --nowarn $(LinkerNoWarn)</ILLinkArgs>
<ILLinkArgs Condition="'$(ILLinkDisableIPConstProp)' == 'true'">$(ILLinkArgs) --disable-opt ipconstprop</ILLinkArgs>
</PropertyGroup>
<!-- Move the assembly into a subdirectory for ILLink -->
<Move SourceFiles="$(ILLinkTrimAssemblyPath)"
DestinationFolder="$(ILLinkTrimInputPath)">
<Output TaskParameter="MovedFiles" ItemName="FileWrites" />
</Move>
<!-- Move the PDB into a subdirectory for ILLink if we are rewriting PDBs -->
<Move SourceFiles="$(ILLinkTrimAssemblySymbols)"
DestinationFolder="$(ILLinkTrimInputPath)"
Condition="'$(ILLinkRewritePDBs)' == 'true' and Exists('$(ILLinkTrimAssemblySymbols)')">
<Output TaskParameter="MovedFiles" ItemName="FileWrites" />
</Move>
<ItemGroup>
<_DependencyDirectoriesTemp Include="@(ReferencePathWithRefAssemblies->'%(RootDir)%(Directory)')" />
<!-- Remove duplicate directories by batching over them -->
<!-- Add project references first to give precedence to project-specific files -->
<_DependencyDirectories Condition="'%(_DependencyDirectoriesTemp.ReferenceSourceTarget)'=='ProjectReference'" Include="%(_DependencyDirectoriesTemp.Identity)" />
<_DependencyDirectories Condition="'%(_DependencyDirectoriesTemp.ReferenceSourceTarget)'!='ProjectReference'" Include="%(_DependencyDirectoriesTemp.Identity)" />
<!-- Remove trailing slash to work around response file parsing behavior -->
<_DependencyDirectoriesSlash Include="@(_DependencyDirectories)">
<PathWithSlash>$([MSBuild]::EnsureTrailingSlash('%(Identity)'))</PathWithSlash>
</_DependencyDirectoriesSlash>
<_DependencyDirectoriesNoSlash Include="@(_DependencyDirectoriesSlash)">
<PathWithoutSlash>$([System.String]::new('%(PathWithSlash)').TrimEnd($([System.IO.Path]::DirectorySeparatorChar)))</PathWithoutSlash>
</_DependencyDirectoriesNoSlash>
<_DependencyDirectories Remove="@(_DependencyDirectories)" />
<_DependencyDirectories Include="%(_DependencyDirectoriesNoSlash.PathWithoutSlash)" />
<ILLinkTrimInputAssembly Include="$(ILLinkTrimInputPath)$(TargetName)$(TargetExt)">
<RootMode>library</RootMode>
</ILLinkTrimInputAssembly>
</ItemGroup>
<PropertyGroup>
<ILLinkArgs Condition="@(_DependencyDirectories->Count()) > 0">$(ILLinkArgs) -d @(_DependencyDirectories->'"%(Identity)"', ' -d ')</ILLinkArgs>
</PropertyGroup>
<ILLink AssemblyPaths=""
RootAssemblyNames="@(ILLinkTrimInputAssembly)"
OutputDirectory="$(ILLinkTrimOutputPath)"
ExtraArgs="$(ILLinkArgs)"
ToolExe="$(_DotNetHostFileName)"
ToolPath="$(_DotNetHostDirectory)" />
</Target>
<!-- ILLink reporting.
Only enabled when developer specifies a path to the AsmDiff tool with property AsmDiffCmd.
EG: AsmDiffCmd=d:\tools\asmdiff\asmdiff.exe
This is necessary until the AsmDiff tool is ported to .NET Core. -->
<Target Name="_CreateILLinkTrimAssemblyReports"
AfterTargets="ILLinkTrimAssembly"
Condition="'$(AsmDiffCmd)' != ''">
<PropertyGroup>
<AsmDiffArgs>$(AsmDiffArgs) $(ILLinkTrimInputAssembly)</AsmDiffArgs>
<AsmDiffArgs>$(AsmDiffArgs) $(ILLinkTrimAssemblyPath)</AsmDiffArgs>
<AsmDiffArgs>$(AsmDiffArgs) -includePrivateApis -includeInternalApis -alwaysDiffMembers -diffAttributes</AsmDiffArgs>
<AsmDiffReport>$(IntermediateOutputPath)$(TargetName).diff.html</AsmDiffReport>
<AsmDiffReportArgs>$(AsmDiffArgs) -out:$(AsmDiffReport)</AsmDiffReportArgs>
<AsmDiffReportArgs>$(AsmDiffReportArgs) -unchanged -changed -added -removed</AsmDiffReportArgs>
<AsmDiffList>$(IntermediateOutputPath)$(TargetName).diff.csv</AsmDiffList>
<AsmDiffListArgs>$(AsmDiffArgs) -out:$(AsmDiffList)</AsmDiffListArgs>
<AsmDiffListArgs>$(AsmDiffListArgs) -unchanged -changed -added -removed </AsmDiffListArgs>
<AsmDiffListArgs>$(AsmDiffListArgs) -diffWriter:CSV</AsmDiffListArgs>
</PropertyGroup>
<Exec Command="$(AsmDiffCmd) $(AsmDiffReportArgs)" />
<Message Text="Assembly trimming diff: $(AsmDiffReport)" />
<Exec Command="$(AsmDiffCmd) $(AsmDiffListArgs)" />
<Message Text="Assembly trimming report: $(AsmDiffList)" />
</Target>
</Project>