Kompilieren mit Mono

Voraussetzungen

  • Mono 6.12.0 oder höher

  • MSBuild

  • NuGet

  • Nur auf Linux/MacOS: pkg-config

Möglicherweise müssen Sie die erforderlichen Zertifikate importieren, damit NuGet HTTPS-Anforderungen ausführen kann.

The recommended method is to use curl's CA (Certificate Authorities) certificate bundle.

Run the following commands to download and import it. On Windows, you can run it from the Mono command line prompt (or the regular prompt if you added Mono's bin directory to your PATH environment variable):

# If using PowerShell, replace `curl` with `curl.exe` below.
curl -LO https://curl.haxx.se/ca/cacert.pem
cert-sync --user cacert.pem

Alternativ können Sie den folgenden Befehl verwenden, obwohl er veraltet ist und möglicherweise nicht richtig funktioniert:

mozroots --import --sync

Umgebungsvariablen

By default, SCons will try to find Mono in the Windows Registry on Windows or via pkg-config on other platforms. You can specify a different installation directory by passing the mono_prefix command-line option to SCons; e.g. scons [...] mono_prefix=%ProgramFiles%/Mono.

Dies ist das Verzeichnis, das die Unterverzeichnisse include und lib enthält.

Aktivieren Sie das Mono-Modul

By default, the Mono module is disabled when building. To enable it, add the option module_mono_enabled=yes to the SCons command line.

Generieren Sie den Kleber

Glue sources are the wrapper functions that will be called by managed methods. These source files must be generated before building your final binaries. In order to generate them, first, you must build a temporary Godot binary with the options tools=yes and mono_glue=no:

scons p=<platform> tools=yes module_mono_enabled=yes mono_glue=no

Nachdem der Build beendet ist, muss man das kompilierte Programm mit dem Parameter --generate-mono-glue, gefolgt von dem Pfad zu einem Ausgabeverzeichnis, ausführen. Dieser Pfad muss modules/mono/glue im Godot-Verzeichnis sein:

<godot_binary> --generate-mono-glue modules/mono/glue

This command will tell Godot to generate the file modules/mono/glue/mono_glue.gen.cpp, the C# solution for the Godot API at modules/mono/glue/GodotSharp/GodotSharp/Generated, and the C# solution for the editor tools at modules/mono/glue/GodotSharp/GodotSharpEditor/Generated. Once these files are generated, you can build Godot for all the desired targets without having to repeat this process.

<godot_binary> bezieht sich auf das Tools-Binary, das oben mit aktiviertem Mono-Modul kompiliert wurde. Sein genauer Name hängt von Ihrem System und Ihrer Konfiguration ab, sollte aber die Form bin/godot.<Plattform>.tools.<bits>.mono haben, z.B. bin/godot.x11.tools.64.mono oder bin/godot.windows.tools.64.mono.exe. Achten Sie besonders auf das Suffix .mono! Wenn Godot zuvor ohne Mono-Unterstützung kompiliert wurde, haben Sie möglicherweise ähnlich benannte Binärdateien ohne dieses Suffix. Diese Binärdateien können nicht verwendet werden, um den Mono-Glue zu erzeugen.

Anmerkungen

  • Erstellen Sie Ihre endgültigen Binärdateien nicht mit mono_glue=no. Dadurch wird die C#-Skripterstellung deaktiviert. Diese Option muss nur für die temporäre Binärdatei verwendet werden, die den Glue erzeugt. Godot wird beim Start eine Warnung ausgeben, wenn es ohne die Glue-Quellen gebaut wurde.

  • The glue sources must be regenerated every time the ClassDB-registered API changes. That is, for example, when a new method is registered to the scripting API or one of the parameters of such a method changes. Godot will print an error at startup if there is an API mismatch between ClassDB and the glue sources.

Rebuild with Mono glue

Sobald Sie den Mono-Glue erzeugt haben, können Sie die endgültige Binärdatei mit mono_glue=yes builden. Dies ist der Standardwert für mono_glue, Sie können ihn also auch weglassen. Um einen Mono-aktivierten Editor zu bauen:

scons p=<platform> tools=yes module_mono_enabled=yes mono_glue=yes

Und Mono-fähige Exportvorlagen:

scons p=<platform> tools=no module_mono_enabled=yes mono_glue=yes

Wenn alles gut gelaufen ist, sollte SCons, abgesehen von der normalen Ausgabe, die folgenden Dateien im bin-Verzeichnis erzeugt haben:

  • Wenn Sie die Mono-Runtime nicht statisch linken, legt das Build-Skript die Mono-Runtime-Shared-Library (monosgen-2.0) neben der Godot-Binary im Ausgabeverzeichnis ab. Stellen Sie sicher, dass Sie diese Bibliothek beim Verteilen von Godot einbinden. Wenn Sie auf Android abzielen, sind keine zusätzlichen Schritte erforderlich, da diese Bibliothek automatisch nach #platform/android/java/libs kopiert wird und Gradle sich um den Rest kümmert.

  • Im Gegensatz zu "klassischen" Godot-Builds kann beim builden mit aktiviertem Mono-Modul (und abhängig von der Zielplattform) ein Datenverzeichnis sowohl für den Editor als auch für Exportvorlagen angelegt werden. Dieses Verzeichnis ist wichtig für die korrekte Funktion und muss zusammen mit Godot verteilt werden. Mehr Details über dieses Verzeichnis in Datenverzeichnis.

Beispiele

Beispiel (Windows)

# Build temporary binary
scons p=windows tools=yes module_mono_enabled=yes mono_glue=no
# Generate glue sources
bin\godot.windows.tools.64.mono --generate-mono-glue modules/mono/glue

### Build binaries normally
# Editor
scons p=windows target=release_debug tools=yes module_mono_enabled=yes
# Export templates
scons p=windows target=release_debug tools=no module_mono_enabled=yes
scons p=windows target=release tools=no module_mono_enabled=yes

Beispiel (X11)

# Build temporary binary
scons p=x11 tools=yes module_mono_enabled=yes mono_glue=no
# Generate glue sources
bin/godot.x11.tools.64.mono --generate-mono-glue modules/mono/glue

### Build binaries normally
# Editor
scons p=x11 target=release_debug tools=yes module_mono_enabled=yes
# Export templates
scons p=x11 target=release_debug tools=no module_mono_enabled=yes
scons p=x11 target=release tools=no module_mono_enabled=yes

Datenverzeichnis

Das Datenverzeichnis ist eine Abhängigkeit für Godot-Binärdateien, die mit aktiviertem Mono-Modul erstellt wurden. Es enthält wichtige Dateien für die korrekte Funktion von Godot. Es muss zusammen mit der ausführbaren Godot-Datei verteilt werden.

Bemerkung

Die folgenden Informationen gelten nicht für Android, iOS und WASM, da es für diese Plattformen kein Datenverzeichnis gibt.

Exportvorlagen

Der Name des Datenverzeichnisses für eine Exportvorlage unterscheidet sich je nach der Konfiguration, mit der sie erstellt wurde. Das Format ist data.mono.<Plattform>.<Bits>.<Ziel>, z. B. data.mono.x11.32.release_debug oder data.mono.windows.64.release.

Dieses Verzeichnis muss mit seinem ursprünglichen Namen neben die Godot-Exportvorlagen gelegt werden. Beim Exportieren eines Projekts kopiert Godot dieses Verzeichnis auch mit der ausführbaren Datei des Spiels, aber der Name wird in data_<APPNAME> geändert, wobei <APPNAME> der Anwendungsname ist, wie er in der Projekteinstellung application/config/name angegeben ist.

Bei MacOS, bei dem die Exportvorlage als ZIP-Archiv komprimiert ist, kann der Inhalt des Datenverzeichnisses an folgenden Stellen im ZIP-Archiv abgelegt werden:

bin/data.mono.<platform>.<bits>.<target>/Mono/lib

/osx_template.app/Contents/Frameworks/GodotSharp/Mono/lib

bin/data.mono.<platform>.<bits>.<target>/Mono/etc

/osx_template.app/Contents/Resources/GodotSharp/Mono/etc

Editor

Der Name des Datenverzeichnisses für den Godot-Editor wird immer GodotSharp lauten. Der Inhalt dieses Verzeichnisses ist der folgende:

  • Api

  • Mono (Optional)

  • Werkzeuge

Das Unterverzeichnis Api enthält die Godot-API-Baugruppen. Unter macOS, wenn der Godot-Editor als Bundle verteilt wird, kann der Inhalt des Datenverzeichnisses an den folgenden Stellen abgelegt werden:

bin/data.mono.<platform>.<bits>.<target>/Api

<bundle_name>.app/Contents/Frameworks/GodotSharp/Api

bin/data.mono.<platform>.<bits>.<target>/Mono/lib

<bundle_name>.app/Contents/Frameworks/GodotSharp/Mono/lib

bin/data.mono.<platform>.<bits>.<target>/Mono/etc

<bundle_name>.app/Contents/Resources/GodotSharp/Mono/etc

bin/data.mono.<platform>.<bits>.<target>/Tools

<bundle_name>.app/Contents/Frameworks/GodotSharp/Tools

Das Unterverzeichnis Mono ist optional. Es wird bei der Verteilung des Editors benötigt, da Probleme auftreten können, wenn die vom Benutzer installierte Mono-Version nicht mit derjenigen identisch ist, mit der Godot-Editor gebaut wurde. Übergeben Sie copy_mono_root=yes an SCons beim Erstellen des Editors, um diesen Ordner und seinen Inhalt zu erzeugen.

Das Unterverzeichnis Tools enthält Werkzeuge, die vom Editor benötigt werden, so wie die GodotTools-Assemblies und deren Abhängigkeiten.

Erstellen der Mono-Laufzeit

Wenn Sie Godot für den Desktop erstellen, werden Sie wahrscheinlich die vorgefertigte Mono-Laufzeit verwenden, die auf Ihrem System installiert ist. Dies wird wahrscheinlich nicht der Fall sein, wenn Sie andere Plattformen wie Android, iOS und WebAssembly anvisieren. Für diese Plattformen müssen Sie die Mono-Laufzeitumgebung selbst erstellen.

Wir empfehlen die Verwendung dieser build-Skripte. Sie vereinfachen diesen Prozess, enthalten aber auch einige Patches, die für die korrekte Funktion mit Godot benötigt werden. Eine Anleitung zur Verwendung der Skripte finden Sie in der README unter dem obigen Link.

Für Android

Compiling the Android export templates with Mono is a bit simpler than it is for the desktop platforms, as there are no additional steps required after building. There is no need to worry about run-time dependencies like a data directory or the shared library (when dynamically linking) as those are automatically added to the Gradle project.

Once you've built Mono, you can proceed to build Godot with the instructions described in this page and the Compiling for Android page. Make sure to let SCons know about the location of the Mono runtime you've just built, e.g.: scons [...] mono_prefix="$HOME/mono-installs/android-armeabi-v7a-release" (This path may be different on your system).

Für iOS

Once you've built Mono, you can proceed to build Godot with the instructions described in this page and the Compiling for iOS page. Make sure to let SCons know about the location of the Mono runtime you've just built, e.g.: scons [...] mono_prefix="$HOME/mono-installs/ios-arm64-release" (This path may be different on your system).

After building Godot for each architecture, you will notice SCons has copied the Mono libraries for each of them to the output directory:

#bin/libmono-native.iphone.<arch>.a
#bin/libmonosgen-2.0.iphone.<arch>.a
#bin/libmonoprofiler-log.iphone.<arch>.a

#bin/libmono-ilgen.iphone.<arch>.a
#bin/libmono-ee-interp.iphone.<arch>.a
#bin/libmono-icall-table.iphone.<arch>.a

The last three are only for iOS devices and are not available for the iOS simulator.

These libraries must be put in universal (multi-architecture) "fat" files to be distributed with the export templates.

Das folgende Bash-Skript erstellt die "fetten" Bibliotheken im Verzeichnis #bin/ios/iphone-mono-libs:

mkdir -p bin/ios
mkdir -p bin/ios/iphone-mono-libs

lipo -create bin/libmonosgen-2.0.iphone.arm64.a bin/libmonosgen-2.0.iphone.x86_64.a -output bin/ios/iphone-mono-libs/libmonosgen-2.0.iphone.fat.a
lipo -create bin/libmono-native.iphone.arm64.a bin/libmono-native.iphone.x86_64.a -output bin/ios/iphone-mono-libs/libmono-native.iphone.fat.a
lipo -create bin/libmono-profiler-log.iphone.arm64.a bin/libmono-profiler-log.iphone.x86_64.a -output bin/ios/iphone-mono-libs/libmono-profiler-log.iphone.fat.a

# The Mono libraries for the interpreter are not available for simulator builds
lipo -create bin/libmono-ee-interp.iphone.arm64.a -output bin/ios/iphone-mono-libs/libmono-ee-interp.iphone.fat.a
lipo -create bin/libmono-icall-table.iphone.arm64.a -output bin/ios/iphone-mono-libs/libmono-icall-table.iphone.fat.a
lipo -create bin/libmono-ilgen.iphone.arm64.a -output bin/ios/iphone-mono-libs/libmono-ilgen.iphone.fat.a

The iphone-mono-libs folder must be distributed with the export templates. The Godot editor will look for the libraries in <templates>/iphone-mono-libs/lib<name>.iphone.fat.a.

WebAssembly im Visier

Building for WebAssembly currently involves the same process regardless of whether the Mono module is enabled.

Once you've built Mono, you can proceed to build Godot with the instructions described in this page and the Compiling for the Web page. Make sure to let SCons know about the location of the Mono runtime you've just built, e.g.: scons [...] mono_prefix="$HOME/mono-installs/wasm-runtime-release" (This path may be different on your system).

Basisklassenbibliothek

The export templates must also include the BCL (Base Class Library) for each target platform. Godot looks for the BCL folder at <templates>/bcl/<target_platform>, where <target_platform> is the same name passed to the SCons platform option, e.g.: <templates>/bcl/windows, <templates>/bcl/javascript.

Alternativ wird Godot sie an folgenden Orten suchen:

Android

<templates>/bcl/monodroid

iOS

<templates>/bcl/monotouch

WebAssembly

<templates>/bcl/wasm

Linux und MacOS

<templates>/bcl/net_4_x

Windows

<templates>/bcl/net_4_x_win

Im Moment gehen wir davon aus, dass das gleiche BCL-Profil sowohl für Linux als auch für macOS verwendet werden kann, aber das kann sich in Zukunft ändern, da nicht garantiert ist, dass sie gleich sind (wie es bei der Windows-BCL der Fall ist).

Wenn die Zielplattform die gleiche ist wie die Plattform des Godot-Editors, dann verwendet der Editor die BCL, auf der er läuft (<data_folder>/Mono/lib/mono/4.5), wenn er die BCL in den Exportvorlagen nicht findet.

AOT-Cross-Compiler

Um eine ahead-of-time (AOT) Kompilierung für andere Plattformen durchzuführen, muss Godot Zugriff auf die Mono-Cross-Compiler für diese Plattform und Architektur haben.

Godot sucht nach der ausführbaren Cross-Compiler-Datei im AOT-Compiler-Ordner. Der Ort dieses Ordners ist <data_folder>/Tools/aot-compilers/.

Um die Cross-Compiler zu erstellen, empfehlen wir die Verwendung dieser Build-Skripte.

Nach dem Erzeugen kopieren Sie die ausführbare Datei in das Godot-AOT-Compiler-Verzeichnis. Der Name der ausführbaren Datei ist <triple>-mono-sgen, z.B.: aarch64-apple-darwin-mono-sgen.

Kommandozeilenoptionen

Im Folgenden finden Sie eine Liste der Befehlszeilenoptionen, die beim Erstellen mit dem Mono-Modul verfügbar sind:

  • module_mono_enabled=yes | no

    • Erstellen Sie Godot mit aktiviertem Mono-Modul.

  • mono_glue=ja | nein

    • Ob die Glue-Quelldateien in den Build eingeschlossen und MONO_GLUE_DISABLED als Präprozessormakro definiert werden soll.

  • mono_prefix=path

    • Pfad zum Mono-Installationsverzeichnis für die Zielplattform und -architektur.

  • mono_static=yes | no

    • Gibt an, ob die Mono-Laufzeit statisch verknüpft werden soll.

    • Die Standardeinstellung ist ja* für iOS und WASM, und **nein für andere Plattformen.

  • copy_mono_root=yes | no

    • Ob die für den Godot-Editor erforderlichen Mono-Framework-Bereiche und Konfigurationsdateien kopiert werden sollen.