為 macOS 進行編譯¶
備註
This page describes how to compile macOS editor and export template binaries from source. If you're looking to export your project to macOS instead, read Exporting for macOS.
系統需求¶
若要在 macOS 下編譯,必須滿足下列需求:
SCons 3.0+ 建置系統。
Xcode (或更輕巧的適用於 Xcode 的命令行工具)。
可選 - yasm (用於最佳化 WebM SIMD)。
編譯¶
開啟終端機,移至 Godot 原始碼的根目錄。
若要為 Intel (x86-64) 核心的 Mac 編譯,請使用:
scons platform=osx arch=x86_64 --jobs=$(sysctl -n hw.logicalcpu)
To compile for Apple Silicon (ARM64) powered Macs, use:
scons platform=osx arch=arm64 --jobs=$(sysctl -n hw.logicalcpu)
若要使用單一「Universal 2」二進位執行檔來同時支援兩個架構,請執行上述兩個指令,然後通過 lipo
來將這兩個檔案捆綁在一起:
lipo -create bin/godot.osx.tools.x86_64 bin/godot.osx.tools.arm64 -output bin/godot.osx.tools.universal
若沒出現問題的話,產生的二進位執行檔會被放在 bin/
子資料夾中。該執行檔包含了完整的 Godot 遊戲引擎,且不需任何相依性套件即可執行。執行該檔案會開啟專案管理員。
備註
若想在客製化建置上使用與 Godot 官方釋出版本不同的編輯器設定,可以通過在 bin/
資料夾中建立檔名為 ._sc_
或 _sc_
的檔案來開啟 Self-contained mode 。
若要建立與官方建置相同的 .app
捆綁,則必須使用放在 misc/dist/osx_tools.app
樣板。一般來說,如果是使用 target=release_debug
建置的最佳化編輯器,則:
cp -r misc/dist/osx_tools.app ./Godot.app
mkdir -p Godot.app/Contents/MacOS
cp bin/godot.osx.opt.tools.universal Godot.app/Contents/MacOS/Godot
chmod +x Godot.app/Contents/MacOS/Godot
編譯無周邊版本與伺服器版本¶
若要編譯用於以編輯器功能來自動化匯出專案的 無周邊 版本,請使用:
scons platform=server tools=yes target=release_debug --jobs=$(sysctl -n hw.logicalcpu)
To compile a debug server build which can be used with remote debugging tools, use:
scons platform=server tools=no target=release_debug --jobs=$(sysctl -n hw.logicalcpu)
To compile a release server build which is optimized to run dedicated game servers, use:
scons platform=server tools=no target=release --jobs=$(sysctl -n hw.logicalcpu)
建置匯出樣板¶
To build macOS export templates, you have to compile with tools=no
(no
editor) and respectively for target=release
(release template) and
target=release_debug
.
Official templates are universal binaries which support both Intel x86_64 and
ARM64 architectures. You can also create export templates that support only one
of those two architectures by leaving out the lipo
step below.
For Intel x86_64:
scons platform=osx tools=no target=release arch=x86_64 --jobs=$(sysctl -n hw.logicalcpu) scons platform=osx tools=no target=release_debug arch=x86_64 --jobs=$(sysctl -n hw.logicalcpu)
For ARM64 (Apple M1):
scons platform=osx tools=no target=release arch=arm64 --jobs=$(sysctl -n hw.logicalcpu) scons platform=osx tools=no target=release_debug arch=arm64 --jobs=$(sysctl -n hw.logicalcpu)
To support both architectures in a single "Universal 2" binary, run the above
two commands blocks and then use lipo
to bundle them together:
lipo -create bin/godot.osx.opt.x86_64 bin/godot.osx.opt.arm64 -output bin/godot.osx.opt.universal
lipo -create bin/godot.osx.opt.debug.x86_64 bin/godot.osx.opt.debug.arm64 -output bin/godot.osx.opt.debug.universal
To create an .app
bundle like in the official builds, you need to use the
template located in misc/dist/osx_template.app
. The release and debug
builds should be placed in osx_template.app/Contents/MacOS
with the names
godot_osx_release.64
and godot_osx_debug.64
respectively. You can do so
with the following commands (assuming a universal build, otherwise replace the
.universal
extension with the one of your arch-specific binaries):
cp -r misc/dist/osx_template.app .
mkdir -p osx_template.app/Contents/MacOS
cp bin/godot.osx.opt.universal osx_template.app/Contents/MacOS/godot_osx_release.64
cp bin/godot.osx.opt.debug.universal osx_template.app/Contents/MacOS/godot_osx_debug.64
chmod +x osx_template.app/Contents/MacOS/godot_osx*
You can then zip the osx_template.app
folder to reproduce the osx.zip
template from the official Godot distribution:
zip -q -9 -r osx.zip osx_template.app
在 Linux 上為 macOS 進行交叉編譯¶
可以在 Linux 環境下為 macOS 編譯 (Windows 下也許可以使用適用於 Linux 的 Windows 子系統來編譯)。若要在 Linux 下為 macOS 交叉編譯,則必須安裝 OSXCross 來將 macOS 作為建置目標使用。首先,請依照下列指示安裝 OSXCross:
先 Clone OSXCross 儲存庫 至電腦上的某處 (或下載 ZIP 檔然後解壓縮)。如:
git clone --depth=1 https://github.com/tpoechtrager/osxcross.git "$HOME/osxcross"
請依照這個指示來打包 SDK:https://github.com/tpoechtrager/osxcross#packaging-the-sdk
請依照這個指示來安裝 OSXCross:https://github.com/tpoechtrager/osxcross#installation
之後,還需要將 OSXCROSS_ROOT
定義為 OSXCross 安裝的路徑 (也就是與儲存庫 Clone 或解壓縮的路徑)。如:
export OSXCROSS_ROOT="$HOME/osxcross"
之後就可以與平常一樣使用 SCons:
scons platform=osx
若 OSXCross 的 SDK 版本與 SCons 建置系統所預期不同,則必須通過 osxcross_sdk
引數來指定一個版本:
scons platform=osx osxcross_sdk=darwin15