Add desktop tests project

The primary purpose of this is to split out the handling of the native
libs. This is a consequence of using ProjectReference, and resolves the
following issues:

1. When compiling for iOS, it really doesn't like multiple files being
   included in the same output path. Example: all Windows SDL.dll files
   placed as SDL.dll in the output path.
2. Even if (1) was somehow resolved, the iOS build also doesn't like the
   linux-specific .so files being included.
3. As a consequence of (1), it's likely that the project already doesn't
   work on some configurations. For example, because win-x86 is
   specified as the last item, it will likely take precedence over all
   other versions.
4. It looks like `RuntimeIdentifier` is not project-transitive, against
   my expectations. I really want the project to both select the correct
   single native lib for the current platform, and also support
   compiling with a RID (`dotnet build -r ...`).

So now we only copy the correct lib to the output path, and don't do it
while packaging (not required).
This commit is contained in:
Dan Balasescu 2024-04-20 19:11:28 +09:00
parent a16389d76c
commit 59cb0158ba
No known key found for this signature in database
5 changed files with 65 additions and 25 deletions

View File

@ -0,0 +1,7 @@
internal class Program
{
public static void Main(string[] args)
{
SDL.Tests.Program.Main();
}
}

View File

@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>SDL3.Tests.Desktop</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SDL3-CS.Tests\SDL3-CS.Tests.csproj"/>
</ItemGroup>
<PropertyGroup Condition=" '$(RuntimeIdentifier)' == '' ">
<SDLArch>$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)</SDLArch>
<!-- If RID is specified -->
<SDLNativeLib Condition=" $(RuntimeIdentifier.StartsWith('win')) ">$(RuntimeIdentifier)\SDL3.dll</SDLNativeLib>
<SDLNativeLib Condition=" $(RuntimeIdentifier.StartsWith('linux')) ">$(RuntimeIdentifier)\libSDL3.so</SDLNativeLib>
<SDLNativeLib Condition=" $(RuntimeIdentifier.StartsWith('osx')) ">$(RuntimeIdentifier)\libSDL3.dylib</SDLNativeLib>
<!-- If RID is not specified -->
<SDLNativeLib Condition=" '$(SDLNativeLib)' == '' And '$([MSBuild]::IsOSPlatform(Windows))' ">win-$(SDLArch.ToLower())\SDL3.dll</SDLNativeLib>
<SDLNativeLib Condition=" '$(SDLNativeLib)' == '' And '$([MSBuild]::IsOSPlatform(Linux))' ">linux-$(SDLArch.ToLower())\libSDL3.so</SDLNativeLib>
<SDLNativeLib Condition=" '$(SDLNativeLib)' == '' And '$([MSBuild]::IsOSPlatform(OSX))' ">osx-$(SDLArch.ToLower())\libSDL3.dylib</SDLNativeLib>
</PropertyGroup>
<ItemGroup Condition=" '$(SDLNativeLib)' != '' ">
<Content Include="$(MSBuildThisFileDirectory)..\native\$(SDLNativeLib)">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Library</OutputType>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<RootNamespace>SDL.Tests</RootNamespace> <RootNamespace>SDL.Tests</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>

View File

