Up to date
This page is up to date for Godot 4.2
.
If you still find outdated information, please open an issue.
為 macOS 進行編譯¶
備註
這個頁面描述的是如何從源碼編譯 macOS 編輯器和匯出範本二進位檔案。如果你要找的是匯出專案到 macOS,請閱讀 為 macOS 匯出。
系統需求¶
若要在 macOS 下編譯,必須滿足下列需求:
SCons 3.0+ 建置系統。
Xcode (或更輕巧的適用於 Xcode 的命令行工具)。
適用於 MoltenVK 的「Vulkan SDK <https://sdk.lunarg.com/sdk/download/latest/mac/vulkan-sdk.dmg>」(macOS 不支援開箱即用的 Vulkan)。
編譯¶
開啟終端機,移至 Godot 原始碼的根目錄。
若要為 Intel (x86-64) 核心的 Mac 編譯,請使用:
scons platform=macos arch=x86_64
若要為 Apple Silicon (ARM64) 核心的 Mac 編譯,請使用 (僅可用於 Godot 3.2.3+):
scons platform=macos arch=arm64
若要使用單一「Universal 2」二進位執行檔來同時支援兩個架構,請執行上述兩個指令,然後通過 lipo
來將這兩個檔案捆綁在一起:
lipo -create bin/godot.macos.editor.x86_64 bin/godot.macos.editor.arm64 -output bin/godot.macos.editor.universal
若沒出現問題的話,產生的二進位執行檔會被放在 bin/
子資料夾中。該執行檔包含了完整的 Godot 遊戲引擎,且不需任何相依性套件即可執行。執行該檔案會開啟專案管理員。
備註
若想在客製化建置上使用與 Godot 官方釋出版本不同的編輯器設定,可以通過在 bin/
資料夾中建立檔名為 ._sc_
或 _sc_
的檔案來開啟 自包含模式 。
To create an .app
bundle like in the official builds, you need to use the
template located in misc/dist/macos_tools.app
. Typically, for an optimized
editor binary built with dev_build=yes
:
cp -r misc/dist/macos_tools.app ./Godot.app
mkdir -p Godot.app/Contents/MacOS
cp bin/godot.macos.editor.universal Godot.app/Contents/MacOS/Godot
chmod +x Godot.app/Contents/MacOS/Godot
codesign --force --timestamp --options=runtime --entitlements misc/dist/macos/editor.entitlements -s - Godot.app
備註
如果您正在建立「master」分支,您還需要包含對 MoltenVK Vulkan 可移植性庫的支援。預設情況下,它將透過您安裝的適用於 macOS 的 Vulkan SDK 進行靜態連結。您也可以選擇透過傳遞“use_volk=yes”並將動態庫包含在“.app”包中來動態連結它:
mkdir -p Godot.app/Contents/Frameworks
cp <Vulkan SDK path>/macOS/lib/libMoltenVK.dylib Godot.app/Contents/Frameworks/libMoltenVK.dylib
編譯無周邊版本與伺服器版本¶
若要編譯用於以編輯器功能來自動化匯出專案的 無周邊 版本,請使用:
scons platform=macos target=editor
然後使用“--headless”命令列參數:
./bin/godot.macos.editor.x86_64 --headless
如果要編譯除錯版本的*伺服器*,支援:ref:遠端除錯工具 <doc_command_line_tutorial>,那麼請使用:
scons platform=macos target=template_debug
若要編譯可執行專屬遊戲伺服器的 伺服器 版本,請使用:
scons platform=macos target=template_release production=yes
建置匯出樣板¶
要建立macOS的匯出範本,你必須用 tools=no
(無編輯器)進行編譯,並分別為 target=release
(發行範本)和 target=release_debug
.
官方範本是通用的二進位檔案,同時支援英特爾x86_64和ARM64架構。你也可以通過省略下面的 lipo
步驟,建立只支援架構中的一種的匯出範本。
對於英特爾 x86_64:
scons platform=macos target=template_release arch=x86_64 scons platform=macos target=template_debug arch=x86_64
對於 ARM64(Apple M1):
scons platform=macos target=template_release arch=arm64 scons platform=macos target=template_debug arch=arm64
若要使用單一「Universal 2」二進位執行檔來同時支援兩個架構,請執行上述兩個指令,然後通過 lipo
來將這兩個檔案捆綁在一起:
lipo -create bin/godot.macos.opt.x86_64 bin/godot.macos.opt.arm64 -output bin/godot.macos.opt.universal
lipo -create bin/godot.macos.opt.debug.x86_64 bin/godot.macos.opt.debug.arm64 -output bin/godot.macos.opt.debug.universal
要建立一個像官方建構的 .app
組合包,你需要使用位於 misc/dist/osx_template.app
的範本。發行版和除錯版應該放在 osx_template.app/Contents/MacOS
裡,名稱分別為 godot_osx_release.64
和 godot_osx_debug.64
。你可以用下面的命令來做(假設是通用建構,否則將 .universal
副檔名替換為你的特定檔案的二進位檔案):
cp -r misc/dist/macos_template.app .
mkdir -p macos_template.app/Contents/MacOS
cp bin/godot.macos.opt.universal macos_template.app/Contents/MacOS/godot_macos_release.64
cp bin/godot.macos.opt.debug.universal macos_template.app/Contents/MacOS/godot_macos_debug.64
chmod +x macos_template.app/Contents/MacOS/godot_macos*
備註
如果您正在建立「master」分支,您還需要包含對 MoltenVK Vulkan 可移植性庫的支援。預設情況下,它將透過您安裝的適用於 macOS 的 Vulkan SDK 進行靜態連結。您也可以選擇透過傳遞“use_volk=yes”並將動態庫包含在“.app”包中來動態連結它:
mkdir -p macos_template.app/Contents/Frameworks
cp <Vulkan SDK path>/macOS/libs/libMoltenVK.dylib macos_template.app/Contents/Frameworks/libMoltenVK.dylib
然後你可以壓縮 osx_template.app
資料夾來複製 Godot 官方發行的 osx.zip
範本:
zip -q -9 -r macos.zip macos_template.app
使用 Clang 與 LLD 來更快速地開發¶
你可以使用 Pyston 來運作 SCons。Pyston 是一種利用了 JIT 的 Python 語言實作(SCons 就是使用 Python 編寫的)。目前它只相容 Linux。Pyston 可以顯著加速差異量建構,經常可以達到 1.5× 和 2× 倍。可以將 Pyston 與 Clang 和 LLD 組合,進行更快的建構。
要安裝 Pyston-lite,請執行“python -m pip install pyston_lite_autoload”,然後照常執行 SCons。這將自動在您執行的任何 Python 程式中載入 Pyston 最佳化的子集。然而,與安裝「完整」Pyston(目前無法在 macOS 上完成)相比,這不會帶來那麼多的效能改進。
在 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=macos
若 OSXCross 的 SDK 版本與 SCons 建置系統所預期不同,則必須通過 osxcross_sdk
參數來指定一個版本:
scons platform=macos osxcross_sdk=darwin15