Skip to content

Commit

Permalink
Migration to .NET 8 and enable AOT compilation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jozef Gajdos committed Jun 14, 2024
1 parent b61f0ba commit e4406dc
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 10 deletions.
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 @@ public void SaveMetaData(
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 @@ public static ZoneTreeMeta LoadZoneTreeMetaWithoutWALRecords(
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

0 comments on commit e4406dc

Please sign in to comment.