From a64e128d0d2e9580c03a43fcd4e73c019fafe86c Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Sat, 8 Jul 2023 15:04:55 +0200 Subject: [PATCH] [WiP] Drop support for .NET Standard 2.0 and Mono See: https://devblogs.microsoft.com/dotnet/the-future-of-net-standard/ --- .github/workflows/ci.yml | 4 - README.md | 5 +- build.ps1 | 2 +- build.sh | 8 +- build/Build.cs | 11 --- build/native/NetVips.Native.linux-arm.nuspec | 5 +- .../native/NetVips.Native.linux-arm64.nuspec | 5 +- .../NetVips.Native.linux-musl-arm64.nuspec | 3 +- .../NetVips.Native.linux-musl-x64.nuspec | 5 +- build/native/NetVips.Native.linux-x64.nuspec | 5 +- build/native/NetVips.Native.nuspec | 17 +--- build/native/NetVips.Native.osx-arm64.nuspec | 3 +- build/native/NetVips.Native.osx-x64.nuspec | 5 +- build/native/NetVips.Native.win-arm64.nuspec | 3 +- build/native/NetVips.Native.win-x64.nuspec | 4 +- build/native/NetVips.Native.win-x86.nuspec | 4 +- .../targets/NetVips.Native.linux-arm.targets | 18 ----- .../NetVips.Native.linux-arm64.targets | 18 ----- .../NetVips.Native.linux-musl-x64.targets | 18 ----- .../targets/NetVips.Native.linux-x64.targets | 18 ----- .../targets/NetVips.Native.osx-x64.targets | 18 ----- build/test-mono.sh | 45 ----------- docker.sh | 2 +- .../NetVips.Extensions.csproj | 17 ++-- src/NetVips/ExtensionMethods.cs | 13 --- src/NetVips/GObject.cs | 2 +- src/NetVips/Interop/Libraries.OSX.cs | 15 ---- src/NetVips/Interop/Libraries.Unix.cs | 15 ---- src/NetVips/Interop/Libraries.Windows.cs | 12 --- src/NetVips/Interop/Libraries.cs | 13 +++ src/NetVips/ModuleInitializer.cs | 80 +++++++++++++++++++ src/NetVips/ModuleInitializerAttribute.cs | 4 +- src/NetVips/NetVips.cs | 4 +- src/NetVips/NetVips.csproj | 36 +-------- src/NetVips/SourceCustom.cs | 8 +- src/NetVips/TargetCustom.cs | 6 +- src/NetVips/VipsBlob.cs | 4 +- src/NetVips/VipsObject.cs | 2 +- tests/NetVips.Tests/NetVips.Tests.csproj | 19 +---- 39 files changed, 139 insertions(+), 337 deletions(-) delete mode 100644 build/native/targets/NetVips.Native.linux-arm.targets delete mode 100644 build/native/targets/NetVips.Native.linux-arm64.targets delete mode 100644 build/native/targets/NetVips.Native.linux-musl-x64.targets delete mode 100644 build/native/targets/NetVips.Native.linux-x64.targets delete mode 100644 build/native/targets/NetVips.Native.osx-x64.targets delete mode 100755 build/test-mono.sh delete mode 100644 src/NetVips/Interop/Libraries.OSX.cs delete mode 100644 src/NetVips/Interop/Libraries.Unix.cs delete mode 100644 src/NetVips/Interop/Libraries.Windows.cs create mode 100644 src/NetVips/Interop/Libraries.cs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 316f4dfd..b1d5a62d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,10 +17,6 @@ jobs: - os: ubuntu-22.04 container: mcr.microsoft.com/dotnet/sdk:7.0-alpine3.16 script: ./build.sh - # TODO(kleisauke): Re-enable Mono CI when C# 9 features are supported. - # - os: ubuntu-22.04 - # script: ./build/test-mono.sh - # allow_failures: true - os: macos-12 script: ./build.sh - os: windows-2022 diff --git a/README.md b/README.md index d45a4d05..39cd9896 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,8 @@ which gives some more background. ## Supported platforms -- .NET Framework (4.5.2 and higher) -- .NET Core (.NETStandard 2.0 and higher on Windows, Linux and macOS) -- Mono +- .NET Framework 4.5.2 and higher +- .NET 6.0 and higher ## Install diff --git a/build.ps1 b/build.ps1 index f561725f..ec978393 100644 --- a/build.ps1 +++ b/build.ps1 @@ -34,7 +34,7 @@ if ((Get-Command "dotnet" -ErrorAction SilentlyContinue) -eq $null) { exit 1 } -Write-Output "Microsoft (R) .NET Core SDK version $(& dotnet --version)" +Write-Output "Microsoft (R) .NET SDK version $(& dotnet --version)" ExecSafe { & dotnet build $BuildProjectFile /nodeReuse:false /p:UseSharedCompilation=false /nologo /clp:NoSummary --verbosity quiet } ExecSafe { & dotnet run --project $BuildProjectFile --no-build -- $BuildArguments } diff --git a/build.sh b/build.sh index 6afa515d..406277bf 100755 --- a/build.sh +++ b/build.sh @@ -18,16 +18,12 @@ export NUKE_TELEMETRY_OPTOUT=1 # EXECUTION ########################################################################### -# Do not use -x to check for the presence of dotnet, -# because that might fail on bash under Alpine 3.14, see: -# https://github.com/alpinelinux/docker-alpine/issues/156 -# https://wiki.alpinelinux.org/wiki/Release_Notes_for_Alpine_3.14.0#faccessat2 -if ! [ -e "$(command -v dotnet)" ]; then +if ! [ -x "$(command -v dotnet)" ]; then echo 'Error: dotnet is not installed.' >&2 exit 1 fi -echo "Microsoft (R) .NET Core SDK version $(dotnet --version)" +echo "Microsoft (R) .NET SDK version $(dotnet --version)" dotnet build "$BUILD_PROJECT_FILE" -nodeReuse:false -p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet dotnet run --project "$BUILD_PROJECT_FILE" --no-build -- "$@" diff --git a/build/Build.cs b/build/Build.cs index 5f127d12..6d8ffd29 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -132,21 +132,10 @@ protected override void OnBuildInitialized() .DependsOn(Clean) .Executes(() => { - // Need to build the macOS and *nix DLL first. - DotNetBuild(c => c - .SetProjectFile(Solution.NetVips) - .SetConfiguration(Configuration) - .SetFramework("netstandard2.0") - .AddProperty("Platform", "AnyCPU") - .CombineWith( - new[] { "OSX", "Unix" }, - (_, os) => _.AddProperty("TargetOS", os))); - DotNetPack(c => c .SetProject(Solution.NetVips) .SetConfiguration(Configuration) .SetOutputDirectory(ArtifactsDirectory) - .AddProperty("TargetOS", "Windows") ); }); diff --git a/build/native/NetVips.Native.linux-arm.nuspec b/build/native/NetVips.Native.linux-arm.nuspec index 72caaec9..0451a10c 100644 --- a/build/native/NetVips.Native.linux-arm.nuspec +++ b/build/native/NetVips.Native.linux-arm.nuspec @@ -22,9 +22,6 @@ - - - @@ -35,7 +32,7 @@ - + \ No newline at end of file diff --git a/build/native/NetVips.Native.linux-arm64.nuspec b/build/native/NetVips.Native.linux-arm64.nuspec index 5d0ab745..851791d1 100644 --- a/build/native/NetVips.Native.linux-arm64.nuspec +++ b/build/native/NetVips.Native.linux-arm64.nuspec @@ -22,9 +22,6 @@ - - - @@ -35,7 +32,7 @@ - + \ No newline at end of file diff --git a/build/native/NetVips.Native.linux-musl-arm64.nuspec b/build/native/NetVips.Native.linux-musl-arm64.nuspec index 55078f30..ee36a3ae 100644 --- a/build/native/NetVips.Native.linux-musl-arm64.nuspec +++ b/build/native/NetVips.Native.linux-musl-arm64.nuspec @@ -32,8 +32,7 @@ - - + \ No newline at end of file diff --git a/build/native/NetVips.Native.linux-musl-x64.nuspec b/build/native/NetVips.Native.linux-musl-x64.nuspec index cb10a20e..ae087d69 100644 --- a/build/native/NetVips.Native.linux-musl-x64.nuspec +++ b/build/native/NetVips.Native.linux-musl-x64.nuspec @@ -22,9 +22,6 @@ - - - @@ -35,7 +32,7 @@ - + \ No newline at end of file diff --git a/build/native/NetVips.Native.linux-x64.nuspec b/build/native/NetVips.Native.linux-x64.nuspec index 044dd606..caa04483 100644 --- a/build/native/NetVips.Native.linux-x64.nuspec +++ b/build/native/NetVips.Native.linux-x64.nuspec @@ -22,9 +22,6 @@ - - - @@ -35,7 +32,7 @@ - + \ No newline at end of file diff --git a/build/native/NetVips.Native.nuspec b/build/native/NetVips.Native.nuspec index 2e157b2e..b655f72b 100644 --- a/build/native/NetVips.Native.nuspec +++ b/build/native/NetVips.Native.nuspec @@ -21,33 +21,20 @@ - - + - - - - - - - - - - - - - + diff --git a/build/native/NetVips.Native.osx-arm64.nuspec b/build/native/NetVips.Native.osx-arm64.nuspec index 299280d1..74bf7cd9 100644 --- a/build/native/NetVips.Native.osx-arm64.nuspec +++ b/build/native/NetVips.Native.osx-arm64.nuspec @@ -32,8 +32,7 @@ - - + \ No newline at end of file diff --git a/build/native/NetVips.Native.osx-x64.nuspec b/build/native/NetVips.Native.osx-x64.nuspec index 799d6e04..ce4a5866 100644 --- a/build/native/NetVips.Native.osx-x64.nuspec +++ b/build/native/NetVips.Native.osx-x64.nuspec @@ -22,9 +22,6 @@ - - - @@ -35,7 +32,7 @@ - + \ No newline at end of file diff --git a/build/native/NetVips.Native.win-arm64.nuspec b/build/native/NetVips.Native.win-arm64.nuspec index 190a4722..b9d39acf 100644 --- a/build/native/NetVips.Native.win-arm64.nuspec +++ b/build/native/NetVips.Native.win-arm64.nuspec @@ -32,8 +32,7 @@ - - + \ No newline at end of file diff --git a/build/native/NetVips.Native.win-x64.nuspec b/build/native/NetVips.Native.win-x64.nuspec index 1be73f0b..3ff799a0 100644 --- a/build/native/NetVips.Native.win-x64.nuspec +++ b/build/native/NetVips.Native.win-x64.nuspec @@ -22,8 +22,8 @@ - - + + diff --git a/build/native/NetVips.Native.win-x86.nuspec b/build/native/NetVips.Native.win-x86.nuspec index 4c208d2a..3d53872a 100644 --- a/build/native/NetVips.Native.win-x86.nuspec +++ b/build/native/NetVips.Native.win-x86.nuspec @@ -22,8 +22,8 @@ - - + + diff --git a/build/native/targets/NetVips.Native.linux-arm.targets b/build/native/targets/NetVips.Native.linux-arm.targets deleted file mode 100644 index 242b3a50..00000000 --- a/build/native/targets/NetVips.Native.linux-arm.targets +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - $(LibvipsOutputBase)\ - - - - - - $(LibvipsOutputBase)%(Filename)%(Extension) - PreserveNewest - - - - \ No newline at end of file diff --git a/build/native/targets/NetVips.Native.linux-arm64.targets b/build/native/targets/NetVips.Native.linux-arm64.targets deleted file mode 100644 index 62c13e13..00000000 --- a/build/native/targets/NetVips.Native.linux-arm64.targets +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - $(LibvipsOutputBase)\ - - - - - - $(LibvipsOutputBase)%(Filename)%(Extension) - PreserveNewest - - - - \ No newline at end of file diff --git a/build/native/targets/NetVips.Native.linux-musl-x64.targets b/build/native/targets/NetVips.Native.linux-musl-x64.targets deleted file mode 100644 index 84c5c801..00000000 --- a/build/native/targets/NetVips.Native.linux-musl-x64.targets +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - $(LibvipsOutputBase)\ - - - - - - $(LibvipsOutputBase)%(Filename)%(Extension) - PreserveNewest - - - - \ No newline at end of file diff --git a/build/native/targets/NetVips.Native.linux-x64.targets b/build/native/targets/NetVips.Native.linux-x64.targets deleted file mode 100644 index 1696b03c..00000000 --- a/build/native/targets/NetVips.Native.linux-x64.targets +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - $(LibvipsOutputBase)\ - - - - - - $(LibvipsOutputBase)%(Filename)%(Extension) - PreserveNewest - - - - \ No newline at end of file diff --git a/build/native/targets/NetVips.Native.osx-x64.targets b/build/native/targets/NetVips.Native.osx-x64.targets deleted file mode 100644 index 60abfd51..00000000 --- a/build/native/targets/NetVips.Native.osx-x64.targets +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - $(LibvipsOutputBase)\ - - - - - - $(LibvipsOutputBase)%(Filename)%(Extension) - PreserveNewest - - - - \ No newline at end of file diff --git a/build/test-mono.sh b/build/test-mono.sh deleted file mode 100755 index 7265bd1f..00000000 --- a/build/test-mono.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env bash - -set -eo pipefail - -########################################################################### -# CONFIGURATION -########################################################################### - -BUILD_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) -SCRIPT_DIR=$(dirname "$BUILD_DIR") - -XUNIT_RUNNER="$SCRIPT_DIR/packages/xunit.runner.console/tools/net472/xunit.console.exe" -BUILD_PROJECT_FILE="$SCRIPT_DIR/tests/NetVips.Tests/NetVips.Tests.csproj" -DLL_FILE="$SCRIPT_DIR/tests/NetVips.Tests/bin/Release/net472/NetVips.Tests.dll" - -# https://github.com/dotnet/runtime/issues/11540 -if [ "$(uname)" == "Darwin" ]; then - export DYLD_LIBRARY_PATH=$(dirname "$DLL_FILE")${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH} -elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then - export LD_LIBRARY_PATH=$(dirname "$DLL_FILE")${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} -fi - -# Parse arguments -while [ $# -gt 0 ]; do - case $1 in - --global-vips) USE_NUGET_BINARIES=false ;; - *) echo "Unknown parameter passed: $1" >&2; exit 1 ;; - esac - shift -done - -########################################################################### -# EXECUTION -########################################################################### - -if ! [ -x "$(command -v mono)" ]; then - echo 'Error: mono is not installed.' >&2 - exit 1 -fi - -echo "Mono version $(mono --version)" - -nuget install xunit.runner.console -ExcludeVersion -o packages -msbuild $BUILD_PROJECT_FILE -t:build -restore -p:TargetFramework="net472" -p:Configuration=Release -p:TestWithNuGetBinaries=${USE_NUGET_BINARIES:-true} -nodeReuse:false -mono $XUNIT_RUNNER $DLL_FILE diff --git a/docker.sh b/docker.sh index c31de595..72c24fb8 100755 --- a/docker.sh +++ b/docker.sh @@ -5,7 +5,7 @@ if ! [ -x "$(command -v docker)" ]; then exit 1 fi -# Ensure latest .NET Core SDK +# Ensure latest .NET SDK docker pull mcr.microsoft.com/dotnet/sdk:7.0-alpine # Create a machine image with all the required build tools pre-installed diff --git a/src/NetVips.Extensions/NetVips.Extensions.csproj b/src/NetVips.Extensions/NetVips.Extensions.csproj index 09ce78aa..e17f196a 100644 --- a/src/NetVips.Extensions/NetVips.Extensions.csproj +++ b/src/NetVips.Extensions/NetVips.Extensions.csproj @@ -3,10 +3,10 @@ - net70;net60;netstandard2.0;net461 + net7.0;net6.0;net461 - net70 - netstandard2.0 + net7.0 + net6.0 true NetVips.Extensions NetVips.Extensions @@ -25,22 +25,17 @@ - + - + - - - - - + diff --git a/src/NetVips/ExtensionMethods.cs b/src/NetVips/ExtensionMethods.cs index b61126bb..347f929d 100644 --- a/src/NetVips/ExtensionMethods.cs +++ b/src/NetVips/ExtensionMethods.cs @@ -38,19 +38,6 @@ internal static void Merge(this VOption self, VOption merge) } } - /// - /// Dereferences data from an unmanaged block of memory - /// to a newly allocated managed object of the specified type. - /// - /// The type of object to be created. This object - /// must represent a formatted class or a structure. - /// A pointer to an unmanaged block of memory. - /// A newly allocated managed object of the specified type. - internal static T Dereference(this IntPtr ptr) - { - return Marshal.PtrToStructure(ptr); - } - /// /// Call a libvips operation. /// diff --git a/src/NetVips/GObject.cs b/src/NetVips/GObject.cs index 105e0dd8..749b6bf2 100644 --- a/src/NetVips/GObject.cs +++ b/src/NetVips/GObject.cs @@ -196,7 +196,7 @@ internal IntPtr ObjectRef() /// /// Get the reference count of object. Handy for debugging. /// - internal uint RefCount => handle.Dereference().RefCount; + internal uint RefCount => Marshal.PtrToStructure(handle).RefCount; // Do not provide a finalizer - SafeHandle's critical finalizer will // call ReleaseHandle for us. diff --git a/src/NetVips/Interop/Libraries.OSX.cs b/src/NetVips/Interop/Libraries.OSX.cs deleted file mode 100644 index 572edcf2..00000000 --- a/src/NetVips/Interop/Libraries.OSX.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace NetVips.Interop -{ - internal static partial class Libraries - { - // We can safely define all these variables as `libvips.42.dylib` since - // DLLImport uses dlsym() on macOS. This function also searches for named - // symbols in the dependencies of the shared library. Therefore, we can - // provide libvips as a single shared library with all dependencies - // statically linked without breaking compatibility with shared builds - // (i.e. what is usually installed via package managers). - internal const string GLib = "libvips.42.dylib", - GObject = "libvips.42.dylib", - Vips = "libvips.42.dylib"; - } -} \ No newline at end of file diff --git a/src/NetVips/Interop/Libraries.Unix.cs b/src/NetVips/Interop/Libraries.Unix.cs deleted file mode 100644 index 93d2e274..00000000 --- a/src/NetVips/Interop/Libraries.Unix.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace NetVips.Interop -{ - internal static partial class Libraries - { - // We can safely define all these variables as `libvips.so.42` since - // DLLImport uses dlsym() on *nix. This function also searches for named - // symbols in the dependencies of the shared library. Therefore, we can - // provide libvips as a single shared library with all dependencies - // statically linked without breaking compatibility with shared builds - // (i.e. what is usually installed via package managers). - internal const string GLib = "libvips.so.42", - GObject = "libvips.so.42", - Vips = "libvips.so.42"; - } -} \ No newline at end of file diff --git a/src/NetVips/Interop/Libraries.Windows.cs b/src/NetVips/Interop/Libraries.Windows.cs deleted file mode 100644 index 002daed4..00000000 --- a/src/NetVips/Interop/Libraries.Windows.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace NetVips.Interop -{ - internal static partial class Libraries - { - // We cannot define all these variables as `libvips-42.dll` without - // breaking compatibility with the shared Windows build. Therefore, - // we always ship at least 3 DLLs. - internal const string GLib = "libglib-2.0-0.dll", - GObject = "libgobject-2.0-0.dll", - Vips = "libvips-42.dll"; - } -} \ No newline at end of file diff --git a/src/NetVips/Interop/Libraries.cs b/src/NetVips/Interop/Libraries.cs new file mode 100644 index 00000000..dcb80b4a --- /dev/null +++ b/src/NetVips/Interop/Libraries.cs @@ -0,0 +1,13 @@ +namespace NetVips.Interop +{ + internal static class Libraries + { + /// + /// These library names are remapped in a cross-platform manner, + /// . + /// + internal const string GLib = "libglib-2.0-0.dll", + GObject = "libgobject-2.0-0.dll", + Vips = "libvips-42.dll"; + } +} \ No newline at end of file diff --git a/src/NetVips/ModuleInitializer.cs b/src/NetVips/ModuleInitializer.cs index 43b184b0..e428d4c7 100644 --- a/src/NetVips/ModuleInitializer.cs +++ b/src/NetVips/ModuleInitializer.cs @@ -1,6 +1,10 @@ namespace NetVips { using System; + using System.Reflection; + using System.Collections.Generic; + using System.Runtime.InteropServices; + using Interop; /// /// All code inside the method is ran as soon as the assembly is loaded. @@ -22,12 +26,75 @@ public static class ModuleInitializer /// public static int? Version; +#if NET6_0_OR_GREATER + /// + /// Windows specific: is GLib statically-linked in `libvips-42.dll`? + /// + [System.Runtime.Versioning.SupportedOSPlatform("windows")] + private static bool _gLibStaticallyLinked = true; + + /// + /// A cache for . + /// + internal static readonly Dictionary DllImportCache = + new Dictionary(); + + internal static string RemapLibraryName(string libraryName) + { + // For Windows, we try to locate the GLib symbols within + // `libvips-42.dll` first. If these symbols cannot be found there, + // we proceed to locate them within `libglib-2.0-0.dll` and + // `libgobject-2.0-0.dll`. Note that distributing a single shared + // library is only possible when we drop support for .NET Framework. + // Therefore, we always ship at least 3 DLLs for now. + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return _gLibStaticallyLinked ? Libraries.Vips : libraryName; + } + + // We can safely remap the library names to `libvips.so.42` on *nix + // and `libvips.42.dylib` on macOS since DLLImport uses dlsym() there. + // This function also searches for named symbols in the dependencies + // of the shared library. Therefore, we can provide libvips as a + // single shared library with all dependencies statically linked + // without breaking compatibility with the shared builds + // (i.e. what is usually installed via package managers). + return RuntimeInformation.IsOSPlatform(OSPlatform.OSX) + ? "libvips.42.dylib" + : "libvips.so.42"; + } + + internal static IntPtr DllImportResolver(string libraryName, Assembly assembly, DllImportSearchPath? searchPath) + { + libraryName = RemapLibraryName(libraryName); + if (DllImportCache.TryGetValue(libraryName, out var cachedHandle)) + { + return cachedHandle; + } + + if (NativeLibrary.TryLoad(libraryName, assembly, searchPath, out var handle)) + { + DllImportCache[libraryName] = handle; + return handle; + } + + // Fallback to the default import resolver. + return IntPtr.Zero; + } +#endif + /// /// Initializes the module. /// +#pragma warning disable CA2255 [System.Runtime.CompilerServices.ModuleInitializer] +#pragma warning restore CA2255 public static void Initialize() { +#if NET6_0_OR_GREATER + NativeLibrary.SetDllImportResolver(typeof(ModuleInitializer).Assembly, DllImportResolver); +#endif + try { VipsInitialized = NetVips.Init(); @@ -36,6 +103,19 @@ public static void Initialize() Version = NetVips.Version(0, false); Version = (Version << 8) + NetVips.Version(1, false); Version = (Version << 8) + NetVips.Version(2, false); + +#if NET6_0_OR_GREATER + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return; + + try + { + _gLibStaticallyLinked = NetVips.TypeFromName("VipsImage") != IntPtr.Zero; + } + catch + { + _gLibStaticallyLinked = false; + } +#endif } else { diff --git a/src/NetVips/ModuleInitializerAttribute.cs b/src/NetVips/ModuleInitializerAttribute.cs index 47e805e2..06d6cea3 100644 --- a/src/NetVips/ModuleInitializerAttribute.cs +++ b/src/NetVips/ModuleInitializerAttribute.cs @@ -1,6 +1,6 @@ -// This file enables ModuleInitializer, a C# 9 feature to work with .NET Standard/Framework. +// This file enables ModuleInitializer, a C# 9 feature to work with .NET Framework. -#if NETSTANDARD || NETFRAMEWORK +#if NETFRAMEWORK namespace System.Runtime.CompilerServices { /// diff --git a/src/NetVips/NetVips.cs b/src/NetVips/NetVips.cs index 4cc5a55e..87ab2cec 100644 --- a/src/NetVips/NetVips.cs +++ b/src/NetVips/NetVips.cs @@ -511,7 +511,7 @@ IntPtr TypeMap(IntPtr type, IntPtr a, IntPtr b) public static Dictionary ValuesForEnum(IntPtr type) { var typeClass = GType.ClassRef(type); - var enumClass = typeClass.Dereference(); + var enumClass = Marshal.PtrToStructure(typeClass); var values = new Dictionary((int)(enumClass.NValues - 1)); @@ -520,7 +520,7 @@ public static Dictionary ValuesForEnum(IntPtr type) // -1 since we always have a "last" member for (var i = 0; i < enumClass.NValues - 1; i++) { - var enumValue = ptr.Dereference(); + var enumValue = Marshal.PtrToStructure(ptr); values[enumValue.ValueNick] = enumValue.Value; ptr += Marshal.SizeOf(typeof(GEnumValue)); diff --git a/src/NetVips/NetVips.csproj b/src/NetVips/NetVips.csproj index f45dba7d..03b3f91e 100644 --- a/src/NetVips/NetVips.csproj +++ b/src/NetVips/NetVips.csproj @@ -3,56 +3,26 @@ - netstandard2.0;net452 - netstandard2.0 + net6.0;net452 + net6.0 true Library x64;x86;ARM64;ARM32 true - $(DefaultItemExcludes);Interop\Libraries.*.cs false - false true true - - - Unix - OSX - Windows - - - - - $(MSBuildThisFileDirectory)bin\$(Platform)\$(Configuration)\$(TargetFramework)\$(TargetOS) - $(BaseIntermediateOutputPath)\$(Platform)\$(Configuration)\$(TargetFramework)\$(TargetOS)\ - - - - Interop\Libraries.cs - - + - - - - true - runtimes\unix\lib\netstandard2.0 - - - true - runtimes\osx\lib\netstandard2.0 - - - \ No newline at end of file diff --git a/src/NetVips/SourceCustom.cs b/src/NetVips/SourceCustom.cs index 09186160..59ede810 100644 --- a/src/NetVips/SourceCustom.cs +++ b/src/NetVips/SourceCustom.cs @@ -16,10 +16,10 @@ public class SourceCustom : Source /// A read delegate. /// /// - /// The interface is exactly as . The handler is given a number - /// of bytes to fetch, and should return a bytes-like object containing up - /// to that number of bytes. If there is no more data available, it should - /// return . + /// The interface is exactly as . + /// The handler is given a number of bytes to fetch, and should return a + /// bytes-like object containing up to that number of bytes. If there is + /// no more data available, it should return . /// /// An array of bytes. /// The maximum number of bytes to be read. diff --git a/src/NetVips/TargetCustom.cs b/src/NetVips/TargetCustom.cs index ce27775c..335fb0b9 100644 --- a/src/NetVips/TargetCustom.cs +++ b/src/NetVips/TargetCustom.cs @@ -16,9 +16,9 @@ public class TargetCustom : Target /// A write delegate. /// /// - /// The interface is the same as , so the handler is - /// given a bytes-like object to write. However, the handler MUST return the number - /// of bytes written. + /// The interface is the same as . + /// The handler is given a bytes-like object to write. However, the handler MUST + /// return the number of bytes written. /// /// An array of bytes. /// The number of bytes to be written to the current target. diff --git a/src/NetVips/VipsBlob.cs b/src/NetVips/VipsBlob.cs index 9d05046a..8404721c 100644 --- a/src/NetVips/VipsBlob.cs +++ b/src/NetVips/VipsBlob.cs @@ -61,11 +61,11 @@ protected override bool ReleaseHandle() /// /// Get the number of bytes of data. /// - internal ulong Length => (ulong)handle.Dereference().Length; + internal ulong Length => (ulong)Marshal.PtrToStructure(handle).Length; /// /// Get the reference count of the blob. Handy for debugging. /// - internal int RefCount => handle.Dereference().Count; + internal int RefCount => Marshal.PtrToStructure(handle).Count; } } \ No newline at end of file diff --git a/src/NetVips/VipsObject.cs b/src/NetVips/VipsObject.cs index df31bd7e..38c9d120 100644 --- a/src/NetVips/VipsObject.cs +++ b/src/NetVips/VipsObject.cs @@ -51,7 +51,7 @@ internal static void PrintAll() return argument != 0 ? default(GParamSpec.Struct?) - : pspec.Dereference(); + : Marshal.PtrToStructure(pspec); } /// diff --git a/tests/NetVips.Tests/NetVips.Tests.csproj b/tests/NetVips.Tests/NetVips.Tests.csproj index 1415f52f..e3981c13 100644 --- a/tests/NetVips.Tests/NetVips.Tests.csproj +++ b/tests/NetVips.Tests/NetVips.Tests.csproj @@ -14,30 +14,15 @@ false - - - linux-x64 - osx-x64 - - - - - - - - - - - - - + all runtime; build; native; contentfiles; analyzers; buildtransitive +