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