cross-compiling_for_ios_on_linux.rst 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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, a `statement from Apple in 2010
  14. <http://www.apple.com/pr/library/2010/09/09Statement-by-Apple-on-App-Store-Review-Guidelines.html>`__
  15. says they relaxed some of the `App Store review guidelines
  16. <https://developer.apple.com/app-store/review/guidelines/>`__
  17. to allow any tool to be used, as long as the resulting binary does not
  18. download any code, which means it should be OK to use the procedure
  19. described here and cross-compiling the binary.
  20. Requirements
  21. ------------
  22. - `XCode with the iOS SDK <https://developer.apple.com/xcode/download>`__
  23. (a dmg image, for newer versions a **xip** file is going to be downloaded.)
  24. - `Clang >= 3.5 <http://clang.llvm.org>`__ for your development
  25. machine installed and in the ``PATH``. It has to be version >= 3.5
  26. to target ``arm64`` architecture.
  27. - `Fuse <https://github.com/libfuse/libfuse>`__ for mounting and unmounting
  28. the dmg image.
  29. - `darling-dmg <https://github.com/darlinghq/darling-dmg>`__, which
  30. needs to be built from source. The procedure for that is explained
  31. below.
  32. - For newer versions you should download `xar <https://mackyle.github.io/xar/>`__
  33. and `pbzx <https://github.com/NiklasRosenstein/pbzx>`__.
  34. - For building darling-dmg, you'll need the development packages of
  35. the following libraries: fuse, icu, openssl, zlib, bzip2.
  36. - For building xar and pbzx you may want to follow
  37. `this guide <https://gist.github.com/phracker/1944ce190e01963c550566b749bd2b54>`__.
  38. - `cctools-port <https://github.com/tpoechtrager/cctools-port>`__
  39. for the needed build tools. The procedure for building is quite
  40. peculiar and is described below.
  41. - This also has some extra dependencies: automake, autogen, libtool.
  42. Configuring the environment
  43. ---------------------------
  44. darling-dmg
  45. ~~~~~~~~~~~
  46. Clone the repository on your machine:
  47. ::
  48. $ git clone https://github.com/darlinghq/darling-dmg.git
  49. Build it:
  50. ::
  51. $ cd darling-dmg
  52. $ mkdir build
  53. $ cd build
  54. $ cmake .. -DCMAKE_BUILD_TYPE=Release
  55. $ make -j 4 # The number is the amount of cores your processor has, for faster build
  56. $ cd ../..
  57. Preparing the SDK
  58. ~~~~~~~~~~~~~~~~~
  59. Mount the XCode image:
  60. ::
  61. $ mkdir xcode
  62. $ ./darling-dmg/build/darling-dmg /path/to/Xcode_7.1.1.dmg xcode
  63. [...]
  64. Everything looks OK, disk mounted
  65. For newer versions you should extract the **xip** file:
  66. ::
  67. $ mkdir xcode
  68. $ xar -xf /path/to/Xcode_X.x.xip -C xcode
  69. $ pbzx -n Content | cpio -i
  70. [...]
  71. ######### Blocks
  72. Note that for the commands below, you may need to replace the version (`X.x`) with whatever iOS SDK version you're using.
  73. Extract the iOS SDK:
  74. ::
  75. $ # If you don't know your iPhone SDK version you can see the json file inside of Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs
  76. $ mkdir -p iPhoneSDK/iPhoneOSX.x.sdk
  77. $ cp -r xcode/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/* iPhoneSDK/iPhoneOSX.x.sdk
  78. $ cp -r xcode/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/* iPhoneSDK/iPhoneOSX.x.sdk/usr/include/c++
  79. $ fusermount -u xcode # unmount the image
  80. Pack the SDK:
  81. ::
  82. $ cd iPhoneSDK
  83. $ tar -cf - * | xz -9 -c - > iPhoneOSX.x.sdk.tar.xz
  84. Toolchain
  85. ~~~~~~~~~
  86. Build cctools:
  87. ::
  88. $ git clone https://github.com/tpoechtrager/cctools-port.git
  89. $ cd cctools-port/usage_examples/ios_toolchain
  90. $ ./build.sh /path/iPhoneOSX.x.sdk.tar.xz arm64
  91. Copy the tools to a nicer place. Note that the SCons scripts for
  92. building will look under ``usr/bin`` inside the directory you provide
  93. for the toolchain binaries, so you must copy to such subdirectory, akin
  94. to the following commands:
  95. ::
  96. $ mkdir -p /home/user/iostoolchain/usr
  97. $ cp -r target/bin /home/user/iostoolchain/usr/
  98. Now you should have the iOS toolchain binaries in
  99. ``/home/user/iostoolchain/usr/bin``.
  100. Compiling Godot for iPhone
  101. --------------------------
  102. Once you've done the above steps, you should keep two things in your
  103. environment: the built toolchain and the iPhoneOS SDK directory. Those
  104. can stay anywhere you want since you have to provide their paths to the
  105. SCons build command.
  106. For the iPhone platform to be detected, you need the ``OSXCROSS_IOS``
  107. environment variable defined to anything.
  108. ::
  109. $ export OSXCROSS_IOS=anything
  110. Now you can compile for iPhone using SCons like the standard Godot
  111. way, with some additional arguments to provide the correct paths:
  112. ::
  113. $ scons -j 4 platform=ios arch=arm64 target=template_release IOS_SDK_PATH="/path/to/iPhoneSDK" IOS_TOOLCHAIN_PATH="/path/to/iostoolchain" ios_triple="arm-apple-darwin11-"