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

Dotnet Sdk not updating when exporting #89792

Open
TCROC opened this issue Mar 22, 2024 · 0 comments
Open

Dotnet Sdk not updating when exporting #89792

TCROC opened this issue Mar 22, 2024 · 0 comments

Comments

@TCROC
Copy link
Contributor

TCROC commented Mar 22, 2024

Tested versions

Godot v4.3.dev.mono (e6d09ef)

System information

Godot v4.3.dev.mono (e6d09ef) - Pop!_OS 22.04 LTS - Wayland - Vulkan (Forward+) - dedicated Intel(R) Arc(tm) A750 Graphics (DG2) () - AMD Ryzen 7 5800X 8-Core Processor (16 Threads)

Issue description

This was a very tricky one to debug. Mainly because the dotnet nuget builds when building from source seem to be updating the godot engine build correctly. However, when exporting (at least for Linux) they do not seem to update. In my case, I had an old cache from last year. And as a result, my linux exports where segfaulting. The only way to seem to get the the export to take the new dotnet builds is to delete the dotnet build outputs in the mono module.

Fortunately a bash script can take care of cleaning this for us since dotnet clean does not seem to work and the --push-nupkgs-local arg as described here also doesn't seem to work: https://docs.godotengine.org/en/stable/contributing/development/compiling/compiling_with_dotnet.html#nuget-packages

This script will delete all folders ignored by git in the folder passed to it:

#!/bin/bash

set -e

prev_pwd="$PWD"

dir_to_clean="$1"
cd "$dir_to_clean"
echo "cleaning directory: $dir_to_clean"
files_to_remove="$(git status . --ignored --short)"

if [[ "$files_to_remove" == "" ]]
then
    echo "$dir_to_clean: nothing to remove"
    exit 0
fi

echo "Removing the following files and folders:"
echo "${files_to_remove[@]}"

# This command removes all files that are gitignored.  This is useful for removing files that 
# ``scons --clean`` doesn't remove such as the mono glue.
#
# Explanation of commands:
#
# Lists all the files and folders that are being ignored due .gitignore
# git status --ignored --short
#
# Removes the !! that ``git status --ignored --short`` outputs.
# NOTE: This could be an issue if we ever name a file or folder with !
# sed 's/!//g'
#
# Replaces all newline charactes with a ' ' so ``git status --ignored --short`` is space delimited
# tr '\n' ' '
#
# Removes all of the files and folders returned after formatting the output
# rm -rf
#
rm -rf $(echo "${files_to_remove[@]}" | sed 's/!//g' | tr '\n' ' ')

cd "$prev_pwd"

And it can be called like this:

# Clean the dotnet build cache because the cache is not being cleared as the godot documentation
# suggests it should.  And this is just another level of certainty that the cache is cleared.
"$dir/clean-ignore.sh" godot/modules/mono/glue/GodotSharp
"$dir/clean-ignore.sh" godot/modules/mono/editor/Godot.NET.Sdk
"$dir/clean-ignore.sh" godot/modules/mono/editor/GodotTools

Steps to reproduce

  1. Build godot mono from source.
  2. Build the Linux export template for mono. Then export a build.
  3. Make a change to the C# code. Ideally something we know will get called like the generated c# code in godot/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/GodotPluginsInitializerGenerator.cs. In my case, I added a Console.WriteLine("Hello") inside InitializeFromGameProject so it looks like:
string source =
                @"using System;
using System.Runtime.InteropServices;
using Godot.Bridge;
using Godot.NativeInterop;

namespace GodotPlugins.Game
{
    internal static partial class Main
    {
        [UnmanagedCallersOnly(EntryPoint = ""godotsharp_game_main_init"")]
        private static godot_bool InitializeFromGameProject(IntPtr godotDllHandle, IntPtr outManagedCallbacks,
            IntPtr unmanagedCallbacks, int unmanagedCallbacksSize)
        {
            Console.WriteLine("Hello");
            try
            {
                DllImportResolver dllImportResolver = new GodotDllImportResolver(godotDllHandle).OnResolveDllImport;

                var coreApiAssembly = typeof(global::Godot.GodotObject).Assembly;

                NativeLibrary.SetDllImportResolver(coreApiAssembly, dllImportResolver);

                NativeFuncs.Initialize(unmanagedCallbacks, unmanagedCallbacksSize);

                ManagedCallbacks.Create(outManagedCallbacks);

                ScriptManagerBridge.LookupScriptsInAssembly(typeof(global::GodotPlugins.Game.Main).Assembly);

                return godot_bool.True;
            }
            catch (Exception e)
            {
                global::System.Console.Error.WriteLine(e);
                return false.ToGodotBool();
            }
        }
    }
}
";

Then rebuild the c# glue and assemblies.

Docs here: https://docs.godotengine.org/en/stable/contributing/development/compiling/compiling_with_dotnet.html#building-the-managed-libraries

And here: https://docs.godotengine.org/en/stable/contributing/development/compiling/compiling_with_dotnet.html#nuget-packages

Minimal reproduction project (MRP)

NA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants