Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration to .NET 8 and enable AOT compilation #57

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
8.0.x
7.0.x
6.0.x
- name: Display dotnet version
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish-nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
8.0.x
7.0.x
6.0.x
- name: Display dotnet version
Expand Down
2 changes: 1 addition & 1 deletion src/Playground/Playground.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
<Configurations>Debug;Release;ReleaseWithDoc</Configurations>
Expand Down
2 changes: 1 addition & 1 deletion src/ZoneTree.UnitTests/ZoneTree.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>

Expand Down
43 changes: 36 additions & 7 deletions src/ZoneTree/Core/ZoneTreeMetaWAL.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Runtime.InteropServices;
using System.Text.Json;
using System.Text.Json.Serialization;
using Tenray.ZoneTree.Exceptions;
using Tenray.ZoneTree.Options;
using Tenray.ZoneTree.Segments.RandomAccess;
Expand Down Expand Up @@ -235,12 +236,7 @@
BottomSegments = bottomSegments,
};

var bytes = JsonSerializer.SerializeToUtf8Bytes(
newZoneTreeMeta,
new JsonSerializerOptions
{
WriteIndented = true
});
var bytes = JsonSerializeToUtf8Bytes(newZoneTreeMeta);
var deviceManager = Options.RandomAccessDeviceManager;
var metaFilePath = deviceManager.GetFilePath(0, MetaFileCategory);

Expand Down Expand Up @@ -289,10 +285,43 @@
var bytes = device.GetBytes(0, (int)device.Length);
device.Close();
deviceManager.RemoveReadOnlyDevice(device.SegmentId, MetaFileCategory);
var meta = JsonSerializer.Deserialize<ZoneTreeMeta>(bytes);
var meta = JsonDeserialize(bytes);
return meta;
}

private static byte[] JsonSerializeToUtf8Bytes(ZoneTreeMeta meta)
{
#if NET8_0_OR_GREATER
return JsonSerializer.SerializeToUtf8Bytes(
meta,
ZoneTreeMetaSourceGenerationContext.Default.ZoneTreeMeta);
#else
return JsonSerializer.SerializeToUtf8Bytes(
meta,
new JsonSerializerOptions()
{
WriteIndented = true
});
#endif
}

private static ZoneTreeMeta JsonDeserialize(byte[] bytes)
{
#if NET8_0_OR_GREATER
return JsonSerializer.Deserialize<ZoneTreeMeta>(bytes, ZoneTreeMetaSourceGenerationContext.Default.ZoneTreeMeta);
#else
return JsonSerializer.Deserialize<ZoneTreeMeta>(bytes);
#endif
}
}

#if NET8_0_OR_GREATER
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(ZoneTreeMeta))]
internal partial class ZoneTreeMetaSourceGenerationContext : JsonSerializerContext

Check warning on line 321 in src/ZoneTree/Core/ZoneTreeMetaWAL.cs

View workflow job for this annotation

GitHub Actions / build

Type 'ZoneTreeMetaSourceGenerationContext' can be sealed because it has no subtypes in its containing assembly and is not externally visible (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1852)
{
}
#endif

public enum MetaWalOperation
{
Expand Down
2 changes: 1 addition & 1 deletion src/ZoneTree/ZoneTree.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Deterministic>true</Deterministic>
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
<NeutralLanguage>en-US</NeutralLanguage>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<RepositoryUrl>https://github.com/koculu/ZoneTree</RepositoryUrl>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
Loading