cross-compiling_for_ios_on_linux.rst 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 it will be easy to
  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)
  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 umounting
  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 building darling-dmg, you'll need the development packages of
  33. the following libraries: fuse, icu, openssl, zlib, bzip2.
  34. - `cctools-port <https://github.com/tpoechtrager/cctools-port>`__
  35. for the needed build tools. The procedure for building is quite
  36. peculiar and is described below.
  37. - This also has some extra dependencies: automake, autogen, libtool.
  38. Configuring the environment
  39. ---------------------------
  40. darling-dmg
  41. ~~~~~~~~~~~
  42. Clone the repository on your machine:
  43. ::
  44. $ git clone https://github.com/darlinghq/darling-dmg.git
  45. Build it:
  46. ::
  47. $ cd darling-dmg
  48. $ mkdir build
  49. $ cd build
  50. $ cmake .. -DCMAKE_BUILD_TYPE=Release
  51. $ make -j 4 # The number is the amount of cores your processor has, for faster build
  52. $ cd ../..
  53. Preparing the SDK
  54. ~~~~~~~~~~~~~~~~~
  55. Mount the XCode image:
  56. ::
  57. $ mkdir xcode
  58. $ ./darling-dmg/build/darling-dmg /path/to/Xcode_7.1.1.dmg xcode
  59. [...]
  60. Everything looks OK, disk mounted
  61. Extract the iOS SDK:
  62. ::
  63. $ mkdir -p iPhoneSDK/iPhoneOS9.1.sdk
  64. $ cp -r xcode/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/* iPhoneSDK/iPhoneOS9.1.sdk
  65. $ cp -r xcode/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/* iPhoneSDK/iPhoneOS9.1.sdk/usr/include/c++
  66. $ fusermount -u xcode # unmount the image
  67. Pack the SDK:
  68. ::
  69. $ cd iPhoneSDK
  70. $ tar -cf - * | xz -9 -c - > iPhoneOS9.1.sdk.tar.xz
  71. Toolchain
  72. ~~~~~~~~~
  73. Build cctools:
  74. ::
  75. $ git clone https://github.com/tpoechtrager/cctools-port.git
  76. $ cd cctools-port/usage_examples/ios_toolchain
  77. $ ./build.sh /path/iPhoneOS9.1.sdk.tar.xz arm64
  78. Copy the tools to a nicer place. Note that the SCons scripts for
  79. building will look under ``usr/bin`` inside the directory you provide
  80. for the toolchain binaries, so you must copy to such subdirectory, akin
  81. to the following commands:
  82. ::
  83. $ mkdir -p /home/user/iostoolchain/usr
  84. $ cp -r target/bin /home/user/iostoolchain/usr/
  85. Now you should have the iOS toolchain binaries in
  86. ``/home/user/iostoolchain/usr/bin``.
  87. Compiling Godot for iPhone
  88. --------------------------
  89. Once you've done the above steps, you should keep two things in your
  90. environment: the built toolchain and the iPhoneOS SDK directory. Those
  91. can stay anywhere you want since you have to provide their paths to the
  92. SCons build command.
  93. For the iPhone platform to be detected, you need the ``OSXCROSS_IOS``
  94. environment variable defined to anything.
  95. ::
  96. $ export OSXCROSS_IOS=anything
  97. Now you can compile for iPhone using SCons like the standard Godot
  98. way, with some additional arguments to provide the correct paths:
  99. ::
  100. $ scons -j 4 platform=iphone arch=arm target=release_debug IPHONESDK="/path/to/iPhoneSDK" IPHONEPATH="/path/to/iostoolchain" ios_triple="arm-apple-darwin11-"
  101. $ scons -j 4 platform=iphone arch=arm64 target=release_debug IPHONESDK="/path/to/iPhoneSDK" IPHONEPATH="/path/to/iostoolchain" ios_triple="arm-apple-darwin11-"
  102. Producing fat binaries
  103. ~~~~~~~~~~~~~~~~~~~~~~
  104. Apple requires a fat binary with both architectures (``armv7`` and
  105. ``arm64``) in a single file. To do this, use the
  106. ``arm-apple-darwin11-lipo`` executable. The following example assumes
  107. you are in the root Godot source directory:
  108. ::
  109. $ /path/to/iostoolchain/usr/bin/arm-apple-darwin11-lipo -create bin/libgodot.iphone.opt.debug.arm.a bin/libgodot.iphone.opt.debug.arm64.a -output bin/libgodot.iphone.debug.fat.a
  110. $ /path/to/iostoolchain/usr/bin/arm-apple-darwin11-lipo -create bin/libgodot_camera_module.iphone.opt.debug.arm.a bin/libgodot_camera_module.iphone.opt.debug.arm64.a -output bin/libgodot_camera_module.iphone.debug.fat.a
  111. $ /path/to/iostoolchain/usr/bin/arm-apple-darwin11-lipo -create bin/libgodot_arkit_module.iphone.opt.debug.arm.a bin/libgodot_arkit_module.iphone.opt.debug.arm64.a -output bin/libgodot_arkit_module.iphone.debug.fat.a
  112. Then you will have iOS fat binaries in ``bin`` directory.