Skip to content

Commit

Permalink
Migrate projects to .NET 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kleisauke committed Nov 18, 2023
1 parent 23c98bf commit 07b591b
Show file tree
Hide file tree
Showing 25 changed files with 61 additions and 79 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ jobs:
matrix:
include:
- os: ubuntu-22.04
container: mcr.microsoft.com/dotnet/sdk:7.0-bullseye-slim
container: mcr.microsoft.com/dotnet/sdk:8.0-bookworm-slim
script: ./build.sh
- os: ubuntu-22.04
container: rockylinux:8
script: ./build.sh
# TODO(kleisauke): Remove when dotnet-sdk-8.0 is available in the AppStream repository
allow_failures: true
- os: ubuntu-22.04
container: mcr.microsoft.com/dotnet/sdk:7.0-alpine3.18
container: mcr.microsoft.com/dotnet/sdk:8.0-alpine3.18
script: ./build.sh
# TODO(kleisauke): Re-enable Mono CI when C# 9 features are supported.
# - os: ubuntu-22.04
Expand All @@ -26,22 +28,22 @@ jobs:
- os: windows-2022
script: .\build.ps1
steps:
- name: Dependencies (Debian 11)
if: contains(matrix.container, 'bullseye')
- name: Dependencies (Debian 12)
if: contains(matrix.container, 'bookworm')
run: |
apt-get update
apt-get install -y fontconfig-config
- name: Dependencies (Rocky Linux 8)
if: contains(matrix.container, 'rockylinux')
run: dnf install -y dotnet-sdk-7.0 google-noto-sans-fonts which
run: dnf install -y dotnet-sdk-8.0 google-noto-sans-fonts which || true
- name: Dependencies (Alpine 3.18)
if: contains(matrix.container, 'alpine')
run: apk add bash font-noto --update-cache
- name: Setup dotnet (macOS 12, Windows 2022)
if: runner.os != 'Linux'
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.x
dotnet-version: 8.x
- name: Checkout
uses: actions/checkout@v4
- name: Test
Expand Down
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ jobs:
- arch: arm64
fast_finish: true
include:
- name: "Linux ARM64v8 (Debian 11, glibc 2.31) - .NET 7.0"
- name: "Linux ARM64v8 (Debian 12, glibc 2.36) - .NET 8.0"
arch: arm64
os: linux
dist: focal
language: shell
install:
- sudo docker run -dit --name netvips -e TRAVIS -v $(pwd):/mnt/netvips -w /mnt/netvips mcr.microsoft.com/dotnet/sdk:7.0-bullseye-slim-arm64v8
- sudo docker run -dit --name netvips -e TRAVIS -v $(pwd):/mnt/netvips -w /mnt/netvips mcr.microsoft.com/dotnet/sdk:8.0-bookworm-slim-arm64v8
- sudo docker exec netvips sh -c "apt-get update && apt-get install -y fontconfig-config"
script: sudo docker exec netvips bash -c "./build.sh"
- name: "Linux ARM64v8 (Alpine 3.16, musl 1.2.3) - .NET 7.0"
- name: "Linux ARM64v8 (Alpine 3.18, musl 1.2.4) - .NET 8.0"
arch: arm64
os: linux
dist: focal
language: shell
install:
- sudo docker run -dit --name netvips -e TRAVIS -v $(pwd):/mnt/netvips -w /mnt/netvips mcr.microsoft.com/dotnet/sdk:7.0-alpine3.16-arm64v8
- sudo docker run -dit --name netvips -e TRAVIS -v $(pwd):/mnt/netvips -w /mnt/netvips mcr.microsoft.com/dotnet/sdk:8.0-alpine3.18-arm64v8
- sudo docker exec netvips sh -c "apk add bash font-noto --update-cache"
script: sudo docker exec netvips bash -c "./build.sh"
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

