From 71bb93253cfdcdd52b2f7f90abaa918640ab0d28 Mon Sep 17 00:00:00 2001 From: Luis Michaelis Date: Sun, 12 Nov 2023 10:27:29 +0100 Subject: [PATCH] build(platform): copy native libraries base on `RuntimeIdentifier` Also updates the README with instructions on how to install and configure your own project with ZenKitCS. --- README.md | 31 +++++++++++++++++++++ ZenKit/NativeLoader/NativePathResolver.cs | 8 ++++++ ZenKit/ZenKit.csproj | 34 +++++++++++++++++++++-- ZenKit/ZenKit.targets | 16 +++++++---- 4 files changed, 81 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index da82c56..05f33a2 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,37 @@ A C#-library wrapping the [ZenKit](https://github.com/GothicKit/ZenKit) library [PiranhaBytes'](https://www.piranha-bytes.com/) early 2000's games [Gothic](https://en.wikipedia.org/wiki/Gothic_(video_game)) and [Gothic II](https://en.wikipedia.org/wiki/Gothic_II). +## Using + +You can install `ZenKitCS` from the [NuGet Package Gallery](https://www.nuget.org/packages/ZenKit). Simply add the +following snippet to your `.csproj` file, replacing the version with the approprite version identifier from NuGet. + +``` + + + +``` + +To build your project then, you will need to add a `RuntimeIdentifiers` property to your `.csproj`. You can simply +use this once and copy it the topmost `` in your `.csproj` like this: + +```xml + + + + linux-x64;win-x64;osx-x64;android-arm64 + + + +``` + +You can now also build your project for those runtimes by supplying the runtime identifier in `dotnet build` using the +`-r` parameter. This is how you would build your project for Android: + +``` +dotnet build -r android-arm64 -c Release --self-contained +``` + ## Building You will need: diff --git a/ZenKit/NativeLoader/NativePathResolver.cs b/ZenKit/NativeLoader/NativePathResolver.cs index d986af8..5976a18 100644 --- a/ZenKit/NativeLoader/NativePathResolver.cs +++ b/ZenKit/NativeLoader/NativePathResolver.cs @@ -12,17 +12,25 @@ public override IEnumerable EnumeratePossibleLibraryLoadTargets(string n { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { + yield return Path.Combine(AppContext.BaseDirectory, $"{name}.dll"); yield return Path.Combine(AppContext.BaseDirectory, $"runtimes\\win-x64\\native\\{name}.dll"); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { if (RuntimeInformation.ProcessArchitecture == Architecture.X64) + { + yield return Path.Combine(AppContext.BaseDirectory, $"lib{name}.so"); yield return Path.Combine(AppContext.BaseDirectory, $"runtimes/linux-x64/native/lib{name}.so"); + } else if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64) + { + yield return Path.Combine(AppContext.BaseDirectory, $"lib{name}.so"); yield return Path.Combine(AppContext.BaseDirectory, $"runtimes/android-arm64/native/lib{name}.so"); + } } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { + yield return Path.Combine(AppContext.BaseDirectory, $"lib{name}.dylib"); yield return Path.Combine(AppContext.BaseDirectory, $"runtimes/osx-x64/native/lib{name}.dylib"); } } diff --git a/ZenKit/ZenKit.csproj b/ZenKit/ZenKit.csproj index c71fd27..fbe643b 100644 --- a/ZenKit/ZenKit.csproj +++ b/ZenKit/ZenKit.csproj @@ -6,7 +6,7 @@ ZenKit true ZenKit - 0.1.7 + 0.1.9 Luis Michaelis GothicKit © 2023. GothicKit Contributors @@ -16,19 +16,47 @@ README.md https://github.com/GothicKit/ZenKitCS C#-bindings for ZenKit, the ZenGin asset parser. + + android-arm64 + linux-x64 + osx-x64 + win-x64 - + + - PreserveNewest + Never true + + + + PreserveNewest + libzenkitcapi.so + + + + PreserveNewest + libzenkitcapi.so + + + + PreserveNewest + libzenkitcapi.dylib + + + + PreserveNewest + zenkitcapi.dll + + diff --git a/ZenKit/ZenKit.targets b/ZenKit/ZenKit.targets index e187863..f594a88 100644 --- a/ZenKit/ZenKit.targets +++ b/ZenKit/ZenKit.targets @@ -1,5 +1,11 @@ - + + android-arm64 + linux-x64 + osx-x64 + win-x64 + + @@ -7,9 +13,9 @@ - - - - + + + +