Kompilieren mit Mono¶
Voraussetzungen¶
Mono 5.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.
Die empfohlene Methode ist die Verwendung des CA-Zertifikatspakets (CA = Certificate Authorities) von curl.
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
After the build finishes, you need to run the compiled executable with the
parameter --generate-mono-glue
followed by the path to an output directory.
This path must be modules/mono/glue
in the Godot directory:
<godot_binary> --generate-mono-glue modules/mono/glue
This command will tell Godot to generate the file modules/mono/glue/mono_glue.gen.cpp
and the C# solution for the Godot API at modules/mono/glue/Managed/Generated
.
Once these files are generated, you can build Godot for all the desired targets
without having to repeat this process.
<godot_binary>
refers to the tools binary you compiled above with the Mono
module enabled. Its exact name will differ based on your system and
configuration, but should be of the form
bin/godot.<platform>.tools.<bits>.mono
, e.g. bin/godot.x11.tools.64.mono
or bin/godot.windows.tools.64.mono.exe
. Be especially aware of the .mono
suffix! If you've previously compiled Godot without Mono support, you might have
similarly named binaries without this suffix. These binaries can't be used to
generate the Mono glue.
Anmerkungen¶
Do not build your final binaries with
mono_glue=no
. This disables C# scripting. This option must be used only for the temporary binary that will generate the glue. Godot will print a warning at startup if it was built without the glue sources.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:
|
|
|
|
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:
|
|
|
|
|
|
|
|
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 |
|
iOS |
|
WebAssembly |
|
Linux und MacOS |
|
Windows |
|
As of now, we're assuming the same BCL profile can be used for both Linux and macOS, but this may change in the future as they're not guaranteed to be the same (as is the case with the Windows BCL).
If the target platform is the same as the platform of the Godot editor,
then the editor will use the BCL it's running on (<data_folder>/Mono/lib/mono/4.5
)
if it cannot find the BCL in the export templates.
AOT-Cross-Compiler¶
To perform ahead-of-time (AOT) compilation for other platforms, Godot needs to have access to the Mono cross-compilers for that platform and architecture.
Godot will look for the cross-compiler executable in the AOT compilers folder.
The location of this folder is <data_folder>/Tools/aot-compilers/
.
Um die Cross-Compiler zu erstellen, empfehlen wir die Verwendung dieser Build-Skripte.
After building them, copy the executable to the Godot AOT compilers directory. The
executable name is <triple>-mono-sgen
, e.g.: aarch64-apple-darwin-mono-sgen
.
Kommandozeilenoptionen¶
The following is the list of command-line options available when building with the Mono module:
module_mono_enabled=yes | no
Erstellen Sie Godot mit aktiviertem Mono-Modul.
mono_glue=ja | nein
Whether to include the glue source files in the build and define
MONO_GLUE_DISABLED
as a preprocessor macro.
mono_prefix=path
Pfad zum Mono-Installationsverzeichnis für die Zielplattform und -architektur.
xbuild_fallback=yes | no
Gibt an, ob auf xbuild zurückgegriffen werden soll, wenn MSBuild nicht verfügbar ist.
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
Whether to copy the Mono framework assemblies and configuration files required by the Godot editor.