Skip to content

Commit

Permalink
Include org.libsdl.app bindings with the aar, working package now
Browse files Browse the repository at this point in the history
  • Loading branch information
Perksey committed Dec 28, 2024
1 parent 917d412 commit 8cf95c2
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 2 deletions.
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<VersionDependsOn>SilkShippingControl;$(VersionDependsOn)</VersionDependsOn>
<PackageVersionDependsOn>SilkShippingControl;$(PackageVersionDependsOn)</PackageVersionDependsOn>
<TargetsForTfmSpecificContentInPackage>SilkNativePackaging;$(TargetsForTfmSpecificContentInPackage)</TargetsForTfmSpecificContentInPackage>
</PropertyGroup>
</Project>
59 changes: 57 additions & 2 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@
</PropertyGroup>
<!-- Non-C# packages (i.e. metapackages, natives) -->
<PropertyGroup Condition="'$(SilkNativePackage)' == 'true' or '$(SilkMetapackage)' == 'true'">
<IncludeBuildOutput>false</IncludeBuildOutput>
<NoWarn>NU5128</NoWarn>
<IncludeBuildOutput Condition="'$(SilkNativeHasAndroidJars)' != 'true'">false</IncludeBuildOutput>
<NoWarn>NU5128;$(NoWarn)</NoWarn>
</PropertyGroup>
<!-- Public API -->
<PropertyGroup Condition="'$(SilkTrackPublicAPI)' != 'true' or '$(TargetFramework)' == ''">
Expand Down Expand Up @@ -191,6 +191,22 @@
<PackageVersion Condition="'$(VersionSuffix)' == ''">$(SilkVersion)</PackageVersion>
<PackageVersion Condition="'$(VersionSuffix)' != ''">$(SilkVersion)-$(VersionSuffix)</PackageVersion>
</PropertyGroup>
<!-- Native Packaging -->
<PropertyGroup>
<SilkVersionTxtPath>$(MSBuildProjectDirectory)/version.txt</SilkVersionTxtPath>
<PackageVersion Condition="Exists('$(SilkVersionTxtPath)')">$([System.IO.File]::ReadAllText("$(SilkVersionTxtPath)"))</PackageVersion>
</PropertyGroup>
<ItemGroup Condition="'$(SilkNativePackage)' == 'true'">
<None Include="$(MSBuildProjectDirectory)/runtimes/**/*" Pack="true" PackagePath="runtimes" />
<!-- bundled in the aar instead -->
<None Remove="$(MSBuildProjectDirectory)/runtimes/android*/**/*" Condition="'$(SilkNativeHasAndroidJars)' == 'true'" />
</ItemGroup>
<ItemGroup Condition="'$(SilkNativePackage)' == 'true' and $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">
<AndroidNativeLibrary Include="$(MSBuildProjectDirectory)/runtimes/android*/native/*.so" />
<ProguardConfiguration Include="$(MSBuildProjectDirectory)/android/proguard.txt" Condition="Exists('$(MSBuildProjectDirectory)/android/proguard.txt')" />
<AndroidLibrary Include="$(MSBuildProjectDirectory)/android/*.jar" Bind="true" Pack="true" />
<TransformFile Include="$(MSBuildProjectDirectory)/android/*.xml" />
</ItemGroup>
<!-- Trimming -->
<PropertyGroup Condition="'$(SilkTrimmingExempt)' == ''">
<IsTrimmable>true</IsTrimmable>
Expand All @@ -200,4 +216,43 @@
<TrimMode>full</TrimMode>
</PropertyGroup>
</Target>


<!-- Closest things to documentation on what the hell this voodoo does:
https://github.com/NuGet/Home/issues/10063#issuecomment-713083004
https://github.com/xamarin/xamarin-android/pull/5242
https://github.com/dotnet/sdk/issues/14042
https://github.com/dotnet/sdk/blob/main/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.PackTool.targets#L54
https://github.com/xamarin/xamarin-android/issues/5957
https://github.com/xamarin/xamarin-android/blob/main/Documentation/guides/OneDotNetEmbeddedResources.md
This is an adaptation of what we used in Silk.NET 2.X to add files to packages, which was originally focused on
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
much better state these days. However, some of the links above may only be relevant with that context. -->
<Target Name="SilkNativePackaging" Condition="'$(SilkNativePackage)' == 'true'">
<GetNuGetShortFolderName TargetFrameworkMoniker="$(TargetFrameworkMoniker)" TargetPlatformMoniker="$(TargetPlatformMoniker)">
<Output TaskParameter="NuGetShortFolderName" PropertyName="SilkNuGetShortFolderName" />
</GetNuGetShortFolderName>
<ReadLinesFromFile File="$(MSBuildThisFileDirectory)eng/native/nuget/NativeNuGetPackage.targets">
<Output TaskParameter="Lines" ItemName="SilkNativeNuGetPackageTargets" />
</ReadLinesFromFile>
<WriteLinesToFile File="$(IntermediateOutputPath)$(TargetFramework)/$(MSBuildProjectName).targets"
Lines="@(SilkNativeNuGetPackageTargets->'%(Identity)'->Replace('TO_BE_REPLACED_MTOUCH_NATIVE_REFERENCE_LINKER_FLAGS', '$(SilkNativeiOSLinkerFlags)')->Replace('TO_BE_REPLACED_PROPERTY_PREFIX', '$(MSBuildProjectName.Replace('.', '_'))'))" />
<WriteLinesToFile File="$(IntermediateOutputPath)$(TargetFramework)/_._" Lines="@(SilkDummyItem)" />
<ItemGroup>
<TfmSpecificPackageFile Include="$(IntermediateOutputPath)$(TargetFramework)/$(MSBuildProjectName).targets"
Link="build/$(SilkNuGetShortFolderName)/$(MSBuildProjectName).targets"
Pack="true"
PackagePath="build/$(SilkNuGetShortFolderName)/$(MSBuildProjectName).targets" />
<TfmSpecificPackageFile Include="$(IntermediateOutputPath)$(TargetFramework)/$(MSBuildProjectName).targets"
Link="build/$(SilkNuGetShortFolderName)/$(MSBuildProjectName).targets"
Pack="true"
PackagePath="buildTransitive/$(SilkNuGetShortFolderName)/$(MSBuildProjectName).targets" />
<TfmSpecificPackageFile Include="$(IntermediateOutputPath)$(TargetFramework)/_._"
Link="lib/$(SilkNuGetShortFolderName)/_._"
Pack="true"
PackagePath="lib/$(SilkNuGetShortFolderName)/_._"
Condition="'$(IncludeBuildOutput)' == 'false'" />
</ItemGroup>
</Target>
</Project>
7 changes: 7 additions & 0 deletions Silk.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET", "sources\Core\Si
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Win32", "Win32", "{6E739132-EEAB-43A5-83C7-EB58C50D03A1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.SDL.Native", "sources\SDL\Native\Silk.NET.SDL.Native.csproj", "{F16C0AB9-DE7E-4C09-9EE9-DAA8B8E935A6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -153,6 +155,10 @@ Global
{6FA628B8-9696-4847-89F9-E58F470AF4FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6FA628B8-9696-4847-89F9-E58F470AF4FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6FA628B8-9696-4847-89F9-E58F470AF4FB}.Release|Any CPU.Build.0 = Release|Any CPU
{F16C0AB9-DE7E-4C09-9EE9-DAA8B8E935A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F16C0AB9-DE7E-4C09-9EE9-DAA8B8E935A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F16C0AB9-DE7E-4C09-9EE9-DAA8B8E935A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F16C0AB9-DE7E-4C09-9EE9-DAA8B8E935A6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -182,6 +188,7 @@ Global
{3CADD95A-179F-4ECF-A49D-4B753832C63C} = {475AEF7B-0154-4989-AF82-97E3A95A96AF}
{6FA628B8-9696-4847-89F9-E58F470AF4FB} = {5CD096DB-6C44-48F1-9093-AD4C84B6B7EC}
{6E739132-EEAB-43A5-83C7-EB58C50D03A1} = {DD29EA8F-B1A6-45AA-8D2E-B38DA56D9EF6}
{F16C0AB9-DE7E-4C09-9EE9-DAA8B8E935A6} = {EC4D7B06-D277-4411-BD7B-71A6D37683F0}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {78D2CF6A-60A1-43E3-837B-00B73C9DA384}
Expand Down
23 changes: 23 additions & 0 deletions eng/native/nuget/NativeNuGetPackage.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project ToolsVersion="15.0">
<!-- This file is part of the built native NuGet package, added in Directory.Build.targets.
Read documentation/for-contributors/build-system.md for more info -->
<PropertyGroup>
<_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>
</PropertyGroup>
<ItemGroup>
<NativeReference Include="$(MSBuildThisFileDirectory)../../runtimes/$(RuntimeIdentifier)/native/*.a" Condition="'$(_TO_BE_REPLACED_PROPERTY_PREFIX_IsMtouch)' == 'true'">
<Kind>Static</Kind>
<Forceload>True</Forceload>
<IsCxx>True</IsCxx>
<SmartLink>False</SmartLink>
<LinkerFlags>TO_BE_REPLACED_MTOUCH_NATIVE_REFERENCE_LINKER_FLAGS</LinkerFlags>
</NativeReference>
<NativeReference Include="$(MSBuildThisFileDirectory)../../runtimes/$(RuntimeIdentifier.Split('-')[0])/native/*.a" Condition="'$(_TO_BE_REPLACED_PROPERTY_PREFIX_IsMtouch)' == 'true'">
<Kind>Static</Kind>
<Forceload>True</Forceload>
<IsCxx>True</IsCxx>
<SmartLink>False</SmartLink>
<LinkerFlags>TO_BE_REPLACED_MTOUCH_NATIVE_REFERENCE_LINKER_FLAGS</LinkerFlags>
</NativeReference>
</ItemGroup>
</Project>
19 changes: 19 additions & 0 deletions sources/SDL/Native/Silk.NET.SDL.Native.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net8.0-android</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('Linux')) == false">$(TargetFrameworks);net8.0-ios</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<SilkDescription>Native binaries for SDL3.</SilkDescription>
<SilkNativePackage>true</SilkNativePackage>
<SilkNativeHasAndroidJars>true</SilkNativeHasAndroidJars>
<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>
<EnableDefaultAndroidItems>false</EnableDefaultAndroidItems>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<NoWarn>1591</NoWarn>
<IncludeBuildOutput Condition="'$(TargetFramework)' != ''">false</IncludeBuildOutput>
<IncludeBuildOutput Condition="'$(SilkNativeHasAndroidJars)' == 'true' and $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">true</IncludeBuildOutput>
</PropertyGroup>

</Project>
16 changes: 16 additions & 0 deletions sources/SDL/Native/android/transform.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<metadata>
<!-- Protected members excluded because they reference private members -->
<remove-node
path="/api/package[@name='org.libsdl.app']/class[@name='SDLControllerManager']/field[@name='mHapticHandler']"/>
<remove-node
path="/api/package[@name='org.libsdl.app']/class[@name='SDLControllerManager']/field[@name='mJoystickHandler']"/>
<remove-node
path="/api/package[@name='org.libsdl.app']/class[@name='SDLActivity']/field[@name='mMotionListener']"/>
<remove-node
path="/api/package[@name='org.libsdl.app']/class[@name='SDLActivity']/field[@name='mClipboardHandler']"/>
<remove-node
path="/api/package[@name='org.libsdl.app']/class[@name='SDLActivity']/method[@name='getMotionListener' and count(parameter)=0]"/>
<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>
<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>
<attr path="/api/package[@name='org.libsdl.app']/class[@name='SDLSurface']/method[@name='onApplyWindowInsets' and count(parameter)=2]" name="return-not-null">true</attr>
</metadata>
1 change: 1 addition & 0 deletions sources/SDL/Native/build-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ cp ../../../eng/submodules/sdl/install-android/x86-install/lib/libSDL3.so runtim
cp ../../../eng/submodules/sdl/install-android/x86_64-install/lib/libSDL3.so runtimes/android-x64/native
jars=( ../../../eng/submodules/sdl/install-android/armeabi-v7a-install/share/java/SDL3/SDL3-*.jar )
cp "${jars[1]}" android/SDL3.jar
cp "$(dirname "${jars[1]}")/proguard.txt" android/proguard.txt

0 comments on commit 8cf95c2

Please sign in to comment.