cross-compiling_for_ios_on_linux.rst 5.0 KB

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