Monoでコンパイルする¶
必要条件¶
Mono 6.12.0 or greater
MSBuild
NuGet
On Linux/macOS only: pkg-config
HTTPS要求を実行するには、NuGetに必要な証明書をインポートする必要がある場合があります。
The recommended method is to use curl's CA (Certificate Authorities) certificate bundle.
次のコマンドを実行して、ダウンロードしてインポートします。Windowsでは、Monoコマンドラインプロンプト(またはMonoの bin
ディレクトリを PATH
環境変数に追加した場合は通常のプロンプト)から実行できます:
# If using PowerShell, replace `curl` with `curl.exe` below.
curl -LO https://curl.haxx.se/ca/cacert.pem
cert-sync --user cacert.pem
または、次のコマンドを使用できますが、非推奨であり、正しく機能しない場合があります:
mozroots --import --sync
環境変数¶
デフォルトでは、SConsはWindowsのWindowsレジストリまたは他のプラットフォームのpkg-configを介してMonoを見つけようとします。SConsに mono_prefix
コマンドラインオプションを渡すことで、別のインストールディレクトリを指定できます。例えば scons [...] mono_prefix=%ProgramFiles%/Mono
など。
これは、サブディレクトリ include
および lib
を含むディレクトリです。
Monoモジュールを有効にする¶
デフォルトでは、Monoモジュールはビルド時に無効になっています。有効にするには、SConsコマンドラインにオプション module_mono_enabled=yes
を追加します。
glueを生成する¶
glueソースは、マネージメソッドによって呼び出されるラッパー関数です。これらのソースファイルは、最終的なバイナリをビルドする前に生成する必要があります。それらを生成するには、まず、オプション tools=yes
および mono_glue=no
: で一時的なGodotバイナリをビルドする必要があります。
scons p=<platform> tools=yes module_mono_enabled=yes mono_glue=no
ビルドが完了したら、パラメーター --generate-mono-glue
に続けて出力ディレクトリへのパスを指定して、コンパイルされた実行可能ファイルを実行する必要があります。このパスは、Godotディレクトリの modules/mono/glue
でなければなりません:
<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>
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.
備考¶
mono_glue=no
で最終的なバイナリをビルドしないでください。これにより、C#スクリプトが無効になります。このオプションは、glueを生成する一時バイナリにのみ使用する必要があります。glueソースなしでビルドされた場合、Godotは起動時に警告を出力します。glueソースは、ClassDBに登録されたAPIが変更されるたびに再生成する必要があります。つまり、たとえば、新しいメソッドがスクリプトAPIに登録されたとき、またはそのようなメソッドのパラメーターの1つが変更されたときです。 ClassDBとグルーソースの間にAPIの不一致がある場合、Godotは起動時にエラーを出力します。
Mono glueで再構築¶
Mono glueを生成したら、mono_glue=yes
を使用して最終バイナリをビルドできます。これは mono_glue
のデフォルト値なので、省略することもできます。 Mono対応のエディタを作成するには:
scons p=<platform> tools=yes module_mono_enabled=yes mono_glue=yes
そして、Mono対応のエクスポートテンプレート:
scons p=<platform> tools=no module_mono_enabled=yes mono_glue=yes
通常の出力とは別に、すべてがうまくいった場合、SConsは bin
ディレクトリに以下のファイルを作成しているはずです:
Monoランタイムを静的にリンクしない場合、ビルドスクリプトはMonoランタイム共有ライブラリ(
monosgen-2.0
)を出力ディレクトリのGodotバイナリの隣に配置します。Godotを配布するときは、このライブラリを必ず含めてください。Androidを対象とする場合、このライブラリは#platform/android/java/libs
に自動的にコピーされ、Gradleが残りを処理するため、追加の手順は必要ありません。「クラシック」Godotビルドとは異なり、Monoモジュールを有効にしてビルドする場合(およびターゲットプラットフォームに応じて)、エディタとエクスポートテンプレートの両方にデータディレクトリが作成される場合があります。このディレクトリは適切に機能するために重要であり、Godotとともに配布する必要があります。このディレクトリの詳細は、:re:`データディレクトリ <compiling_with_mono_data_directory>` にあります。
例¶
例(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
例(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
データディレクトリ¶
データディレクトリは、Monoモジュールを有効にして構築されたGodotバイナリの依存関係です。Godotが正しく機能するための重要なファイルが含まれています。Godot実行可能ファイルと一緒に配布する必要があります。
注釈
The information below doesn't apply for Android, iOS and WASM, as there is no data directory for these platforms.
エクスポートテンプレート¶
エクスポートテンプレートのデータディレクトリの名前は、それが構築された構成によって異なります。形式は data.mono.<platform>.<bits>.<target> `` です。例: ``data.mono.x11.32.release_debug
または data.mono.windows.64.release
。
このディレクトリは、Godotエクスポートテンプレートの横に元の名前で配置する必要があります。プロジェクトをエクスポートするとき、Godotはこのディレクトリをゲームの実行可能ファイルとともにコピーしますが、名前は data_<APPNAME> `` に変更されます。ここで、\ ``<APPNAME> `` はプロジェクト設定で指定されたアプリケーション名 ``application/config/name
です。
エクスポートテンプレートがZIPアーカイブとして圧縮されているmacOSの場合、データディレクトリのコンテンツはZIPアーカイブ内の次の場所に配置できます:
|
|
|
|
エディタ¶
Godotエディタのデータディレクトリの名前は、常に GodotSharp
です。このディレクトリの内容は次のとおりです:
Api
Mono
(オプション)Tools
Api
サブディレクトリにはGodot APIアセンブリが含まれています。macOSでは、Godotエディタがバンドルとして配布されている場合、データディレクトリのコンテンツは次の場所に配置できます:
|
|
|
|
|
|
|
|
Mono
サブディレクトリはオプションです。ユーザーがインストールしたMonoバージョンがGodotエディタのビルドに使用したものと同一でない場合に問題が発生する可能性があるため、エディタを配布するときに必要になります。このフォルダとその内容を作成するためにエディタをビルドするときは、SConsに copy_mono_root=yes
を渡します。
Tools
サブディレクトリには、GodotTools
アセンブリやその依存関係など、エディタに必要なツールが含まれています。
Building the Mono runtime¶
When building Godot for the desktop, you will likely use the pre-built Mono runtime that is installed on your system. This likely won't be the case when targeting other platforms like Android, iOS and WebAssembly. You will have to build the Mono runtime yourself for those platforms.
We recommend using these build scripts. They simplify this process but also include some patches needed for proper functioning with Godot. See the README on the link above for instructions on how to use the scripts.
Androidをターゲットとする¶
Monoを使用したAndroidエクスポートテンプレートのコンパイルは、構築後に追加の手順が必要ないため、デスクトッププラットフォームの場合よりも少し簡単です。Gradleプロジェクトに自動的に追加されるため、データディレクトリや共有ライブラリ(動的リンクの場合)などの実行時の依存関係を心配する必要はありません。
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).
Targeting 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.
The following bash script will create the "fat" libraries in the directory #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
.
Targeting WebAssembly¶
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).
Base Class Library¶
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
.
Alternatively, Godot will look for them in the following locations:
Android |
|
iOS |
|
WebAssembly |
|
Linux and 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-compilers¶
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/
.
In order to build the cross-compilers we recommend using these build scripts.
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
.
コマンドラインオプション¶
以下は、Monoモジュールでビルドするときに使用できるコマンドラインオプションのリストです:
module_mono_enabled=yes | no
Monoモジュールを有効にしてGodotをビルド。
mono_glue=yes | no
ビルドにグルー ソースファイルを含め、プリプロセッサマクロとして
MONO_GLUE_DISABLED
を定義するかどうか。
mono_prefix=path
ターゲット プラットフォームとアーキテクチャ用のMonoインストール ディレクトリへのパス。
mono_static=yes | no
Monoランタイムを静的にリンクするかどうか。
The default is yes for iOS and WASM, and no for other platforms.
copy_mono_root=yes | no
Godotエディタに必要なMonoフレームワークアセンブリと構成ファイルをコピーするかどうか。