為 iOS 編譯

也參考

本頁說明如何從原始碼編譯 iOS 匯出範本二進位檔。如果你想要將專案匯出到 iOS,請參閱 為 iOS 匯出

系統需求

  • Python 3.8+

  • SCons 4.0+ 建置系統。

  • Xcode
    • 請先啟動一次 Xcode 並安裝 iOS 支援。若已經啟動過 Xcode但需要安裝 iOS 支援,請前往 Xcode -> 設定... -> 平台

    • 前往 Xcode -> 設定... -> 位置 -> 命令列工具 並選擇一個已安裝的版本。即使已經有選擇,請重新選取一次。

  • 下載並依照 README 說明,從 MoltenVK SDK 建置靜態 .xcframework

備註

若已安裝 Homebrew,可以用以下指令輕鬆安裝 SCons:

brew install scons

安裝 Homebrew 時,若尚未安裝 Xcode 命令列工具,會自動下載安裝。

同樣地,若已安裝 MacPorts,可使用以下指令安裝 SCons:

sudo port install scons

也參考

如需取得 Godot 編譯所需的原始碼,請參閱 取得原始碼

關於 Godot 使用 SCons 的基本說明,請參閱 建置系統介紹

編譯

開啟終端機,前往引擎原始碼的根目錄,並輸入下列指令以編譯偵錯版本:

scons platform=ios target=template_debug generate_bundle=yes

要編譯發行版本:

scons platform=ios target=template_release generate_bundle=yes

另外,你也可以執行下列指令,以編譯用於 Xcode 模擬器的函式庫(選用):

scons platform=ios target=template_debug ios_simulator=yes arch=arm64
scons platform=ios target=template_debug ios_simulator=yes arch=x86_64 generate_bundle=yes

這些模擬器函式庫無法用於在目標裝置上執行匯出專案。但你可以用它們直接在 Mac 上執行匯出專案,同時測試 iOS 特定功能。

若要建立如官方版本的 Xcode 專案,必須使用位於 misc/dist/ios_xcode 的樣板。發行版與偵錯版的函式庫應分別放入 libgodot.ios.release.xcframeworklibgodot.ios.debug.xcframework。你可以在*最後*一次用於建置匯出範本的 SCons 指令中加上 generate_bundle=yes 選項,自動完成這個流程(以便包含所有二進位檔)。

MoltenVK 靜態 .xcframework 資料夾建立完成後,也必須放入 ios_xcode 資料夾內。在 iOS 上 MoltenVK 必須是靜態連結,沒有像 macOS 那樣的動態連結選項。

執行

如需在裝置或模擬器執行,請依照這些指示操作:為 iOS 匯出

疑難排解

Fatal error: 'cstdint' file not found

If you get a compilation error of this form early on, it's likely because the Xcode command line tools installation needs to be repaired after a macOS or Xcode update:

./core/typedefs.h:45:10: fatal error: 'cstdint' file not found
45 | #include <cstdint>
   |          ^~~~~~~~~

Run these two commands to reinstall Xcode command line tools (enter your administrator password as needed):

sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install

If it still does not work, try updating Xcode from the Mac App Store and try again.