Skip to content

Commit 8cf95c2

Browse files
committed
Include org.libsdl.app bindings with the aar, working package now
1 parent 917d412 commit 8cf95c2

File tree

7 files changed

+124
-2
lines changed

7 files changed

+124
-2
lines changed

Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,6 @@
6464
<PublishRepositoryUrl>true</PublishRepositoryUrl>
6565
<VersionDependsOn>SilkShippingControl;$(VersionDependsOn)</VersionDependsOn>
6666
<PackageVersionDependsOn>SilkShippingControl;$(PackageVersionDependsOn)</PackageVersionDependsOn>
67+
<TargetsForTfmSpecificContentInPackage>SilkNativePackaging;$(TargetsForTfmSpecificContentInPackage)</TargetsForTfmSpecificContentInPackage>
6768
</PropertyGroup>
6869
</Project>

Directory.Build.targets

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@
149149
</PropertyGroup>
150150
<!-- Non-C# packages (i.e. metapackages, natives) -->
151151
<PropertyGroup Condition="'$(SilkNativePackage)' == 'true' or '$(SilkMetapackage)' == 'true'">
152-
<IncludeBuildOutput>false</IncludeBuildOutput>
153-
<NoWarn>NU5128</NoWarn>
152+
<IncludeBuildOutput Condition="'$(SilkNativeHasAndroidJars)' != 'true'">false</IncludeBuildOutput>
153+
<NoWarn>NU5128;$(NoWarn)</NoWarn>
154154
</PropertyGroup>
155155
<!-- Public API -->
156156
<PropertyGroup Condition="'$(SilkTrackPublicAPI)' != 'true' or '$(TargetFramework)' == ''">
@@ -191,6 +191,22 @@
191191
<PackageVersion Condition="'$(VersionSuffix)' == ''">$(SilkVersion)</PackageVersion>
192192
<PackageVersion Condition="'$(VersionSuffix)' != ''">$(SilkVersion)-$(VersionSuffix)</PackageVersion>
193193
</PropertyGroup>
194+
<!-- Native Packaging -->
195+
<PropertyGroup>
196+
<SilkVersionTxtPath>$(MSBuildProjectDirectory)/version.txt</SilkVersionTxtPath>
197+
<PackageVersion Condition="Exists('$(SilkVersionTxtPath)')">$([System.IO.File]::ReadAllText("$(SilkVersionTxtPath)"))</PackageVersion>
198+
</PropertyGroup>
199+
<ItemGroup Condition="'$(SilkNativePackage)' == 'true'">
200+
<None Include="$(MSBuildProjectDirectory)/runtimes/**/*" Pack="true" PackagePath="runtimes" />
201+
<!-- bundled in the aar instead -->
202+
<None Remove="$(MSBuildProjectDirectory)/runtimes/android*/**/*" Condition="'$(SilkNativeHasAndroidJars)' == 'true'" />
203+
</ItemGroup>
204+
<ItemGroup Condition="'$(SilkNativePackage)' == 'true' and $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">
205+
<AndroidNativeLibrary Include="$(MSBuildProjectDirectory)/runtimes/android*/native/*.so" />
206+
<ProguardConfiguration Include="$(MSBuildProjectDirectory)/android/proguard.txt" Condition="Exists('$(MSBuildProjectDirectory)/android/proguard.txt')" />
207+
<AndroidLibrary Include="$(MSBuildProjectDirectory)/android/*.jar" Bind="true" Pack="true" />
208+
<TransformFile Include="$(MSBuildProjectDirectory)/android/*.xml" />
209+
</ItemGroup>
194210
<!-- Trimming -->
195211
<PropertyGroup Condition="'$(SilkTrimmingExempt)' == ''">
196212
<IsTrimmable>true</IsTrimmable>
@@ -200,4 +216,43 @@
200216
<TrimMode>full</TrimMode>
201217
</PropertyGroup>
202218
</Target>
219+
220+
221+
<!-- Closest things to documentation on what the hell this voodoo does:
222+
https://github.com/NuGet/Home/issues/10063#issuecomment-713083004
223+
https://github.com/xamarin/xamarin-android/pull/5242
224+
https://github.com/dotnet/sdk/issues/14042
225+
https://github.com/dotnet/sdk/blob/main/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.PackTool.targets#L54
226+
https://github.com/xamarin/xamarin-android/issues/5957
227+
https://github.com/xamarin/xamarin-android/blob/main/Documentation/guides/OneDotNetEmbeddedResources.md
228+
229+
This is an adaptation of what we used in Silk.NET 2.X to add files to packages, which was originally focused on
230+
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
231+
much better state these days. However, some of the links above may only be relevant with that context. -->
232+
<Target Name="SilkNativePackaging" Condition="'$(SilkNativePackage)' == 'true'">
233+
<GetNuGetShortFolderName TargetFrameworkMoniker="$(TargetFrameworkMoniker)" TargetPlatformMoniker="$(TargetPlatformMoniker)">
234+
<Output TaskParameter="NuGetShortFolderName" PropertyName="SilkNuGetShortFolderName" />
235+
</GetNuGetShortFolderName>
236+
<ReadLinesFromFile File="$(MSBuildThisFileDirectory)eng/native/nuget/NativeNuGetPackage.targets">
237+
<Output TaskParameter="Lines" ItemName="SilkNativeNuGetPackageTargets" />
238+
</ReadLinesFromFile>
239+
<WriteLinesToFile File="$(IntermediateOutputPath)$(TargetFramework)/$(MSBuildProjectName).targets"
240+
Lines="@(SilkNativeNuGetPackageTargets->'%(Identity)'->Replace('TO_BE_REPLACED_MTOUCH_NATIVE_REFERENCE_LINKER_FLAGS', '$(SilkNativeiOSLinkerFlags)')->Replace('TO_BE_REPLACED_PROPERTY_PREFIX', '$(MSBuildProjectName.Replace('.', '_'))'))" />
241+
<WriteLinesToFile File="$(IntermediateOutputPath)$(TargetFramework)/_._" Lines="@(SilkDummyItem)" />
242+
<ItemGroup>
243+
<TfmSpecificPackageFile Include="$(IntermediateOutputPath)$(TargetFramework)/$(MSBuildProjectName).targets"
244+
Link="build/$(SilkNuGetShortFolderName)/$(MSBuildProjectName).targets"
245+
Pack="true"
246+
PackagePath="build/$(SilkNuGetShortFolderName)/$(MSBuildProjectName).targets" />
247+
<TfmSpecificPackageFile Include="$(IntermediateOutputPath)$(TargetFramework)/$(MSBuildProjectName).targets"
248+
Link="build/$(SilkNuGetShortFolderName)/$(MSBuildProjectName).targets"
249+
Pack="true"
250+
PackagePath="buildTransitive/$(SilkNuGetShortFolderName)/$(MSBuildProjectName).targets" />
251+
<TfmSpecificPackageFile Include="$(IntermediateOutputPath)$(TargetFramework)/_._"
252+
Link="lib/$(SilkNuGetShortFolderName)/_._"
253+
Pack="true"
254+
PackagePath="lib/$(SilkNuGetShortFolderName)/_._"
255+
Condition="'$(IncludeBuildOutput)' == 'false'" />
256+
</ItemGroup>
257+
</Target>
203258
</Project>