@ -23,6 +23,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SDL3-CS.Android", "SDL3-CS.
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SDL3-CS.Tests.Android", "SDL3-CS.Tests.Android\SDL3-CS.Tests.Android.csproj", "{E8469DA5-E437-4287-9E2A-8B8F4DC21C1A}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SDL3-CS.Tests.Android", "SDL3-CS.Tests.Android\SDL3-CS.Tests.Android.csproj", "{E8469DA5-E437-4287-9E2A-8B8F4DC21C1A}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SDL3-CS.Tests.Desktop", "SDL3-CS.Tests.Desktop\SDL3-CS.Tests.Desktop.csproj", "{7E8D719A-5B69-43B7-A9D5-385B6FE7F411}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -49,6 +51,10 @@ Global
{E8469DA5-E437-4287-9E2A-8B8F4DC21C1A}.Debug|Any CPU.Build.0 = Debug|Any CPU {E8469DA5-E437-4287-9E2A-8B8F4DC21C1A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E8469DA5-E437-4287-9E2A-8B8F4DC21C1A}.Release|Any CPU.ActiveCfg = Release|Any CPU {E8469DA5-E437-4287-9E2A-8B8F4DC21C1A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E8469DA5-E437-4287-9E2A-8B8F4DC21C1A}.Release|Any CPU.Build.0 = Release|Any CPU {E8469DA5-E437-4287-9E2A-8B8F4DC21C1A}.Release|Any CPU.Build.0 = Release|Any CPU
{7E8D719A-5B69-43B7-A9D5-385B6FE7F411}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7E8D719A-5B69-43B7-A9D5-385B6FE7F411}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7E8D719A-5B69-43B7-A9D5-385B6FE7F411}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7E8D719A-5B69-43B7-A9D5-385B6FE7F411}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -29,46 +29,38 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="$(MSBuildThisFileDirectory)..\native\win-x64\SDL3.dll"> <None Include="$(MSBuildThisFileDirectory)..\native\win-x64\SDL3.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PackagePath>runtimes/win-x64/native</PackagePath> <PackagePath>runtimes/win-x64/native</PackagePath>
<Pack>true</Pack> <Pack>true</Pack>
</Content> </None>
<Content Include="$(MSBuildThisFileDirectory)..\native\win-arm64\SDL3.dll"> <None Include="$(MSBuildThisFileDirectory)..\native\win-arm64\SDL3.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PackagePath>runtimes/win-arm64/native</PackagePath> <PackagePath>runtimes/win-arm64/native</PackagePath>
<Pack>true</Pack> <Pack>true</Pack>
</Content> </None>
<Content Include="$(MSBuildThisFileDirectory)..\native\win-x86\SDL3.dll"> <None Include="$(MSBuildThisFileDirectory)..\native\win-x86\SDL3.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PackagePath>runtimes/win-x86/native</PackagePath> <PackagePath>runtimes/win-x86/native</PackagePath>
<Pack>true</Pack> <Pack>true</Pack>
</Content> </None>
<Content Include="$(MSBuildThisFileDirectory)..\native\osx-x64\libSDL3.dylib"> <None Include="$(MSBuildThisFileDirectory)..\native\osx-x64\libSDL3.dylib">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PackagePath>runtimes/osx-x64/native</PackagePath> <PackagePath>runtimes/osx-x64/native</PackagePath>
<Pack>true</Pack> <Pack>true</Pack>
</Content> </None>
<Content Include="$(MSBuildThisFileDirectory)..\native\osx-arm64\libSDL3.dylib"> <None Include="$(MSBuildThisFileDirectory)..\native\osx-arm64\libSDL3.dylib">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PackagePath>runtimes/osx-arm64/native</PackagePath> <PackagePath>runtimes/osx-arm64/native</PackagePath>
<Pack>true</Pack> <Pack>true</Pack>
</Content> </None>
<Content Include="$(MSBuildThisFileDirectory)..\native\linux-x64\libSDL3.so"> <None Include="$(MSBuildThisFileDirectory)..\native\linux-x64\libSDL3.so">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PackagePath>runtimes/linux-x64/native</PackagePath> <PackagePath>runtimes/linux-x64/native</PackagePath>
<Pack>true</Pack> <Pack>true</Pack>
</Content> </None>
<Content Include="$(MSBuildThisFileDirectory)..\native\linux-x86\libSDL3.so"> <None Include="$(MSBuildThisFileDirectory)..\native\linux-x86\libSDL3.so">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PackagePath>runtimes/linux-x86/native</PackagePath> <PackagePath>runtimes/linux-x86/native</PackagePath>
<Pack>true</Pack> <Pack>true</Pack>
</Content> </None>
<Content Include="$(MSBuildThisFileDirectory)..\native\ios\**\*"> <None Include="$(MSBuildThisFileDirectory)..\native\ios\**\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PackagePath>runtimes/ios/native</PackagePath> <PackagePath>runtimes/ios/native</PackagePath>
<Pack>true</Pack> <Pack>true</Pack>
</Content> </None>
</ItemGroup> </ItemGroup>
</Project> </Project>