|
139 | 139 | </UsingTask>
|
140 | 140 |
|
141 | 141 | <Target Name="SilkShippingControl" BeforeTargets="BeforeBuild">
|
| 142 | + <!-- Non-C# packages (i.e. metapackages, natives) --> |
| 143 | + <PropertyGroup Condition="'$(SilkNativePackage)' == 'true' or '$(SilkMetapackage)' == 'true'"> |
| 144 | + <IncludeBuildOutput Condition="'$(SilkNativeHasAndroidJars)' != 'true'">false</IncludeBuildOutput> |
| 145 | + <IncludeBuildOutput Condition="'$(TargetFramework)' != ''">false</IncludeBuildOutput> |
| 146 | + <IncludeBuildOutput Condition="'$(SilkNativeHasAndroidJars)' == 'true' and $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">true</IncludeBuildOutput> |
| 147 | + <NoWarn>NU5128;1591;$(NoWarn)</NoWarn> |
| 148 | + <GenerateDocumentationFile>false</GenerateDocumentationFile> |
| 149 | + </PropertyGroup> |
| 150 | + |
142 | 151 | <!-- Public API -->
|
143 | 152 | <PropertyGroup Condition="'$(SilkTrackPublicAPI)' != 'true' or '$(TargetFramework)' == ''">
|
144 | 153 | <SilkTrackPublicAPI>false</SilkTrackPublicAPI>
|
145 | 154 | </PropertyGroup>
|
146 | 155 | <ItemGroup Condition="'$(SilkTrackPublicAPI)' == 'true'">
|
147 | 156 | <PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" PrivateAssets="All" />
|
148 | 157 | </ItemGroup>
|
149 |
| - <ItemGroup Condition="'$(SilkSourceLinkExempt)' == ''"> |
| 158 | + |
| 159 | + <!-- SourceLink --> |
| 160 | + <ItemGroup Condition="'$(SilkSourceLinkExempt)' == '' and '$(SilkNativePackage)' != 'true' and '$(SilkMetapackage)' != 'true'"> |
150 | 161 | <PackageReference Include="DotNet.ReproducibleBuilds" PrivateAssets="All"/>
|
151 | 162 | <PackageReference Include="DotNet.ReproducibleBuilds.Isolated" PrivateAssets="All"/>
|
152 | 163 | </ItemGroup>
|
|
161 | 172 | <WriteLinesToFile File="PublicAPI/$(TargetFramework)/PublicAPI.Unshipped.txt"
|
162 | 173 | Lines="@(SilkNewPublicAPILines)"
|
163 | 174 | Condition="'$(SilkTrackPublicAPI)' == 'true' and !Exists('PublicAPI/$(TargetFramework)/PublicAPI.Unshipped.txt')" />
|
| 175 | + |
164 | 176 | <!-- Versioning -->
|
165 | 177 | <PropertyGroup>
|
166 | 178 | <SilkChangelog>$([System.IO.File]::ReadAllText("$(MSBuildThisFileDirectory)docs/CHANGELOG.md"))</SilkChangelog>
|
|
171 | 183 | <Output PropertyName="SilkReleaseNotes" TaskParameter="SilkReleaseNotes" />
|
172 | 184 | </SilkGetVersionInfoTask>
|
173 | 185 | <PropertyGroup>
|
| 186 | + <SilkOriginalVersionSuffix>$(VersionSuffix)</SilkOriginalVersionSuffix> |
174 | 187 | <Version>$(SilkVersion)</Version>
|
175 | 188 | <VersionSuffix Condition="'$(VersionSuffix)' == ''">$(SilkVersionSuffix)</VersionSuffix>
|
176 | 189 | <PackageReleaseNotes>$(SilkReleaseNotes)</PackageReleaseNotes>
|
177 | 190 | <PackageVersion Condition="'$(VersionSuffix)' == ''">$(SilkVersion)</PackageVersion>
|
178 | 191 | <PackageVersion Condition="'$(VersionSuffix)' != ''">$(SilkVersion)-$(VersionSuffix)</PackageVersion>
|
179 | 192 | </PropertyGroup>
|
180 |
| - <!-- Trimming --> |
| 193 | + |
| 194 | + <!-- Native Packaging --> |
181 | 195 | <PropertyGroup>
|
182 |
| - <IsTrimmable Condition="'$(SilkTrimmingExempt)' == ''">true</IsTrimmable> |
183 |
| - <EnableTrimAnalyzer Condition="'$(SilkTrimmingExempt)' == ''">true</EnableTrimAnalyzer> |
184 |
| - <EnableAotAnalyzer Condition="'$(SilkTrimmingExempt)' == ''">true</EnableAotAnalyzer> |
185 |
| - <EnableSingleFileAnalyzer Condition="'$(SilkTrimmingExempt)' == ''">true</EnableSingleFileAnalyzer> |
186 |
| - <TrimMode Condition="'$(SilkTrimmingExempt)' == ''">full</TrimMode> |
| 196 | + <SilkVersionTxtPath>$(MSBuildProjectDirectory)/version.txt</SilkVersionTxtPath> |
| 197 | + <PackageVersion Condition="Exists('$(SilkVersionTxtPath)')">$([System.IO.File]::ReadAllText("$(SilkVersionTxtPath)").Trim())</PackageVersion> |
| 198 | + <PackageVersion Condition="'$(SilkOriginalVersionSuffix)' != '' and Exists('$(SilkVersionTxtPath)') and $(PackageVersion.Contains('-'))">$(PackageVersion)$(SilkOriginalVersionSuffix)</PackageVersion> |
| 199 | + <PackageVersion Condition="'$(SilkOriginalVersionSuffix)' != '' and Exists('$(SilkVersionTxtPath)') and !$(PackageVersion.Contains('-'))">$(PackageVersion)-$(SilkOriginalVersionSuffix)</PackageVersion> |
187 | 200 | </PropertyGroup>
|
| 201 | + <Error Text="Native packages should have a version.txt file! Read documentation/for-contributors/build-system.md for more info." |
| 202 | + Condition="'$(SilkNativePackage)' == 'true' and !Exists('$(SilkVersionTxtPath)')" /> |
| 203 | + <ItemGroup Condition="'$(SilkNativePackage)' == 'true'"> |
| 204 | + <None Include="$(MSBuildProjectDirectory)/runtimes/**/*" Pack="true" PackagePath="runtimes" /> |
| 205 | + <!-- bundled in the aar instead --> |
| 206 | + <None Remove="$(MSBuildProjectDirectory)/runtimes/android*/**/*" Condition="'$(SilkNativeHasAndroidJars)' == 'true'" /> |
| 207 | + </ItemGroup> |
| 208 | + <ItemGroup Condition="'$(SilkNativePackage)' == 'true' and $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'"> |
| 209 | + <AndroidNativeLibrary Include="$(MSBuildProjectDirectory)/runtimes/android*/native/*.so" /> |
| 210 | + <ProguardConfiguration Include="$(MSBuildProjectDirectory)/android/proguard.txt" Condition="Exists('$(MSBuildProjectDirectory)/android/proguard.txt')" /> |
| 211 | + <AndroidLibrary Include="$(MSBuildProjectDirectory)/android/*.jar" Bind="true" Pack="true" /> |
| 212 | + <TransformFile Include="$(MSBuildProjectDirectory)/android/*.xml" /> |
| 213 | + </ItemGroup> |
| 214 | + |
| 215 | + <!-- Trimming --> |
| 216 | + <PropertyGroup Condition="'$(SilkTrimmingExempt)' == ''"> |
| 217 | + <IsTrimmable>true</IsTrimmable> |
| 218 | + <EnableTrimAnalyzer>true</EnableTrimAnalyzer> |
| 219 | + <EnableAotAnalyzer>true</EnableAotAnalyzer> |
| 220 | + <EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer> |
| 221 | + <TrimMode>full</TrimMode> |
| 222 | + </PropertyGroup> |
| 223 | + </Target> |
| 224 | + |
| 225 | + |
| 226 | + <!-- Closest things to documentation on what the hell this voodoo does: |
| 227 | + https://github.com/NuGet/Home/issues/10063#issuecomment-713083004 |
| 228 | + https://github.com/xamarin/xamarin-android/pull/5242 |
| 229 | + https://github.com/dotnet/sdk/issues/14042 |
| 230 | + https://github.com/dotnet/sdk/blob/main/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.PackTool.targets#L54 |
| 231 | + https://github.com/xamarin/xamarin-android/issues/5957 |
| 232 | + https://github.com/xamarin/xamarin-android/blob/main/Documentation/guides/OneDotNetEmbeddedResources.md |
| 233 | +
|
| 234 | + This is an adaptation of what we used in Silk.NET 2.X to add files to packages, which was originally focused on |
| 235 | + Android. For 3.0, we're trying to lean as much as possible on the built-in stuff for e.g. jars as this is in a |
| 236 | + much better state these days. However, some of the links above may only be relevant with that context. --> |
| 237 | + <Target Name="SilkNativePackaging" Condition="'$(SilkNativePackage)' == 'true'"> |
| 238 | + <GetNuGetShortFolderName TargetFrameworkMoniker="$(TargetFrameworkMoniker)" TargetPlatformMoniker="$(TargetPlatformMoniker)"> |
| 239 | + <Output TaskParameter="NuGetShortFolderName" PropertyName="SilkNuGetShortFolderName" /> |
| 240 | + </GetNuGetShortFolderName> |
| 241 | + <ReadLinesFromFile File="$(MSBuildThisFileDirectory)eng/native/nuget/NativeNuGetPackage.targets"> |
| 242 | + <Output TaskParameter="Lines" ItemName="SilkNativeNuGetPackageTargets" /> |
| 243 | + </ReadLinesFromFile> |
| 244 | + <WriteLinesToFile File="$(IntermediateOutputPath)$(TargetFramework)/$(MSBuildProjectName).targets" |
| 245 | + Lines="@(SilkNativeNuGetPackageTargets->'%(Identity)'->Replace('TO_BE_REPLACED_MTOUCH_NATIVE_REFERENCE_LINKER_FLAGS', '$(SilkNativeiOSLinkerFlags)')->Replace('TO_BE_REPLACED_PROPERTY_PREFIX', '$(MSBuildProjectName.Replace('.', '_'))'))" /> |
| 246 | + <WriteLinesToFile File="$(IntermediateOutputPath)$(TargetFramework)/_._" Lines="@(SilkDummyItem)" /> |
| 247 | + <ItemGroup> |
| 248 | + <TfmSpecificPackageFile Include="$(IntermediateOutputPath)$(TargetFramework)/$(MSBuildProjectName).targets" |
| 249 | + Link="build/$(SilkNuGetShortFolderName)/$(MSBuildProjectName).targets" |
| 250 | + Pack="true" |
| 251 | + PackagePath="build/$(SilkNuGetShortFolderName)/$(MSBuildProjectName).targets" /> |
| 252 | + <TfmSpecificPackageFile Include="$(IntermediateOutputPath)$(TargetFramework)/$(MSBuildProjectName).targets" |
| 253 | + Link="build/$(SilkNuGetShortFolderName)/$(MSBuildProjectName).targets" |
| 254 | + Pack="true" |
| 255 | + PackagePath="buildTransitive/$(SilkNuGetShortFolderName)/$(MSBuildProjectName).targets" /> |
| 256 | + <TfmSpecificPackageFile Include="$(IntermediateOutputPath)$(TargetFramework)/_._" |
| 257 | + Link="lib/$(SilkNuGetShortFolderName)/_._" |
| 258 | + Pack="true" |
| 259 | + PackagePath="lib/$(SilkNuGetShortFolderName)/_._" |
| 260 | + Condition="'$(IncludeBuildOutput)' == 'false'" /> |
| 261 | + </ItemGroup> |
188 | 262 | </Target>
|
189 | 263 | </Project>
|
0 commit comments