Silk.NET.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET", "sources\Core\Si
9595
EndProject
9696
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Win32", "Win32", "{6E739132-EEAB-43A5-83C7-EB58C50D03A1}"
9797
EndProject
98+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.SDL.Native", "sources\SDL\Native\Silk.NET.SDL.Native.csproj", "{F16C0AB9-DE7E-4C09-9EE9-DAA8B8E935A6}"
99+
EndProject
98100
Global
99101
GlobalSection(SolutionConfigurationPlatforms) = preSolution
100102
Debug|Any CPU = Debug|Any CPU
@@ -153,6 +155,10 @@ Global
153155
{6FA628B8-9696-4847-89F9-E58F470AF4FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
154156
{6FA628B8-9696-4847-89F9-E58F470AF4FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
155157
{6FA628B8-9696-4847-89F9-E58F470AF4FB}.Release|Any CPU.Build.0 = Release|Any CPU
158+
{F16C0AB9-DE7E-4C09-9EE9-DAA8B8E935A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
159+
{F16C0AB9-DE7E-4C09-9EE9-DAA8B8E935A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
160+
{F16C0AB9-DE7E-4C09-9EE9-DAA8B8E935A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
161+
{F16C0AB9-DE7E-4C09-9EE9-DAA8B8E935A6}.Release|Any CPU.Build.0 = Release|Any CPU
156162
EndGlobalSection
157163
GlobalSection(SolutionProperties) = preSolution
158164
HideSolutionNode = FALSE
@@ -182,6 +188,7 @@ Global
182188
{3CADD95A-179F-4ECF-A49D-4B753832C63C} = {475AEF7B-0154-4989-AF82-97E3A95A96AF}
183189
{6FA628B8-9696-4847-89F9-E58F470AF4FB} = {5CD096DB-6C44-48F1-9093-AD4C84B6B7EC}
184190
{6E739132-EEAB-43A5-83C7-EB58C50D03A1} = {DD29EA8F-B1A6-45AA-8D2E-B38DA56D9EF6}
191+
{F16C0AB9-DE7E-4C09-9EE9-DAA8B8E935A6} = {EC4D7B06-D277-4411-BD7B-71A6D37683F0}
185192
EndGlobalSection
186193
GlobalSection(ExtensibilityGlobals) = postSolution
187194
SolutionGuid = {78D2CF6A-60A1-43E3-837B-00B73C9DA384}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project ToolsVersion="15.0">
2+
<!-- This file is part of the built native NuGet package, added in Directory.Build.targets.
3+
Read documentation/for-contributors/build-system.md for more info -->
4+
<PropertyGroup>
5+
<_TO_BE_REPLACED_PROPERTY_PREFIX_IsMtouch Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios' or $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst' or $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tvos'">true</_TO_BE_REPLACED_PROPERTY_PREFIX_IsMtouch>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<NativeReference Include="$(MSBuildThisFileDirectory)../../runtimes/$(RuntimeIdentifier)/native/*.a" Condition="'$(_TO_BE_REPLACED_PROPERTY_PREFIX_IsMtouch)' == 'true'">
9+
<Kind>Static</Kind>
10+
<Forceload>True</Forceload>
11+
<IsCxx>True</IsCxx>
12+
<SmartLink>False</SmartLink>
13+
<LinkerFlags>TO_BE_REPLACED_MTOUCH_NATIVE_REFERENCE_LINKER_FLAGS</LinkerFlags>
14+
</NativeReference>
15+
<NativeReference Include="$(MSBuildThisFileDirectory)../../runtimes/$(RuntimeIdentifier.Split('-')[0])/native/*.a" Condition="'$(_TO_BE_REPLACED_PROPERTY_PREFIX_IsMtouch)' == 'true'">
16+
<Kind>Static</Kind>
17+
<Forceload>True</Forceload>
18+
<IsCxx>True</IsCxx>
19+
<SmartLink>False</SmartLink>
20+
<LinkerFlags>TO_BE_REPLACED_MTOUCH_NATIVE_REFERENCE_LINKER_FLAGS</LinkerFlags>
21+
</NativeReference>
22+
</ItemGroup>
23+
</Project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net8.0;net8.0-android</TargetFrameworks>
5+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('Linux')) == false">$(TargetFrameworks);net8.0-ios</TargetFrameworks>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<SilkDescription>Native binaries for SDL3.</SilkDescription>
9+
<SilkNativePackage>true</SilkNativePackage>
10+
<SilkNativeHasAndroidJars>true</SilkNativeHasAndroidJars>
11+
<SilkNativeiOSLinkerFlags>-framework AudioToolbox -framework AVFoundation -framework CoreAudio -framework CoreBluetooth -framework CoreFoundation -framework CoreGraphics -framework CoreHaptics -framework CoreMotion -framework CoreVideo -framework GameController -framework IOKit -framework Metal -framework OpenGLES -framework QuartzCore -framework UIKit -framework Foundation</SilkNativeiOSLinkerFlags>
12+
<EnableDefaultAndroidItems>false</EnableDefaultAndroidItems>
13+
<GenerateDocumentationFile>false</GenerateDocumentationFile>
14+
<NoWarn>1591</NoWarn>
15+
<IncludeBuildOutput Condition="'$(TargetFramework)' != ''">false</IncludeBuildOutput>
16+
<IncludeBuildOutput Condition="'$(SilkNativeHasAndroidJars)' == 'true' and $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">true</IncludeBuildOutput>
17+
</PropertyGroup>
18+
19+
</Project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<metadata>
2+
<!-- Protected members excluded because they reference private members -->
3+
<remove-node
4+
path="/api/package[@name='org.libsdl.app']/class[@name='SDLControllerManager']/field[@name='mHapticHandler']"/>
5+
<remove-node
6+
path="/api/package[@name='org.libsdl.app']/class[@name='SDLControllerManager']/field[@name='mJoystickHandler']"/>
7+
<remove-node
8+
path="/api/package[@name='org.libsdl.app']/class[@name='SDLActivity']/field[@name='mMotionListener']"/>
9+
<remove-node
10+
path="/api/package[@name='org.libsdl.app']/class[@name='SDLActivity']/field[@name='mClipboardHandler']"/>
11+
<remove-node
12+
path="/api/package[@name='org.libsdl.app']/class[@name='SDLActivity']/method[@name='getMotionListener' and count(parameter)=0]"/>
13+
<attr path="/api/package[@name='org.libsdl.app']/class[@name='SDLSurface']/method[@name='onApplyWindowInsets' and count(parameter)=2]/parameter[1]" name="not-null">true</attr>
14+
<attr path="/api/package[@name='org.libsdl.app']/class[@name='SDLSurface']/method[@name='onApplyWindowInsets' and count(parameter)=2]/parameter[2]" name="not-null">true</attr>
15+
<attr path="/api/package[@name='org.libsdl.app']/class[@name='SDLSurface']/method[@name='onApplyWindowInsets' and count(parameter)=2]" name="return-not-null">true</attr>
16+
</metadata>

sources/SDL/Native/build-android.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ cp ../../../eng/submodules/sdl/install-android/x86-install/lib/libSDL3.so runtim
2121
cp ../../../eng/submodules/sdl/install-android/x86_64-install/lib/libSDL3.so runtimes/android-x64/native
2222
jars=( ../../../eng/submodules/sdl/install-android/armeabi-v7a-install/share/java/SDL3/SDL3-*.jar )
2323
cp "${jars[1]}" android/SDL3.jar
24+
cp "$(dirname "${jars[1]}")/proguard.txt" android/proguard.txt

0 commit comments

Comments
 (0)