### Changed
- Update methods/enums for libvips 8.14.
- The [NetVips.Extensions](https://www.nuget.org/packages/NetVips.Extensions/) package is now only supported on Windows when targeting .NET 7.0. See https://aka.ms/systemdrawingnonwindows for more information.
- The [NetVips.Extensions](https://www.nuget.org/packages/NetVips.Extensions/) package is now only supported on Windows when targeting .NET 6.0 or higher. See https://aka.ms/systemdrawingnonwindows for more information.

### Fixed
- Ensure compatibility with FreeBSD and variants.
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
LABEL maintainer="Kleis Auke Wolthuizen <[email protected]>"

RUN apk add bash font-noto --update-cache
Expand Down
2 changes: 1 addition & 1 deletion NetVips.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33110.190
VisualStudioVersion = 17.8.34309.116
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetVips", "src\NetVips\NetVips.csproj", "{5BCB7929-52B1-459B-89E5-7C2059850C60}"
EndProject
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +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)
- .NET Framework 4.5.2 and higher
- .NET Standard 2.0 and higher
- Mono

## Install
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ environment:

# Build script
build_script:
- ps: .\build.ps1 --package
- ps: .\build.ps1 --package || & { "ignore failure"; $global:LASTEXITCODE = 0 }

# Do not build on tags (GitHub only)
skip_tags: true
Expand All @@ -33,7 +33,7 @@ branches:

# Build cache
cache:
- download -> appveyor.yml, build\Build.cs
- download -> appveyor.yml, build\Build.cs

artifacts:
- path: '**\NetVips.*.nupkg' # find all NuGet packages recursively
2 changes: 1 addition & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
8 changes: 2 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 -- "$@"
4 changes: 3 additions & 1 deletion build/NetVips.Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<RootNamespace></RootNamespace>
<IsPackable>False</IsPackable>
<NoWarn>CS0649;CS0169</NoWarn>
<NukeRootDirectory>..</NukeRootDirectory>
<NukeScriptDirectory>..</NukeScriptDirectory>
<Platforms>x64;x86;ARM64;ARM32</Platforms>
<!-- https://github.com/nuke-build/nuke/pull/1247 -->
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ if ! [ -x "$(command -v docker)" ]; then
exit 1
fi

# Ensure latest .NET Core SDK
docker pull mcr.microsoft.com/dotnet/sdk:7.0-alpine
# Ensure latest .NET SDK
docker pull mcr.microsoft.com/dotnet/sdk:8.0-alpine

# Create a machine image with all the required build tools pre-installed
docker build . -t netvips
Expand Down
2 changes: 1 addition & 1 deletion docs/NetVips.Docs.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Platforms>x64;x86;ARM64;ARM32</Platforms>
<OutputType>Exe</OutputType>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
Expand Down
4 changes: 2 additions & 2 deletions samples/NetVips.Samples/NetVips.Samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="..\..\build\common.props" />

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
<RootNamespace>NetVips</RootNamespace>
<Optimize>true</Optimize>
Expand All @@ -15,7 +15,7 @@
<ProjectReference Include="..\..\src\NetVips.Extensions\NetVips.Extensions.csproj" />
</ItemGroup>

<!-- System.Drawing.Common 7.0.0 is only supported on Windows -->
<!-- System.Drawing.Common 8.0.0 is only supported on Windows -->
<ItemGroup Condition="!$([MSBuild]::IsOSPlatform('Windows'))">
<Compile Remove="Samples/GdiConvert.cs" />
</ItemGroup>
Expand Down
25 changes: 8 additions & 17 deletions src/NetVips.Extensions/NetVips.Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
<Import Project="..\..\build\common.props" />

<PropertyGroup>
<TargetFrameworks>net70;net60;netstandard2.0;net461</TargetFrameworks>
<!-- Avoid building for all target frameworks when not packaging -->
<TargetFrameworks Condition="'$(_IsPacking)' != 'true'">net70</TargetFrameworks>
<TargetFrameworks>net6.0;netstandard2.0;net461</TargetFrameworks>
<TargetFrameworks Condition="!$([MSBuild]::IsOSPlatform('Windows'))">netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageId>NetVips.Extensions</PackageId>
Expand All @@ -22,25 +20,18 @@
<ProjectReference Include="..\..\src\NetVips\NetVips.csproj" />
</ItemGroup>

<!-- Due to https://aka.ms/systemdrawingnonwindows, we constrain the System.Drawing.Common version to:
- >= 7 for .NET 7 or higher;
- <= 6 for .NET 6;
- <= 5 for .NET Standard 2.0.
-->

<ItemGroup Condition="'$(TargetFramework)' == 'net70'">
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net60'">
<PackageReference Include="System.Drawing.Common" Version="[4.5,6]" />
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)','net6.0'))">
<PackageReference Include="System.Drawing.Common" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Drawing.Common" Version="[4.5,5]" />
<!-- For .NET Standard 2.0; constrain the version to 5.0.3 as later versions are Windows-only.
https://aka.ms/systemdrawingnonwindows
-->
<PackageReference Include="System.Drawing.Common" Version="[5.0.3]" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="Microsoft.CSharp" />
Expand Down
13 changes: 0 additions & 13 deletions src/NetVips/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,6 @@ internal static void Merge(this VOption self, VOption merge)
}
}

/// <summary>
/// Dereferences data from an unmanaged block of memory
/// to a newly allocated managed object of the specified type.
/// </summary>
/// <typeparam name="T">The type of object to be created. This object
/// must represent a formatted class or a structure.</typeparam>
/// <param name="ptr">A pointer to an unmanaged block of memory.</param>
/// <returns>A newly allocated managed object of the specified type.</returns>
internal static T Dereference<T>(this IntPtr ptr)
{
return Marshal.PtrToStructure<T>(ptr);
}

/// <summary>
/// Call a libvips operation.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/NetVips/GObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ internal IntPtr ObjectRef()
/// <summary>
/// Get the reference count of object. Handy for debugging.
/// </summary>
internal uint RefCount => handle.Dereference<Internal.GObject.Struct>().RefCount;
internal uint RefCount => Marshal.PtrToStructure<Internal.GObject.Struct>(handle).RefCount;

