goostengine / goost

A general-purpose, extensible and customizable C++ extension for Godot Engine.
https://goostengine.github.io/
MIT License
479 stars 18 forks source link

Unable to compile with Mono on custom build #186

Closed GlitchedCode closed 2 years ago

GlitchedCode commented 2 years ago

Goost and Godot version: latest gd3 commit, and custom Godot build based on latest 3.x commit

OS/platform/device including version:

Arch Linux

dotnet --list-sdks
5.0.403 [/usr/share/dotnet/sdk]
6.0.102 [/usr/share/dotnet/sdk]

Issue description: I want to build Goost against my custom Godot build with Mono support. Compiling with mono glue enabled fails with the following errors:

/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/MeshLibrary.cs(71,25): error CS0117: 'NativeCalls' non contiene una definizione per 'godot_icall_2_647' [/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/MeshLibrary.cs(95,25): error CS0117: 'NativeCalls' non contiene una definizione per 'godot_icall_2_647' [/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/MeshLibrary.cs(108,25): error CS0117: 'NativeCalls' non contiene una definizione per 'godot_icall_2_648' [/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/MeshInstance.cs(158,32): error CS0117: 'NativeCalls' non contiene una definizione per 'godot_icall_0_476' [/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/MeshLibrary.cs(144,86): error CS1503: Argomento 3: non è possibile convertire da 'int' a 'System.IntPtr' [/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/MeshLibrary.cs(156,25): error CS0117: 'NativeCalls' non contiene una definizione per 'godot_icall_1_650' [/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/MeshInstance.cs(194,32): error CS0117: 'NativeCalls' non contiene una definizione per 'godot_icall_1_634' [/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/MeshInstance.cs(206,32): error CS0117: 'NativeCalls' non contiene una definizione per 'godot_icall_1_634' [/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/MeshDataTool.cs(67,39): error CS0117: 'NativeCalls' non contiene una definizione per 'godot_icall_2_638' [/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/MeshDataTool.cs(79,39): error CS0117: 'NativeCalls' non contiene una definizione per 'godot_icall_1_639' [/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]

... # and a  lot more of the same kind

Steps to reproduce: Clone Goost and symlink custom godot source tree inside Goost local repository. Use scons as described in the Goost and Godot documentation for building from source: i compile with mono enabled and no glue, then i generate the glue, and then i recompile with glue.

scons p=x11 target=release_debug tools=yes bits=64 module_mono_enabled=yes mono_glue=no -j8
godot/bin/godot.x11.opt.tools.64.goost.mono --generate-mono-glue godot/modules/mono/glue
scons p=x11 target=release_debug tools=yes bits=64 module_mono_enabled=yes mono_glue=yes-j8

Is this issue reproducible in official Godot builds? No.

Minimal reproduction project: N/A

Xrayez commented 2 years ago

Is this issue reproducible in official Godot builds? No.

Are you sure about this? The provided log doesn't contain any Goost classes. Could you share the full log?

This may be a regression in Godot.

Note that I no longer provide Mono builds officially. However, contributions to fix Mono-related bugs are welcomed.

GlitchedCode commented 2 years ago

I often rebase my fork (which does not touch Mono support) with the latest additions to Godot's 3.x branch, and it builds fine with Mono support. Building Godot with the same scons arguments works fine. build.log

Xrayez commented 2 years ago

@GlitchedCode do you use other modules in your custom Godot build (beside Goost)? Without actually testing this myself yet, I don't see how compiling Godot + Goost could lead to this kind of problem to be honest.

Clone Goost and symlink custom godot source tree inside Goost local repository.

Instead of symlink, you could specify GODOT_SOURCE_PATH environment variable.

You may try to build from within Godot root instead (build Godot + Goost via custom_modules option). I'd actually recommend to build this way for production, especially if you plan to build Godot with other modules.

GlitchedCode commented 2 years ago

Thank you for pointing me to more resources, i tried out a few more times and, sadly, building from godot's source tree using custom_modules i get the same result from above, though i am now noticing the following errors are thrown when i try to generate the glue after the first build.

ERROR: Condition "getter->return_type.cname != setter->arguments.back()->get().type.cname" is true. Returned: ERR_BUG
   at: _generate_cs_property (modules/mono/editor/bindings_generator.cpp:1419)
ERROR: Failed to generate property 'format' for class 'MidiFile'.
   at: _generate_cs_type (modules/mono/editor/bindings_generator.cpp:1290)
ERROR: Generation of the Core API C# project failed.
   at: generate_cs_api (modules/mono/editor/bindings_generator.cpp:1110)
ERROR: --generate-mono-glue: Failed to generate the C# API.
   at: handle_cmdline_options (modules/mono

And yes, Goost is the only module i'm adding to Godot in this build.

Xrayez commented 2 years ago

CC @filipworksdev, looks like MidiFile has inconsistent return type somewhere which fails C# Mono glue generation.

@GlitchedCode If this only affects MidiFile and you're not interested in it, as a workaround you could try to compile Goost without audio component for now (both when building with and without Mono glue):

scons goost_audio_enabled=no

I could fix this myself but given Russia's invasion in Ukraine, it's difficult for me to do any kind of development at the moment, but I'll likely fix this issue myself eventually after Godot 3.5 is released.

filipworksdev commented 2 years ago

Ahh sorry guys I don't do any Mono whatsoever. Someone who does Mono would need to fix this. I have completely dropped Mono from my custom build.

GlitchedCode commented 2 years ago

The changes in my PR fix the aforementioned issue, but there is an additional problem with these errors being thrown during the final step of a Mono build

/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/Debug2D.cs(188,73): error CS1503: Argomento 2: non è possibile convertire da 'double' a 'float' [/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/Debug2D.cs(188,77): error CS1503: Argomento 3: non è possibile convertire da 'double' a 'float' [/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/Debug2D.cs(216,73): error CS1503: Argomento 2: non è possibile convertire da 'double' a 'float' [/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/Debug2D.cs(216,77): error CS1503: Argomento 3: non è possibile convertire da 'double' a 'float' [/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/Debug2D.cs(231,73): error CS1503: Argomento 2: non è possibile convertire da 'double' a 'float' [/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/Debug2D.cs(231,77): error CS1503: Argomento 3: non è possibile convertire da 'double' a 'float' [/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/Debug2D.cs(245,73): error CS1503: Argomento 2: non è possibile convertire da 'double' a 'float' [/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/Debug2D.cs(245,77): error CS1503: Argomento 3: non è possibile convertire da 'double' a 'float' [/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/Debug2D.cs(263,73): error CS1503: Argomento 2: non è possibile convertire da 'double' a 'float' [/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/Debug2D.cs(263,77): error CS1503: Argomento 3: non è possibile convertire da 'double' a 'float' [/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/Debug2D.cs(279,73): error CS1503: Argomento 2: non è possibile convertire da 'double' a 'float' [/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/Debug2D.cs(279,77): error CS1503: Argomento 3: non è possibile convertire da 'double' a 'float' [/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/Debug2D.cs(295,73): error CS1503: Argomento 2: non è possibile convertire da 'double' a 'float' [/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/Debug2D.cs(295,77): error CS1503: Argomento 3: non è possibile convertire da 'double' a 'float' [/home/glitchedcode/repos/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]

Which are caused by the way Godot's code generation algorithm generates the glue, passing double constants (the default in C#) to Color's constructor which accepts floats. This can be worked around by adding the following constructor to the Color class in godot/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs:

/// <summary>
/// Constructs a <see cref="Color"/> from RGBA values, typically on the range of 0 to 1.
/// </summary>
/// <param name="r">The color's red component, typically on the range of 0 to 1.</param>
/// <param name="g">The color's green component, typically on the range of 0 to 1.</param>
/// <param name="b">The color's blue component, typically on the range of 0 to 1.</param>
/// <param name="a">The color's alpha (transparency) value, typically on the range of 0 to 1. Default: 1.</param>
public Color(double r, double g, double b, double a = 1.0f)
{
    this.r = (float)r;
    this.g = (float)g;
    this.b = (float)b;
    this.a = (float)a;
}

But if you're particularly pedantic about the semantics of floating-point maths this is not optimal. I'm going to open an issue to Godot's repo and eventually a PR to get this sorted out. On the bright side, Godot and Goost with Mono support now gets compiled just fine.