Skip to content

Commit

Permalink
Merge pull request #92131 from paulloz/net8
Browse files Browse the repository at this point in the history
C#: Move GodotSharp to .NET8
  • Loading branch information
akien-mga authored Dec 13, 2024
2 parents 691d8be + fb8553e commit 7f5c469
Show file tree
Hide file tree
Showing 31 changed files with 278 additions and 250 deletions.
2 changes: 1 addition & 1 deletion modules/mono/build_scripts/build_assemblies.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def build_godot_api(msbuild_tool, module_dir, output_dir, push_nupkgs_local, pre

core_src_dir = os.path.abspath(os.path.join(sln, os.pardir, "GodotSharp", "bin", build_config))
editor_src_dir = os.path.abspath(os.path.join(sln, os.pardir, "GodotSharpEditor", "bin", build_config))
plugins_src_dir = os.path.abspath(os.path.join(sln, os.pardir, "GodotPlugins", "bin", build_config, "net6.0"))
plugins_src_dir = os.path.abspath(os.path.join(sln, os.pardir, "GodotPlugins", "bin", build_config, "net8.0"))

if not os.path.isdir(editor_api_dir):
assert not os.path.isfile(editor_api_dir)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>11</LangVersion>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>12</LangVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Test : CSharpAnalyzerTest<TAnalyzer, XUnitVerifier>
{
public Test()
{
ReferenceAssemblies = ReferenceAssemblies.Net.Net60;
ReferenceAssemblies = Constants.Net80;

SolutionTransforms.Add((Solution solution, ProjectId projectId) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;

namespace Godot.SourceGenerators.Tests;
Expand All @@ -17,7 +16,7 @@ public class Test : CSharpCodeFixTest<TAnalyzer, TCodeFix, XUnitVerifier>
{
public Test()
{
ReferenceAssemblies = ReferenceAssemblies.Net.Net60;
ReferenceAssemblies = Constants.Net80;
SolutionTransforms.Add((Solution solution, ProjectId projectId) =>
{
Project project = solution.GetProject(projectId)!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Test : CSharpSourceGeneratorTest<TSourceGenerator, XUnitVerifier>
{
public Test()
{
ReferenceAssemblies = ReferenceAssemblies.Net.Net60;
ReferenceAssemblies = Constants.Net80;

SolutionTransforms.Add((Solution solution, ProjectId projectId) =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
using System.IO;
using System.Reflection;
using Microsoft.CodeAnalysis.Testing;

namespace Godot.SourceGenerators.Tests;

public static class Constants
{
public static Assembly GodotSharpAssembly => typeof(GodotObject).Assembly;

// Can't find what needs updating to be able to access ReferenceAssemblies.Net.Net80, so we're making our own one.
public static ReferenceAssemblies Net80 => new ReferenceAssemblies(
"net8.0",
new PackageIdentity("Microsoft.NETCore.App.Ref", "8.0.0"),
Path.Combine("ref", "net8.0")
);

public static string ExecutingAssemblyPath { get; }
public static string SourceFolderPath { get; }
public static string GeneratedSourceFolderPath { get; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>

<LangVersion>11</LangVersion>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>12</LangVersion>

<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>10</LangVersion>
<Nullable>enable</Nullable>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>
<PropertyGroup>
<Description>Core C# source generator for Godot projects.</Description>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<ProjectGuid>{639E48BD-44E5-4091-8EDD-22D36DC0768D}</ProjectGuid>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>12</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<ProjectGuid>{A8CDAD94-C6D4-4B19-A7E7-76C53CC92984}</ProjectGuid>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>12</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build" Version="15.1.548" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Locator" Version="1.2.6" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GodotTools.Core\GodotTools.Core.csproj" />
<ProjectReference Include="..\GodotTools.Shared\GodotTools.Shared.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@ public static ProjectRootElement GenGameProject(string name)
root.Sdk = GodotSdkAttrValue;

var mainGroup = root.AddPropertyGroup();
mainGroup.AddProperty("TargetFramework", "net6.0");

var net7 = mainGroup.AddProperty("TargetFramework", "net7.0");
net7.Condition = " '$(GodotTargetPlatform)' == 'android' ";

var net8 = mainGroup.AddProperty("TargetFramework", "net8.0");
net8.Condition = " '$(GodotTargetPlatform)' == 'ios' ";
mainGroup.AddProperty("TargetFramework", "net8.0");

mainGroup.AddProperty("EnableDynamicLoading", "true");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<!-- Specify compile items manually to avoid including dangling generated items. -->
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>
<Import Project="GenerateGodotNupkgsVersions.targets" />

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>12</LangVersion>
<!-- Specify compile items manually to avoid including dangling generated items. -->
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>

<Import Project="GenerateGodotNupkgsVersions.targets" />

</Project>
12 changes: 10 additions & 2 deletions modules/mono/editor/GodotTools/GodotTools/GodotTools.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<ProjectGuid>{27B00618-A6F2-4828-B922-05CAEB08C286}</ProjectGuid>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>12</LangVersion>
<EnableDynamicLoading>true</EnableDynamicLoading>
<LangVersion>10</LangVersion>
<Nullable>enable</Nullable>
<!-- The Godot editor uses the Debug Godot API assemblies -->
<GodotApiConfiguration>Debug</GodotApiConfiguration>
Expand All @@ -13,20 +14,24 @@
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<!-- Needed for our source generators to work despite this not being a Godot game project -->
<PropertyGroup>
<IsGodotToolsProject>true</IsGodotToolsProject>
</PropertyGroup>

<ItemGroup>
<CompilerVisibleProperty Include="IsGodotToolsProject" />
</ItemGroup>

<PropertyGroup Condition=" Exists('$(GodotApiAssembliesDir)/GodotSharp.dll') ">
<!-- The project is part of the Godot source tree -->
<!-- Use the Godot source tree output folder instead of '$(ProjectDir)/bin' -->
<OutputPath>$(GodotOutputDataDir)/Tools</OutputPath>
<!-- Must not append '$(TargetFramework)' to the output path in this case -->
<AppendTargetFrameworkToOutputPath>False</AppendTargetFrameworkToOutputPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2019.1.3.0" ExcludeAssets="runtime" PrivateAssets="all" />
<PackageReference Include="JetBrains.Rider.PathLocator" Version="1.0.9" />
Expand All @@ -41,14 +46,17 @@
<Private>False</Private>
</Reference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Godot.NET.Sdk\Godot.SourceGenerators\Godot.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\..\..\glue\GodotSharp\Godot.SourceGenerators.Internal\Godot.SourceGenerators.Internal.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GodotTools.BuildLogger\GodotTools.BuildLogger.csproj" />
<ProjectReference Include="..\GodotTools.IdeMessaging\GodotTools.IdeMessaging.csproj" />
<ProjectReference Include="..\GodotTools.ProjectEditor\GodotTools.ProjectEditor.csproj" />
<ProjectReference Include="..\GodotTools.Core\GodotTools.Core.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>10</LangVersion>
<Nullable>enable</Nullable>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.10.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void AppendPartialContainingTypeDeclarations(INamedTypeSymbol? containingType)
{
var parameter = callback.Parameters[i];

AppendRefKind(source, parameter.RefKind);
AppendRefKind(source, parameter.RefKind, parameter.ScopedKind);
source.Append(' ');
source.Append(parameter.Type.FullQualifiedNameIncludeGlobal());
source.Append(' ');
Expand Down Expand Up @@ -208,7 +208,7 @@ void AppendPartialContainingTypeDeclarations(INamedTypeSymbol? containingType)
{
// If it's a by-ref param and we can't get the pointer
// just pass it by-ref and let it be pinned.
AppendRefKind(methodCallArguments, parameter.RefKind)
AppendRefKind(methodCallArguments, parameter.RefKind, parameter.ScopedKind)
.Append(' ')
.Append(parameter.Name);
}
Expand Down Expand Up @@ -346,7 +346,7 @@ void AppendPartialContainingTypeDeclarations(INamedTypeSymbol? containingType)
{
// If it's a by-ref param and we can't get the pointer
// just pass it by-ref and let it be pinned.
AppendRefKind(source, parameter.RefKind)
AppendRefKind(source, parameter.RefKind, parameter.ScopedKind)
.Append(' ')
.Append(parameter.Type.FullQualifiedNameIncludeGlobal());
}
Expand Down Expand Up @@ -392,14 +392,18 @@ private static bool IsGodotInteropStruct(ITypeSymbol type) =>
private static bool IsByRefParameter(IParameterSymbol parameter) =>
parameter.RefKind is RefKind.In or RefKind.Out or RefKind.Ref;

private static StringBuilder AppendRefKind(StringBuilder source, RefKind refKind) =>
refKind switch
private static StringBuilder AppendRefKind(StringBuilder source, RefKind refKind, ScopedKind scopedKind)
{
return (refKind, scopedKind) switch
{
RefKind.In => source.Append("in"),
RefKind.Out => source.Append("out"),
RefKind.Ref => source.Append("ref"),
(RefKind.Out, _) => source.Append("out"),
(RefKind.In, ScopedKind.ScopedRef) => source.Append("scoped in"),
(RefKind.In, _) => source.Append("in"),
(RefKind.Ref, ScopedKind.ScopedRef) => source.Append("scoped ref"),
(RefKind.Ref, _) => source.Append("ref"),
_ => source,
};
}

private static void AppendPointerType(StringBuilder source, ITypeSymbol type)
{
Expand Down
4 changes: 2 additions & 2 deletions modules/mono/glue/GodotSharp/GodotPlugins/GodotPlugins.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>12</LangVersion>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

Expand Down
21 changes: 8 additions & 13 deletions modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public Array()
/// <returns>A new Godot Array.</returns>
public Array(IEnumerable<Variant> collection) : this()
{
if (collection == null)
throw new ArgumentNullException(nameof(collection));
ArgumentNullException.ThrowIfNull(collection);

foreach (Variant element in collection)
Add(element);
Expand All @@ -67,8 +66,7 @@ public Array(IEnumerable<Variant> collection) : this()
/// <returns>A new Godot Array.</returns>
public Array(Variant[] array)
{
if (array == null)
throw new ArgumentNullException(nameof(array));
ArgumentNullException.ThrowIfNull(array);

NativeValue = (godot_array.movable)NativeFuncs.godotsharp_array_new();
_weakReferenceToSelf = DisposablesTracker.RegisterDisposable(this);
Expand Down Expand Up @@ -1056,7 +1054,7 @@ public sealed class Array<[MustBeVariant] T> :
IEnumerable<T>,
IGenericGodotArray
{
private static godot_variant ToVariantFunc(in Array<T> godotArray) =>
private static godot_variant ToVariantFunc(scoped in Array<T> godotArray) =>
VariantUtils.CreateFromArray(godotArray);

private static Array<T> FromVariantFunc(in godot_variant variant) =>
Expand All @@ -1080,8 +1078,8 @@ private void SetTypedForUnderlyingArray()

static unsafe Array()
{
VariantUtils.GenericConversion<Array<T>>.ToVariantCb = &ToVariantFunc;
VariantUtils.GenericConversion<Array<T>>.FromVariantCb = &FromVariantFunc;
VariantUtils.GenericConversion<Array<T>>.ToVariantCb = ToVariantFunc;
VariantUtils.GenericConversion<Array<T>>.FromVariantCb = FromVariantFunc;
}

private readonly Array _underlyingArray;
Expand Down Expand Up @@ -1114,8 +1112,7 @@ public Array()
/// <returns>A new Godot Array.</returns>
public Array(IEnumerable<T> collection)
{
if (collection == null)
throw new ArgumentNullException(nameof(collection));
ArgumentNullException.ThrowIfNull(collection);

_underlyingArray = new Array();
SetTypedForUnderlyingArray();
Expand All @@ -1134,8 +1131,7 @@ public Array(IEnumerable<T> collection)
/// <returns>A new Godot Array.</returns>
public Array(T[] array)
{
if (array == null)
throw new ArgumentNullException(nameof(array));
ArgumentNullException.ThrowIfNull(array);

_underlyingArray = new Array();
SetTypedForUnderlyingArray();
Expand All @@ -1154,8 +1150,7 @@ public Array(T[] array)
/// <returns>A new Godot Array.</returns>
public Array(Array array)
{
if (array == null)
throw new ArgumentNullException(nameof(array));
ArgumentNullException.ThrowIfNull(array);

_underlyingArray = array;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ internal static void FrameCallback()
}

[UnmanagedCallersOnly]
internal static unsafe IntPtr CreateManagedForGodotObjectBinding(godot_string_name* nativeTypeName,
IntPtr godotObject)
internal static unsafe IntPtr CreateManagedForGodotObjectBinding(godot_string_name* nativeTypeName, IntPtr godotObject)
{
try
{
Expand Down Expand Up @@ -143,7 +142,7 @@ internal static unsafe godot_bool CreateManagedForGodotObjectScriptInstance(IntP
}
}

var obj = (GodotObject)FormatterServices.GetUninitializedObject(scriptType);
var obj = (GodotObject)RuntimeHelpers.GetUninitializedObject(scriptType);

var parameters = ctor.GetParameters();
int paramCount = parameters.Length;
Expand Down
Loading

0 comments on commit 7f5c469

Please sign in to comment.