forked from dotnet/corefx
-
Notifications
You must be signed in to change notification settings - Fork 3
/
illink.targets
151 lines (132 loc) · 7.93 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
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetsTriggeredByCompilation>
$(TargetsTriggeredByCompilation);
_SetILLinkTrimAssembly;
ILLinkTrimAssembly
</TargetsTriggeredByCompilation>
</PropertyGroup>
<!-- Inputs and outputs of ILLinkTrimAssembly -->
<PropertyGroup>
<ILLinkToolPath Condition="'$(ILLinkToolPath)' == ''">$(ToolsDir)ILLink/illink.dll</ILLinkToolPath>
<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>
<ILLinkTrimXml Condition="'$(ILLinkTrimXml)' == '' AND Exists('$(MSBuildProjectDirectory)/ILLinkTrim.xml')">$(MSBuildProjectDirectory)/ILLinkTrim.xml</ILLinkTrimXml>
<!-- if building a PDB, tell illink to rewrite the symbols file -->
<ILLinkRewritePDBs Condition="'$(ILLinkRewritePDBs)' == '' AND '$(DebugSymbols)' != 'false'">true</ILLinkRewritePDBs>
</PropertyGroup>
<!-- Custom binplacing for pre/post-trimming and reports that is useful for analysis
Must be enabled by setting BinPlaceILLinkTrimAssembly=true
-->
<ItemGroup Condition="'$(BinPlaceILLinkTrimAssembly)' == 'true'">
<BinPlaceConfiguration Include="$(BuildConfiguration)">
<RuntimePath>$(BinDir)ILLinkTrimAssembly/$(BuildConfiguration)/trimmed</RuntimePath>
<ItemName>TrimmedItem</ItemName>
</BinPlaceConfiguration>
<BinPlaceConfiguration Include="$(BuildConfiguration)">
<RuntimePath>$(BinDir)ILLinkTrimAssembly/$(BuildConfiguration)/reports</RuntimePath>
<ItemName>TrimmingReport</ItemName>
</BinPlaceConfiguration>
<BinPlaceConfiguration Include="$(BuildConfiguration)">
<RuntimePath>$(BinDir)ILLinkTrimAssembly/$(BuildConfiguration)/pretrimmed</RuntimePath>
<ItemName>PreTrimmedItem</ItemName>
</BinPlaceConfiguration>
</ItemGroup>
<Target Name="_SetILLinkTrimAssembly"
Condition="'$(ILLinkTrimAssembly)' == ''"
DependsOnTargets="GetBinPlaceConfiguration">
<PropertyGroup>
<!-- Currently ILLink cannot handle type projections from Windows.winmd, disable if the project references it -->
<ILLinkTrimAssembly Condition="'%(ReferencePath.FileName)%(ReferencePath.Extension)' == 'Windows.winmd'">false</ILLinkTrimAssembly>
</PropertyGroup>
</Target>
<!-- ILLinkTrimAssembly
Examines the "input assembly" for IL that is unreachable from public API and trims that,
rewriting the assembly to an "output assembly"
-->
<Target Name="ILLinkTrimAssembly" Condition="'$(ILLinkTrimAssembly)' == 'true'" DependsOnTargets="EnsureBuildToolsRuntime">
<ItemGroup>
<!-- currently only directories are supported by ILLink. -->
<_ILLinkReferenceDirectory Include="%(ReferencePath.RootDir)%(ReferencePath.Directory)" />
</ItemGroup>
<PropertyGroup>
<!-- Root public entry points in this assembly.
Currently this must be passed as name and directory.
Directory of this assembly *must* occur before directory of references. -->
<ILLinkArgs>$(ILLinkArgs) -r $(TargetName)</ILLinkArgs>
<ILLinkArgs>$(ILLinkArgs) -d $(ILLinkTrimInputPath)</ILLinkArgs>
<!-- directories to examine for assembly dependencies -->
<ILLinkArgs>$(ILLinkArgs) @(_ILLinkReferenceDirectory->'-d %(Identity)', ' ')</ILLinkArgs>
<!-- don't trim anything that's defined in core assemblies -->
<ILLinkArgs>$(ILLinkArgs) -c skip</ILLinkArgs>
<ILLinkArgs>$(ILLinkArgs) -p skip netstandard</ILLinkArgs>
<!-- keep type-forward assemblies (facades) -->
<ILLinkArgs>$(ILLinkArgs) -t</ILLinkArgs>
<ILLinkArgs>$(ILLinkArgs) -out $(ILLinkTrimOutputPath)</ILLinkArgs>
<ILLinkArgs Condition="'$(ILLinkTrimXml)' != ''">$(ILLinkArgs) -x $(ILLinkTrimXml)</ILLinkArgs>
<ILLinkArgs Condition="'$(ILLinkRewritePDBs)' == 'true' AND Exists('$(ILLinkTrimAssemblySymbols)')">$(ILLinkArgs) -b true</ILLinkArgs>
<!-- keep types and members required by Debugger-related attributes -->
<ILLinkArgs>$(ILLinkArgs) -v true</ILLinkArgs>
<!-- reflection heuristics to apply -->
<ILLinkArgs>$(ILLinkArgs) -h LdtokenTypeMethods,InstanceConstructors</ILLinkArgs>
</PropertyGroup>
<MakeDir Directories="$(ILLinkTrimInputPath)" />
<!-- Move the assembly into a subdirectory for ILLink -->
<Move SourceFiles="$(ILLinkTrimAssemblyPath)"
DestinationFolder="$(ILLinkTrimInputPath)"
/>
<!-- Move the PDB into a subdirectory for ILLink if we are rewriting PDBs -->
<Move SourceFiles="$(ILLinkTrimAssemblySymbols)"
DestinationFolder="$(ILLinkTrimInputPath)"
Condition="'$(ILLinkRewritePDBs)' == 'true' AND Exists('$(ILLinkTrimAssemblySymbols)')"
/>
<PropertyGroup>
<ILLinkCmd>$(OverrideToolHost) "$(ILLinkToolPath)"</ILLinkCmd>
</PropertyGroup>
<Exec Command="$(ILLinkCmd) $(ILLinkArgs)" />
</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>
<!-- Similar to _CheckForCompileOutputs and runs in the same places,
always set these even if compile didn't run. -->
<Target Name="_CheckForILLinkTrimAssemblyOutputs"
BeforeTargets="CopyFilesToOutputDirectory;_CleanGetCurrentAndPriorFileWrites"
Condition="'$(ILLinkTrimAssembly)' == 'true'">
<ItemGroup>
<PreTrimmedItem Condition="Exists('$(ILLinkTrimInputAssembly)')" Include="$(ILLinkTrimInputAssembly)" />
<PreTrimmedItem Condition="'$(ILLinkRewritePDBs)' == 'true' AND Exists('$(ILLinkTrimInputSymbols)')" Include="$(ILLinkTrimInputSymbols)" />
<FileWrites Include="@(PreTrimmedItem)" />
<TrimmedItem Condition="Exists('$(ILLinkTrimAssemblyPath)')" Include="$(ILLinkTrimAssemblyPath)" />
<TrimmedItem Condition="'$(ILLinkRewritePDBs)' == 'true' AND Exists('$(ILLinkTrimAssemblySymbols)')" Include="$(ILLinkTrimAssemblySymbols)" />
<TrimmingReport Condition="Exists('$(AsmDiffReport)')" Include="$(AsmDiffReport)" />
<TrimmingReport Condition="Exists('$(AsmDiffList)')" Include="$(AsmDiffList)" />
</ItemGroup>
</Target>
</Project>