-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathStride.Dependencies.targets
More file actions
216 lines (190 loc) · 13.8 KB
/
Copy pathStride.Dependencies.targets
File metadata and controls
216 lines (190 loc) · 13.8 KB
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
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
================================================================
Stride.Dependencies.targets - Native Dependency System (.ssdeps)
================================================================
Manages native libraries and content files that travel alongside
managed assemblies via .ssdeps manifest files.
Two workflows:
1. READING: When referencing assemblies that have .ssdeps files,
reads them and copies native libs/content to output directory.
2. WRITING: When a project declares StrideNativeLib or StrideContent
items, generates a .ssdeps file and copies files to output.
Platform-specific handling:
- Desktop (Windows/Linux/macOS): Native libs copied as None items
- Android: Native libs added as AndroidNativeLibrary
- iOS: Native libs linked via mtouch arguments
================================================================
-->
<PropertyGroup>
<AllowedOutputExtensionsInPackageBuildOutputFolder>.ssdeps; $(AllowedOutputExtensionsInPackageBuildOutputFolder)</AllowedOutputExtensionsInPackageBuildOutputFolder>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);_StrideRegisterDependenciesOutputs</TargetsForTfmSpecificBuildOutput>
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);_StrideRegisterPackageFiles</TargetsForTfmSpecificContentInPackage>
</PropertyGroup>
<!-- ================================================================ -->
<!-- Dependencies reading (from .ssdeps) -->
<!-- ================================================================ -->
<!-- List dependency files from .ssdeps -->
<!-- When the current build targets a specific StrideGraphicsApi, drop candidate paths whose
parent directory is a non-current API folder. Otherwise a non-API-dependent middle project
(say Stride.Engine, built with default API=Direct3D11) re-exports its CopyLocal'd
Stride.Graphics.ssdeps through the reference graph, and the direct API-dependent reference
also provides one — both land on the same filename in the output folder and race. -->
<Target Name="_StrideListDepsFiles" DependsOnTargets="ResolveAssemblyReferences">
<ItemGroup>
<_StrideDepsFile Include="@(ReferencePath->'%(RootDir)%(Directory)%(Filename).ssdeps')" Condition="'%(ReferencePath.CopyLocal)' != 'false' And Exists('%(RootDir)%(Directory)%(Filename).ssdeps')"/>
<_StrideDepsFile Include="@(ReferenceDependencyPaths->'%(RootDir)%(Directory)%(Filename).ssdeps')" Condition="'%(ReferenceDependencyPaths.CopyLocal)' != 'false' And Exists('%(RootDir)%(Directory)%(Filename).ssdeps')"/>
</ItemGroup>
<ItemGroup Condition="'$(StrideGraphicsApi)' != ''">
<_StrideDepsFile Remove="@(_StrideDepsFile)" Condition="$([System.String]::Copy('%(Identity)').Contains('\Direct3D11\')) And '$(StrideGraphicsApi)' != 'Direct3D11'" />
<_StrideDepsFile Remove="@(_StrideDepsFile)" Condition="$([System.String]::Copy('%(Identity)').Contains('\Direct3D12\')) And '$(StrideGraphicsApi)' != 'Direct3D12'" />
<_StrideDepsFile Remove="@(_StrideDepsFile)" Condition="$([System.String]::Copy('%(Identity)').Contains('\Vulkan\')) And '$(StrideGraphicsApi)' != 'Vulkan'" />
<_StrideDepsFile Remove="@(_StrideDepsFile)" Condition="$([System.String]::Copy('%(Identity)').Contains('\OpenGL\')) And '$(StrideGraphicsApi)' != 'OpenGL'" />
<_StrideDepsFile Remove="@(_StrideDepsFile)" Condition="$([System.String]::Copy('%(Identity)').Contains('\OpenGLES\')) And '$(StrideGraphicsApi)' != 'OpenGLES'" />
</ItemGroup>
<ItemGroup>
<None Include="@(_StrideDepsFile)" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Target>
<!-- Filter transitive CopyToOutput items coming from non-API-dependent project references.
They would otherwise pull the default-API variant (e.g. Direct3D11) of API-dependent
side files (Stride.Graphics.ssdeps, Stride.VirtualReality.ssdeps, and the native libs
they manifest) through the reference graph, colliding in the consumer's output folder
with the direct API-dependent reference's correct variant. -->
<Target Name="_StrideFilterTransitiveCopyToOutputDirectoryItems"
BeforeTargets="_CopyOutOfDateSourceItemsToOutputDirectory;_CopyOutOfDateSourceItemsToOutputDirectoryAlways"
DependsOnTargets="GetCopyToOutputDirectoryItems"
Condition="'$(StrideGraphicsApi)' != ''">
<ItemGroup>
<_SourceItemsToCopyToOutputDirectory Remove="@(_SourceItemsToCopyToOutputDirectory)" Condition="$([System.String]::Copy('%(Identity)').Contains('\Direct3D11\')) And '$(StrideGraphicsApi)' != 'Direct3D11'" />
<_SourceItemsToCopyToOutputDirectory Remove="@(_SourceItemsToCopyToOutputDirectory)" Condition="$([System.String]::Copy('%(Identity)').Contains('\Direct3D12\')) And '$(StrideGraphicsApi)' != 'Direct3D12'" />
<_SourceItemsToCopyToOutputDirectory Remove="@(_SourceItemsToCopyToOutputDirectory)" Condition="$([System.String]::Copy('%(Identity)').Contains('\Vulkan\')) And '$(StrideGraphicsApi)' != 'Vulkan'" />
<_SourceItemsToCopyToOutputDirectory Remove="@(_SourceItemsToCopyToOutputDirectory)" Condition="$([System.String]::Copy('%(Identity)').Contains('\OpenGL\')) And '$(StrideGraphicsApi)' != 'OpenGL'" />
<_SourceItemsToCopyToOutputDirectory Remove="@(_SourceItemsToCopyToOutputDirectory)" Condition="$([System.String]::Copy('%(Identity)').Contains('\OpenGLES\')) And '$(StrideGraphicsApi)' != 'OpenGLES'" />
</ItemGroup>
</Target>
<!-- Note: this target Outputs are not real, used so that it gets expanded for each file
also, if _StrideDepsFile is empty the target is still called so check for it -->
<Target Name="_StrideBuildDependencies" DependsOnTargets="_StrideListDepsFiles" Outputs="%(_StrideDepsFile.Identity)">
<!-- Read dependencies from file -->
<ReadLinesFromFile File="%(_StrideDepsFile.Identity)" Condition="'%(_StrideDepsFile.Identity)' != ''">
<Output TaskParameter="Lines" ItemName="_StrideDependencyLocal"/>
</ReadLinesFromFile>
<PropertyGroup>
<_StrideSourceDir>%(_StrideDepsFile.RootDir)%(_StrideDepsFile.Directory)</_StrideSourceDir>
</PropertyGroup>
<ItemGroup>
<_StrideDependencyLocal>
<!-- Note: Using regex match rather than regex split or string split to avoid MSBuild MissingMethodException -->
<Type>$([System.Text.RegularExpressions.Regex]::Match('%(Identity)', `(.*);(.*);(.*)`).get_Groups().get_Item(1).ToString())</Type>
<SourcePath>$([System.Text.RegularExpressions.Regex]::Match('%(Identity)', `(.*);(.*);(.*)`).get_Groups().get_Item(2).ToString())</SourcePath>
<Link>$([System.Text.RegularExpressions.Regex]::Match('%(Identity)', `(.*);(.*);(.*)`).get_Groups().get_Item(3).ToString())</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</_StrideDependencyLocal>
<_StrideDependencyContent Include="@(_StrideDependencyLocal->'$(_StrideSourceDir)%(SourcePath)')" Condition="'%(_StrideDependencyLocal.Type)' == 'Content'"/>
<_StrideDependencyNativeLib Include="@(_StrideDependencyLocal->'$(_StrideSourceDir)%(SourcePath)')" Condition="'%(_StrideDependencyLocal.Type)' == 'NativeLib'"/>
</ItemGroup>
<!-- Message -->
<Message Importance="Normal" Text="Detected dependency from %(_StrideDepsFile.FileName)" Condition="'%(_StrideDepsFile.Identity)' != ''"/>
<Message Importance="Normal" Text=" %(_StrideDependencyLocal.Type): %(_StrideDependencyLocal.Identity) => %(_StrideDependencyLocal.Link)"/>
<!-- Cleanup so that _StrideDependencyLocal is local -->
<ItemGroup>
<_StrideDependencyLocal Remove="@(_StrideDependencyLocal)"/>
</ItemGroup>
</Target>
<Target Name="_StrideCopyContent" DependsOnTargets="_StrideBuildDependencies" AfterTargets="ResolveAssemblyReferences" Condition="'$(StrideDependenciesCopy)' != 'false'">
<ItemGroup>
<Content Include="@(_StrideDependencyContent)" Pack="False"/>
</ItemGroup>
</Target>
<!-- ================================================================ -->
<!-- Native libraries setup (from .ssdeps) -->
<!-- ================================================================ -->
<Target Name="_StrideSetupNativeLibraries" DependsOnTargets="_StrideBuildDependencies" AfterTargets="ResolveAssemblyReferences" Condition="'$(StrideDependenciesCopy)' != 'false'">
<!-- Windows, Linux, macOS -->
<ItemGroup Condition=" '$(TargetFramework)' == '$(StrideFramework)' Or '$(TargetFramework)' == '$(StrideFrameworkWindows)' ">
<None Include="@(_StrideDependencyNativeLib)">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<!-- Android -->
<ItemGroup Condition=" '$(TargetFramework)' == '$(StrideFrameworkAndroid)' ">
<AndroidNativeLibrary Include="@(_StrideDependencyNativeLib)"/>
</ItemGroup>
<!-- iOS -->
<ItemGroup Condition=" '$(TargetFramework)' == '$(StrideFrameworkiOS)' ">
<!-- strip any "lib" prefix and populate the LibraryName value -->
<_StrideDependencyNativeLib>
<LibraryName>$([System.Text.RegularExpressions.Regex]::Match('%(Filename)', `(lib)*(.+)`).get_Groups().get_Item(2).ToString())</LibraryName>
</_StrideDependencyNativeLib>
<None Include="@(_StrideDependencyNativeLib)">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == '$(StrideFrameworkiOS)' ">
<MtouchExtraArgsLibs>$(StrideMTouchExtras) -L"%24{ProjectDir}" @(_StrideDependencyNativeLib->'-l%(LibraryName) "%24{ProjectDir}/%(Filename)%(Extension)"',' ')</MtouchExtraArgsLibs>
<MtouchExtraArgs>$(MtouchExtraArgs) --compiler=clang -cxx -gcc_flags '-lstdc++ $(MtouchExtraArgsLibs)'</MtouchExtraArgs>
</PropertyGroup>
</Target>
<!-- ================================================================ -->
<!-- Dependencies generation (to .ssdeps) -->
<!-- ================================================================ -->
<Target Name="_StrideGenerateDependenciesCore">
<!-- Set TargetPath on StrideContent and StrideNativeLib -->
<AssignTargetPath RootFolder="$(OutputPath)" Files="@(StrideContent)">
<Output TaskParameter="AssignedFiles" ItemName="_StrideContentAssigned"/>
</AssignTargetPath>
<AssignTargetPath RootFolder="$(OutputPath)" Files="@(StrideNativeLib)">
<Output TaskParameter="AssignedFiles" ItemName="_StrideNativeLibAssigned"/>
</AssignTargetPath>
<!-- Combine into _StrideDependencyToCopy (and add RelativePath and Type) -->
<ItemGroup>
<_StrideDependencyToCopy Include="@(_StrideContentAssigned)">
<RelativePath Condition="'%(_StrideContentAssigned.RelativePath)' == ''">%(TargetPath)</RelativePath>
<Type>Content</Type>
<Destination>$(OutDir)%(TargetPath)</Destination>
</_StrideDependencyToCopy>
<_StrideDependencyToCopy Include="@(_StrideNativeLibAssigned)">
<RelativePath Condition="'%(_StrideNativeLibAssigned.RelativePath)' == ''">%(TargetPath)</RelativePath>
<Type>NativeLib</Type>
<Destination>$(OutDir)%(TargetPath)</Destination>
</_StrideDependencyToCopy>
<_StrideDependencyToCopy Remove="@(_StrideNativeLibAssigned)" Condition=" '$(StridePackageBuild)' == 'true' And '%(_StrideNativeLibAssigned.Extension)' == '.pdb' "/>
</ItemGroup>
<!-- Copy files -->
<Copy
SourceFiles = "@(_StrideDependencyToCopy)"
DestinationFiles = "@(_StrideDependencyToCopy->'%(Destination)')"
OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
Retries="$(CopyRetryCount)"
RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
UseHardlinksIfPossible="$(CreateHardLinksForAdditionalFilesIfPossible)">
<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
</Copy>
<!-- Write file containing list of dependent files (or delete it if nothing) -->
<WriteLinesToFile Condition="'@(_StrideDependencyToCopy)' != ''" File="$(OutputPath)$(TargetName).ssdeps" Lines="@(_StrideDependencyToCopy->'%(Type);%(TargetPath);%(RelativePath)')" Overwrite="true"/>
<Delete Condition="'@(_StrideDependencyToCopy)' == ''" Files="$(OutputPath)$(TargetName).ssdeps"/>
</Target>
<!-- Build -->
<Target Name="_StrideGenerateDependencies" Condition="'$(TargetFramework)' != '' Or '$(StrideProjectType)' == 'Cpp'" DependsOnTargets="_StrideGenerateDependenciesCore" AfterTargets="CopyFilesToOutputDirectory"/>
<!-- Packaging -->
<Target Name="_StrideRegisterDependenciesOutputs" Condition="'$(TargetFramework)' != ''" DependsOnTargets="_StrideGenerateDependenciesCore">
<ItemGroup Condition="'@(_StrideDependencyToCopy)' != ''">
<BuildOutputInPackage Include="$(OutputPath)$(AssemblyName).ssdeps" />
</ItemGroup>
</Target>
<Target Name="_StrideRegisterPackageFiles" Condition="'$(TargetFramework)' != ''" DependsOnTargets="_StrideGenerateDependenciesCore">
<ItemGroup Condition="'@(_StrideDependencyToCopy)' != ''">
<!-- Native dependencies go to the runtimes/RID/native folder -->
<TfmSpecificPackageFile Include="@(_StrideDependencyToCopy)"
Condition=" '%(_StrideDependencyToCopy.Type)' == 'NativeLib' "
PackagePath="%(_StrideDependencyToCopy.TargetPath)" />
<!-- Content goes to contentFiles/any/any (language/tfm) with CopyToOutput=true and BuildAction=None -->
<TfmSpecificPackageFile Include="@(_StrideDependencyToCopy)"
Condition=" '%(_StrideDependencyToCopy.Type)' == 'Content' "
PackagePath="contentFiles/any/any/%(_StrideDependencyToCopy.TargetPath)"
PackageCopyToOutput="true"
BuildAction="None" />
</ItemGroup>
</Target>
</Project>