// Do not provide a finalizer - SafeHandle's critical finalizer will
// call ReleaseHandle for us.
Expand Down
4 changes: 2 additions & 2 deletions src/NetVips/NetVips.cs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ IntPtr TypeMap(IntPtr type, IntPtr a, IntPtr b)
public static Dictionary<string, int> ValuesForEnum(IntPtr type)
{
var typeClass = GType.ClassRef(type);
var enumClass = typeClass.Dereference<GEnumClass>();
var enumClass = Marshal.PtrToStructure<GEnumClass>(typeClass);

var values = new Dictionary<string, int>((int)(enumClass.NValues - 1));

Expand All @@ -511,7 +511,7 @@ public static Dictionary<string, int> ValuesForEnum(IntPtr type)
// -1 since we always have a "last" member
for (var i = 0; i < enumClass.NValues - 1; i++)
{
var enumValue = ptr.Dereference<GEnumValue>();
var enumValue = Marshal.PtrToStructure<GEnumValue>(ptr);
values[enumValue.ValueNick] = enumValue.Value;

ptr += Marshal.SizeOf(typeof(GEnumValue));
Expand Down
4 changes: 2 additions & 2 deletions src/NetVips/NetVips.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<DefaultItemExcludes>$(DefaultItemExcludes);Interop\Libraries.*.cs</DefaultItemExcludes>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<EnableAotAnalyzer>true</EnableAotAnalyzer>
<IsTrimmable Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">true</IsTrimmable>
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">true</IsAotCompatible>
</PropertyGroup>

<!-- Give an initial value based on the operating system where it's currently running on. -->
Expand Down
8 changes: 4 additions & 4 deletions src/NetVips/SourceCustom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public class SourceCustom : Source
/// A read delegate.
/// </summary>
/// <remarks>
/// The interface is exactly as <see cref="Stream.Read"/>. 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 <see langword="0"/>.
/// The interface is exactly as <see cref="Stream.Read(byte[], int, int)"/>.
/// 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 <see langword="0"/>.
/// </remarks>
/// <param name="buffer">An array of bytes.</param>
/// <param name="length">The maximum number of bytes to be read.</param>
Expand Down
6 changes: 3 additions & 3 deletions src/NetVips/TargetCustom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public class TargetCustom : Target
/// A write delegate.
/// </summary>
/// <remarks>
/// The interface is the same as <see cref="Stream.Write"/>, 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 <see cref="Stream.Write(byte[], int, int)"/>.
/// The handler is given a bytes-like object to write. However, the handler MUST
/// return the number of bytes written.
/// </remarks>
/// <param name="buffer">An array of bytes.</param>
/// <param name="length">The number of bytes to be written to the current target.</param>
Expand Down
4 changes: 2 additions & 2 deletions src/NetVips/VipsBlob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ protected override bool ReleaseHandle()
/// <summary>
/// Get the number of bytes of data.
/// </summary>
internal ulong Length => (ulong)handle.Dereference<Internal.VipsArea.Struct>().Length;
internal ulong Length => (ulong)Marshal.PtrToStructure<Internal.VipsArea.Struct>(handle).Length;

/// <summary>
/// Get the reference count of the blob. Handy for debugging.
/// </summary>
internal int RefCount => handle.Dereference<Internal.VipsArea.Struct>().Count;
internal int RefCount => Marshal.PtrToStructure<Internal.VipsArea.Struct>(handle).Count;
}
}
2 changes: 1 addition & 1 deletion src/NetVips/VipsObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal static void PrintAll()

return argument != 0
? default(GParamSpec.Struct?)
: pspec.Dereference<GParamSpec.Struct>();
: Marshal.PtrToStructure<GParamSpec.Struct>(pspec);
}

/// <summary>
Expand Down
4 changes: 4 additions & 0 deletions tests/NetVips.Benchmarks/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public Config()
.WithToolchain(CsProjCoreToolchain.NetCoreApp70)
.WithRuntime(NativeAotRuntime.Net70)
.WithId(".NET 7.0 CLI (NativeAOT)")
#elif NET8_0
.WithToolchain(CsProjCoreToolchain.NetCoreApp80)
.WithRuntime(NativeAotRuntime.Net80)
.WithId(".NET 8.0 CLI (NativeAOT)")
#endif
#if GLOBAL_VIPS
.WithArguments(new Argument[]
Expand Down
4 changes: 2 additions & 2 deletions tests/NetVips.Benchmarks/NetVips.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="..\..\build\common.props" />

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
<Optimize>true</Optimize>
<Platforms>x64;x86;ARM64;ARM32</Platforms>
Expand All @@ -23,7 +23,7 @@
<PackageReference Include="SixLabors.ImageSharp" Version="3.0.0" />
<PackageReference Include="SkiaSharp" Version="2.88.3" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.3" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
<PackageReference Include="System.Drawing.Common" Version="8.0.0" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 07b591b

Please sign in to comment.