From 3b305013a1319e2be05073e6f705f734e7cfaedc Mon Sep 17 00:00:00 2001 From: tiger tiger tiger Date: Tue, 30 Jun 2026 17:12:15 +0200 Subject: [PATCH] fix: centralized version data in Directory.build.props, and fixed various interop details that had incorrect function signatures --- .gitignore | 1 + Directory.Build.props | 6 + Directory.Build.targets | 17 +++ Raylib-cs.Tests/Raylib-cs.Tests.csproj | 2 +- Raylib-cs/Build.props | 4 +- Raylib-cs/Raylib-cs.csproj | 154 ++++++++++--------------- Raylib-cs/Raylib-cs.targets | 52 ++++++++- Raylib-cs/interop/Raylib.cs | 9 +- Raylib-cs/interop/Rlgl.cs | 8 +- Raylib-cs/types/Raylib.Utils.cs | 8 ++ Raylib-cs/types/Rlgl.Utils.cs | 13 +++ 11 files changed, 169 insertions(+), 105 deletions(-) create mode 100644 Directory.Build.props create mode 100644 Directory.Build.targets diff --git a/.gitignore b/.gitignore index f3e5588..0203353 100644 --- a/.gitignore +++ b/.gitignore @@ -177,6 +177,7 @@ PublishScripts/ # NuGet Packages *.nupkg +nuget # The packages folder can be ignored because of Package Restore **/packages/* # except build/, which is used as an MSBuild target. diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..1787477 --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,6 @@ + + + + 8.1.0 + + diff --git a/Directory.Build.targets b/Directory.Build.targets new file mode 100644 index 0000000..89f1009 --- /dev/null +++ b/Directory.Build.targets @@ -0,0 +1,17 @@ + + + + + <_LocalNuGetDir>$(MSBuildThisFileDirectory)nuget + <_LocalRaylibCsNupkg>$(_LocalNuGetDir)/Raylib-cs.$(RaylibCsVersion).nupkg + + + + + diff --git a/Raylib-cs.Tests/Raylib-cs.Tests.csproj b/Raylib-cs.Tests/Raylib-cs.Tests.csproj index 31bc88b..fb066da 100644 --- a/Raylib-cs.Tests/Raylib-cs.Tests.csproj +++ b/Raylib-cs.Tests/Raylib-cs.Tests.csproj @@ -16,6 +16,6 @@ - + diff --git a/Raylib-cs/Build.props b/Raylib-cs/Build.props index 1603a20..3a91b49 100644 --- a/Raylib-cs/Build.props +++ b/Raylib-cs/Build.props @@ -1,7 +1,7 @@ 6.0 - 8.0.0 - 8.0.0 + $(RaylibCsVersion) + $(RaylibCsVersion) diff --git a/Raylib-cs/Raylib-cs.csproj b/Raylib-cs/Raylib-cs.csproj index 7da6253..7155e74 100644 --- a/Raylib-cs/Raylib-cs.csproj +++ b/Raylib-cs/Raylib-cs.csproj @@ -5,7 +5,6 @@ Raylib_cs true 12 - win-x64;win-x86;linux-x64;osx-x64;osx-arm64;browser-wasm @@ -14,7 +13,6 @@ Raylib-cs - 8.0.0 C# bindings for raylib https://github.com/raylib-cs/raylib-cs/ raylib-cs @@ -49,93 +47,51 @@ $(BaseIntermediateOutputPath)natives/ - - - - raylib-$(TargetRaylibTag)_win64_msvc16 - .zip - raylib.dll - - - - - raylib-$(TargetRaylibTag)_win32_msvc16 - .zip - raylib.dll - - - - - raylib-$(TargetRaylibTag)_linux_amd64 - .tar.gz - libraylib.so* - - - - - raylib-$(TargetRaylibTag)_macos - .tar.gz - libraylib.dylib - - - - - raylib-$(TargetRaylibTag)_macos - .tar.gz - libraylib.dylib - - - - - raylib-$(TargetRaylibTag)_webassembly - .zip - libraylib.web.a - - - + + + + + + + + + + + + + + @(RaylibRid->WithMetadataValue('Identity','$(RuntimeIdentifier)')->'%(Pkg)') + @(RaylibRid->WithMetadataValue('Identity','$(RuntimeIdentifier)')->'%(Ext)') + @(RaylibRid->WithMetadataValue('Identity','$(RuntimeIdentifier)')->'%(Lib)') + + - - <_TargetRids Include="$(PackageRids)"/> - - - + - <_PackageFiles Include="$(NativesRoot)win-x64/raylib-$(TargetRaylibTag)_win64_msvc16/lib/raylib.dll"> - runtimes/win-x64/native/ + <_PackageFiles Include="@(RaylibRid->'$(NativesRoot)%(Identity)/%(Pkg)/lib/%(Pack)')" + Condition="'%(RaylibRid.PackAs)' == ''"> + runtimes/%(RaylibRid.Identity)/native/ None - - <_PackageFiles Include="$(NativesRoot)win-x86/raylib-$(TargetRaylibTag)_win32_msvc16/lib/raylib.dll"> - runtimes/win-x86/native/ - None - - - <_PackageFiles Include="$(NativesRoot)linux-x64/raylib-$(TargetRaylibTag)_linux_amd64/lib/libraylib.so"> - runtimes/linux-x64/native/ - None - - - <_PackageFiles Include="$(NativesRoot)osx-x64/raylib-$(TargetRaylibTag)_macos/lib/libraylib.dylib"> - runtimes/osx-x64/native/ - None - - - <_PackageFiles Include="$(NativesRoot)osx-arm64/raylib-$(TargetRaylibTag)_macos/lib/libraylib.dylib"> - runtimes/osx-arm64/native/ - None - - - <_PackageFiles Include="$(NativesRoot)browser-wasm/raylib-$(TargetRaylibTag)_webassembly/lib/libraylib.web.a"> - runtimes/browser-wasm/native/raylib.a + <_PackageFiles Include="@(RaylibRid->'$(NativesRoot)%(Identity)/%(Pkg)/lib/%(Pack)')" + Condition="'%(RaylibRid.PackAs)' != ''"> + runtimes/%(RaylibRid.Identity)/native/%(RaylibRid.PackAs) None @@ -145,53 +101,65 @@ - - + + + + <_RaylibNativesDir>$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)/$(NativesRoot)')) + - <_NativeToCopy Include="$(NativesRoot)$(RuntimeIdentifier)/**/$(LibPattern)"/> + <_NativeCandidate Include="$(_RaylibNativesDir)$(RuntimeIdentifier)/**/$(LibPattern)"/> + <_RaylibNativeLibraryItem Include="@(_NativeCandidate)"/> - + + + + + + <_WasmNativeSrc>$(NativesRoot)browser-wasm/$(RaylibPackageName)/lib/libraylib.web.a + <_WasmNativeDst>$(MSBuildThisFileDirectory)obj/browser-wasm/raylib.a + + + + - + + <_WorkDir>$(NativesRoot)$(RuntimeIdentifier)/ <_ArchiveFile>$(_WorkDir)$(RaylibPackageName)$(ArchiveExt) <_ExtractMarker>$(_WorkDir).extracted - - - - + - + - - - - + \ No newline at end of file diff --git a/Raylib-cs/Raylib-cs.targets b/Raylib-cs/Raylib-cs.targets index 7cde8d4..290cbc8 100644 --- a/Raylib-cs/Raylib-cs.targets +++ b/Raylib-cs/Raylib-cs.targets @@ -1,10 +1,54 @@ - - - - + + + 6.0 + $(EmccFlags) -sUSE_GLFW=3 + + + + + + + + + + + + + + + + + + + <_RaylibNativeRid Condition="'$(_RaylibNativeRid)' == ''">$(RuntimeIdentifier) + <_RaylibNativeRid Condition="'$(_RaylibNativeRid)' == ''">$(NETCoreSdkPortableRuntimeIdentifier) + <_RaylibNativeOutputDir>$(OutputPath)runtimes\$(_RaylibNativeRid)\native\ + + + + + + + + + diff --git a/Raylib-cs/interop/Raylib.cs b/Raylib-cs/interop/Raylib.cs index 4e5e186..c7ca8f9 100644 --- a/Raylib-cs/interop/Raylib.cs +++ b/Raylib-cs/interop/Raylib.cs @@ -26,7 +26,14 @@ public static unsafe partial class Raylib static Raylib() { - NativeLibrary.SetDllImportResolver(Assembly.GetExecutingAssembly(), ResolveDllImport); + // On WebAssembly (browser) the native library is statically linked into the main + // module, and P/Invokes are resolved by the runtime's built-in static-linking table. + // A custom resolver would override that and fail (there is no library to load), so we + // only install it on platforms where raylib is a separate dynamic library. + if (!OperatingSystem.IsBrowser()) + { + NativeLibrary.SetDllImportResolver(Assembly.GetExecutingAssembly(), ResolveDllImport); + } } public static IntPtr ResolveDllImport(string libraryName, Assembly assembly, DllImportSearchPath? searchPath) diff --git a/Raylib-cs/interop/Rlgl.cs b/Raylib-cs/interop/Rlgl.cs index 677be6e..2a2d1ad 100644 --- a/Raylib-cs/interop/Rlgl.cs +++ b/Raylib-cs/interop/Rlgl.cs @@ -744,7 +744,7 @@ public static unsafe partial class Rlgl /// Load depth texture/renderbuffer (to be attached to fbo) [LibraryImport(NativeLibName, EntryPoint = "rlLoadTextureDepth")] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] - public static partial uint LoadTextureDepth(int width, int height, CBool useRenderBuffer); + public static partial uint LoadTextureDepth(int width, int height, int useRenderBuffer); /// Load texture cubemap data [LibraryImport(NativeLibName, EntryPoint = "rlLoadTextureCubemap")] @@ -813,15 +813,15 @@ public static unsafe partial class Rlgl public static partial void FramebufferAttach( uint fboId, uint texId, - FramebufferAttachType attachType, - FramebufferAttachTextureType texType, + int attachType, + int texType, int mipLevel ); /// Verify framebuffer is complete [LibraryImport(NativeLibName, EntryPoint = "rlFramebufferComplete")] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] - public static partial CBool FramebufferComplete(uint id); + public static partial int FramebufferComplete(uint id); /// Delete framebuffer from GPU [LibraryImport(NativeLibName, EntryPoint = "rlUnloadFramebuffer")] diff --git a/Raylib-cs/types/Raylib.Utils.cs b/Raylib-cs/types/Raylib.Utils.cs index 8f92726..3e10ae6 100644 --- a/Raylib-cs/types/Raylib.Utils.cs +++ b/Raylib-cs/types/Raylib.Utils.cs @@ -186,6 +186,14 @@ public static unsafe partial class Raylib /// Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR) public static void TraceLog(TraceLogLevel logLevel, string text) { + // raylib's TraceLog is variadic (const char *text, ...). WebAssembly cannot invoke + // variadic C functions from managed code (traps with "function signature mismatch"). + if (OperatingSystem.IsBrowser()) + { + Console.WriteLine(text); + return; + } + using Utf8Buffer str1 = text.ToUtf8Buffer(); TraceLog(logLevel, str1.AsPointer()); } diff --git a/Raylib-cs/types/Rlgl.Utils.cs b/Raylib-cs/types/Rlgl.Utils.cs index 3f50d50..5f258e0 100644 --- a/Raylib-cs/types/Rlgl.Utils.cs +++ b/Raylib-cs/types/Rlgl.Utils.cs @@ -4,6 +4,19 @@ namespace Raylib_cs; public static unsafe partial class Rlgl { + /// Load depth texture/renderbuffer (to be attached to fbo) + public static uint LoadTextureDepth(int width, int height, bool useRenderBuffer) => + LoadTextureDepth(width, height, useRenderBuffer ? 1 : 0); + + /// Attach texture/renderbuffer to a framebuffer + public static void FramebufferAttach( + uint fboId, + uint texId, + FramebufferAttachType attachType, + FramebufferAttachTextureType texType, + int mipLevel + ) => FramebufferAttach(fboId, texId, (int)attachType, (int)texType, mipLevel); + /// Set shader value matrices public static void SetUniformMatrices(int locIndex, Matrix4x4[] mat) {