Skip to content

Commit

Permalink
Upgrade to .NET 9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
raulsntos committed Nov 16, 2024
1 parent 9958f9d commit e3888f3
Show file tree
Hide file tree
Showing 37 changed files with 68 additions and 259 deletions.
2 changes: 1 addition & 1 deletion eng/common/tasks/Tasks.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net9.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"sdk": {
"version": "8.0.200",
"version": "9.0.100",
"rollForward": "latestFeature"
},
"tools": {
"dotnet": "8.0.200"
"dotnet": "9.0.100"
}
}
2 changes: 1 addition & 1 deletion samples/Summator/Extension/Summator.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<PublishAot>true</PublishAot>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ namespace Godot.Bridge;

partial class ClassDBRegistrationContext
{
private Func<GodotObject>? _registeredConstructor;

internal Func<GodotObject>? RegisteredConstructor => _registeredConstructor;
internal Func<GodotObject>? RegisteredConstructor { get; private set; }

/// <summary>
/// Register a function to construct a new instance of the class.
Expand All @@ -15,6 +13,6 @@ partial class ClassDBRegistrationContext
public unsafe void BindConstructor(Func<GodotObject> constructor)
{
ArgumentNullException.ThrowIfNull(constructor);
_registeredConstructor = constructor;
RegisteredConstructor = constructor;
}
}
6 changes: 2 additions & 4 deletions src/Godot.Bindings/Core/GD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,7 @@ private unsafe static void ErrPrintError(string message, ErrorHandlerType type =
// TODO: Getting the caller information using the StackTrace API is problematic:
//
// - It won't work in NativeAOT:
// - StackFrame.GetMethod requires unrefenced code, the method may be trimmed.
// See: https://github.com/dotnet/runtime/issues/96528
// - The file name may also be unknown.
// - The file name may be unknown.
// - The line number is always 0.
// See: https://github.com/dotnet/runtime/issues/68714
// - Even when not using AOT, it may not retrieve the expected information:
Expand All @@ -367,7 +365,7 @@ private unsafe static void ErrPrintError(string message, ErrorHandlerType type =
var stackTrace = new StackTrace(skipFrames: 2, fNeedFileInfo: true);
var stackFrame = stackTrace.GetFrame(0);

string? callerName = stackFrame?.GetMethod()?.Name;
string? callerName = stackFrame is not null ? DiagnosticMethodInfo.Create(stackFrame)?.Name : null;
string? callerFilePath = stackFrame?.GetFileName();
int callerLineNumber = stackFrame?.GetFileLineNumber() ?? 0;

Expand Down
4 changes: 2 additions & 2 deletions src/Godot.Bindings/Godot.Bindings.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IsTrimmable>true</IsTrimmable>
<IsAotCompatible>true</IsAotCompatible>
Expand Down Expand Up @@ -32,7 +32,7 @@
<ProjectReference Include="..\Godot.BindingsGenerator\Godot.BindingsGenerator.csproj" ReferenceOutputAssembly="false" />
</ItemGroup>

<UsingTask TaskName="Godot.BindingsGenerator.GenerateTask" AssemblyFile="$(ArtifactsBinDir)\Godot.BindingsGenerator\$(Configuration)\net8.0\Godot.BindingsGenerator.dll" />
<UsingTask TaskName="Godot.BindingsGenerator.GenerateTask" AssemblyFile="$(ArtifactsBinDir)\Godot.BindingsGenerator\$(Configuration)\net9.0\Godot.BindingsGenerator.dll" />

<!-- Generate the bindings before building the project. -->
<ItemGroup Condition="'$(GenerateGodotBindings)' == 'true'">
Expand Down
30 changes: 9 additions & 21 deletions src/Godot.Bindings/NativeInterop/DelegateCallable.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using Godot.Bridge;

namespace Godot.NativeInterop;

internal sealed class DelegateCallable : CustomCallable, IEquatable<DelegateCallable>
{
private readonly Delegate _delegate;
private readonly unsafe delegate* managed<object, NativeGodotVariantPtrSpan, out NativeGodotVariant, void> _trampoline;

public object? Target
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _delegate.Target;
}
public object? Target => Delegate.Target;

public Delegate Delegate
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _delegate;
}
public Delegate Delegate { get; }

public unsafe DelegateCallable(Delegate @delegate, delegate* managed<object, NativeGodotVariantPtrSpan, out NativeGodotVariant, void> trampoline)
{
_delegate = @delegate;
Delegate = @delegate;
_trampoline = trampoline;
}

Expand All @@ -41,9 +31,7 @@ protected override ulong GetObjectId()

protected override bool TryGetArgumentCount(out long argCount)
{
// TODO: Replace with DiagnosticMethodInfo in .NET 9.0
// https://github.com/dotnet/runtime/issues/96528
argCount = _delegate.Method.GetParameters().Length;
argCount = Delegate.Method.GetParameters().Length;
return true;
}

Expand All @@ -55,18 +43,18 @@ protected override CallError _Call(ReadOnlySpan<Variant> args, out Variant resul

internal override unsafe void Call(NativeGodotVariantPtrSpan args, NativeGodotVariant* outRet, GDExtensionCallError* outError)
{
Debug.Assert(_delegate is not null);
Debug.Assert(Delegate is not null);
Debug.Assert(_trampoline is not null);

_trampoline(_delegate, args, out NativeGodotVariant ret);
_trampoline(Delegate, args, out NativeGodotVariant ret);

*outRet = ret;
outError->error = GDExtensionCallErrorType.GDEXTENSION_CALL_OK;
}

public override int GetHashCode()
{
return HashCode.Combine(_delegate);
return HashCode.Combine(Delegate);
}

public override bool Equals(object? obj)
Expand All @@ -76,11 +64,11 @@ public override bool Equals(object? obj)

public bool Equals(DelegateCallable? delegateCallable)
{
return EqualityComparer<Delegate>.Default.Equals(_delegate, delegateCallable?._delegate);
return EqualityComparer<Delegate>.Default.Equals(Delegate, delegateCallable?.Delegate);
}

public override string? ToString()
{
return _delegate.ToString();
return Delegate.ToString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private readonly ref struct ArrayPrivate
{
private readonly uint _safeRefCount;

private readonly NativeGodotVectorOfVariant _vector;
private readonly NativeGodotVector<NativeGodotVariant> _vector;

private unsafe readonly NativeGodotVariant* _readOnly;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Godot.NativeInterop;

[StructLayout(LayoutKind.Sequential)]
internal readonly ref struct NativeGodotVector<T> where T : unmanaged
internal readonly ref struct NativeGodotVector<T> where T : unmanaged, allows ref struct
{
private readonly nint _writeProxy;

Expand All @@ -26,56 +26,3 @@ public unsafe readonly int Size
return _ptr;
}
}

// These types are used when the generic type can't be used because T would be a ref struct
// and ref structs can't be used as generic type arguments yet.
// TODO: Remove when C# implements support for ref structs in generic type arguments.
// See: https://github.com/dotnet/csharplang/issues/1148

[StructLayout(LayoutKind.Sequential)]
internal readonly ref struct NativeGodotVectorOfString
{
private readonly nint _writeProxy;

private unsafe readonly NativeGodotString* _ptr;

public unsafe readonly int Size
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
// This code must match the method 'CowData::get_size' in the engine side.
return _ptr is not null ? (int)*((ulong*)_ptr - 1) : 0;
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal unsafe readonly NativeGodotString* GetPtrw()
{
return _ptr;
}
}

[StructLayout(LayoutKind.Sequential)]
internal readonly ref struct NativeGodotVectorOfVariant
{
private readonly nint _writeProxy;

private unsafe readonly NativeGodotVariant* _ptr;

public unsafe readonly int Size
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
// This code must match the method 'CowData::get_size' in the engine side.
return _ptr is not null ? (int)*((ulong*)_ptr - 1) : 0;
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal unsafe readonly NativeGodotVariant* GetPtrw()
{
return _ptr;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<IsTrimmable>true</IsTrimmable>
<IsAotCompatible>true</IsAotCompatible>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
Expand Down
12 changes: 5 additions & 7 deletions src/Godot.BindingsGenerator.ApiDump/Models/GodotApiType.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
using Godot.BindingsGenerator.ApiDump.Serialization;

namespace Godot.BindingsGenerator.ApiDump;

/// <summary>
/// Defines the type of an API.
/// </summary>
[JsonConverter(typeof(StringEnumConverter<GodotApiType>))]
[JsonConverter(typeof(JsonStringEnumConverter<GodotApiType>))]
public enum GodotApiType
{
/// <summary>
/// API defined in core types.
/// </summary>
[JsonPropertyName("core")]
[JsonStringEnumMemberName("core")]
Core = 1,

/// <summary>
/// API defined in editor types that aren't available in exported projects.
/// </summary>
[JsonPropertyName("editor")]
[JsonStringEnumMemberName("editor")]
Editor,

/// <summary>
/// API defined in extension types.
/// </summary>
[JsonPropertyName("extension")]
[JsonStringEnumMemberName("extension")]
Extension,

/// <summary>
/// API defined in extension editor types that aren't available in exported projects.
/// </summary>
[JsonPropertyName("editor_extension")]
[JsonStringEnumMemberName("editor_extension")]
EditorExtension,
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
using System.Diagnostics.CodeAnalysis;
using Godot.BindingsGenerator.ApiDump.Serialization;

namespace Godot.BindingsGenerator.ApiDump;

/// <summary>
/// The configuration used to build the Godot engine used to dump the extension API.
/// </summary>
[JsonConverter(typeof(StringEnumConverter<GodotBuildConfiguration>))]
[JsonConverter(typeof(JsonStringEnumConverter<GodotBuildConfiguration>))]
public enum GodotBuildConfiguration
{
/// <summary>
/// Godot was built for a 32-bits architecture, and with 32-bit floating-point precision.
/// </summary>
[SuppressMessage("Naming", "CA1720:Identifier contains type name", Justification = "The name of the enum value must match the string used by the API JSON dump.")]
[JsonPropertyName("float_32")]
[JsonStringEnumMemberName("float_32")]
Float32 = 1,

/// <summary>
/// Godot was built for a 64-bits architecture, and with 32-bit floating-point precision.
/// </summary>
[SuppressMessage("Naming", "CA1720:Identifier contains type name", Justification = "The name of the enum value must match the string used by the API JSON dump.")]
[JsonPropertyName("float_64")]
[JsonStringEnumMemberName("float_64")]
Float64,

/// <summary>
/// Godot was built for a 32-bits architecture, and with 64-bit floating-point precision.
/// </summary>
[JsonPropertyName("double_32")]
[JsonStringEnumMemberName("double_32")]
Double32,

/// <summary>
/// Godot was built for a 64-bits architecture, and with 64-bit floating-point precision.
/// </summary>
[JsonPropertyName("double_64")]
[JsonStringEnumMemberName("double_64")]
Double64,
}

This file was deleted.

Loading

0 comments on commit e3888f3

Please sign in to comment.