cross-compiling_for_ios_on_linux.rst 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. .. _doc_cross-compiling_for_ios_on_linux:
  2. Cross-compiling for iOS on Linux
  3. ================================
  4. .. highlight:: shell
  5. The procedure for this is somewhat complex and requires a lot of steps,
  6. but once you have the environment properly configured you can
  7. compile Godot for iOS anytime you want.
  8. Disclaimer
  9. ----------
  10. While it is possible to compile for iOS on a Linux environment, Apple is
  11. very restrictive about the tools to be used (especially hardware-wise),
  12. allowing pretty much only their products to be used for development. So
  13. this is **not official**. However, in 2010 Apple said they relaxed some of the
  14. `App Store review guidelines <https://developer.apple.com/app-store/review/guidelines/>`__
  15. to allow any tool to be used, as long as the resulting binary does not
  16. download any code, which means it should be OK to use the procedure
  17. described here and cross-compiling the binary.
  18. Requirements
  19. ------------
  20. - `XCode with the iOS SDK <https://developer.apple.com/download/all/?q=Xcode>`__
  21. (you must be logged into an Apple ID to download Xcode).
  22. - `Clang >= 3.5 <https://clang.llvm.org>`__ for your development
  23. machine installed and in the ``PATH``. It has to be version >= 3.5
  24. to target ``arm64`` architecture.
  25. - `xar <https://mackyle.github.io/xar/>`__ and `pbzx <https://github.com/NiklasRosenstein/pbzx>`__
  26. (required to extract the ``.xip`` archive Xcode comes in).
  27. - For building xar and pbzx, you may want to follow
  28. `this guide <https://gist.github.com/phracker/1944ce190e01963c550566b749bd2b54>`__.
  29. - `cctools-port <https://github.com/tpoechtrager/cctools-port>`__
  30. for the needed build tools. The procedure for building is quite
  31. peculiar and is described below.
  32. - This also has some extra dependencies: automake, autogen, libtool.
  33. Configuring the environment
  34. ---------------------------
  35. Preparing the SDK
  36. ~~~~~~~~~~~~~~~~~
  37. Extract the Xcode ``.xip`` file you downloaded from Apple's developer website:
  38. ::
  39. mkdir xcode
  40. xar -xf /path/to/Xcode_X.x.xip -C xcode
  41. pbzx -n Content | cpio -i
  42. [...]
  43. ######### Blocks
  44. Note that for the commands below, you will need to replace the version (``x.x``)
  45. with whatever iOS SDK version you're using. If you don't know your iPhone SDK
  46. version, you can see the JSON file inside of
  47. ``Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs``.
  48. Extract the iOS SDK:
  49. ::
  50. export IOS_SDK_VERSION="x.x"
  51. mkdir -p iPhoneSDK/iPhoneOS${IOS_SDK_VERSION}.sdk
  52. cp -r xcode/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/* iPhoneSDK/iPhoneOS${IOS_SDK_VERSION}.sdk
  53. cp -r xcode/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/* iPhoneSDK/iPhoneOS${IOS_SDK_VERSION}.sdk/usr/include/c++
  54. fusermount -u xcode
  55. Pack the SDK so that cctools can use it:
  56. ::
  57. cd iPhoneSDK
  58. tar -cf - * | xz -9 -c - > iPhoneOS${IOS_SDK_VERSION}.sdk.tar.xz
  59. Toolchain
  60. ~~~~~~~~~
  61. Build cctools:
  62. ::
  63. git clone https://github.com/tpoechtrager/cctools-port.git
  64. cd cctools-port/usage_examples/ios_toolchain
  65. ./build.sh /path/iPhoneOS${IOS_SDK_VERSION}.sdk.tar.xz arm64
  66. Copy the tools to a nicer place. Note that the SCons scripts for
  67. building will look under ``usr/bin`` inside the directory you provide
  68. for the toolchain binaries, so you must copy to such subdirectory, akin
  69. to the following commands:
  70. ::
  71. mkdir -p "$HOME/iostoolchain/usr"
  72. cp -r target/bin "$HOME/iostoolchain/usr/"
  73. Now you should have the iOS toolchain binaries in
  74. ``$HOME/iostoolchain/usr/bin``.
  75. Compiling Godot for iPhone
  76. --------------------------
  77. Once you've done the above steps, you should keep two things in your
  78. environment: the built toolchain and the iPhoneOS SDK directory. Those
  79. can stay anywhere you want since you have to provide their paths to the
  80. SCons build command.
  81. For the iPhone platform to be detected, you need the ``OSXCROSS_IOS``
  82. environment variable defined to anything.
  83. ::
  84. export OSXCROSS_IOS="anything"
  85. Now you can compile for iPhone using SCons like the standard Godot
  86. way, with some additional arguments to provide the correct paths:
  87. ::
  88. scons platform=ios arch=arm64 target=template_release IOS_SDK_PATH="/path/to/iPhoneSDK" IOS_TOOLCHAIN_PATH="/path/to/iostoolchain" ios_triple="arm-apple-darwin11-"