godot-docs/reference/cross-compiling_for_ios_on_...

160 lines
5.0 KiB
ReStructuredText
Raw Normal View History

2016-02-08 23:45:57 +01:00
.. _doc_cross-compiling_for_ios_on_linux:
2015-12-12 17:57:44 +01:00
Cross-compiling for iOS on Linux
================================
.. highlight:: shell
2015-12-12 17:57:44 +01:00
The procedure for this is somewhat complex and requires a lot of steps,
but once you have the environment properly configured it will be easy to
compile Godot for iOS anytime you want.
Disclaimer
----------
While it is possible to compile for iOS on a Linux environment, Apple is
very restrictive about the tools to be used (specially hardware-wise),
allowing pretty much only their products to be used for development. So
2016-02-11 22:03:01 +01:00
this is **not official**. However, a `statement from Apple in 2010
<http://www.apple.com/pr/library/2010/09/09Statement-by-Apple-on-App-Store-Review-Guidelines.html>`__
says they relaxed some of the `App Store review guidelines
<https://developer.apple.com/app-store/review/guidelines/>`__
to allow any tool to be used, as long as the resulting binary does not
2015-12-12 17:57:44 +01:00
download any code, which means it should be OK to use the procedure
described here and cross-compiling the binary.
Requirements
------------
2016-02-11 22:03:01 +01:00
- `XCode with the iOS SDK <https://developer.apple.com/xcode/download>`__
(a dmg image)
- `Clang >= 3.5 <http://clang.llvm.org>`__ for your development
machine installed and in the ``PATH``. It has to be version >= 3.5
2016-02-06 01:54:33 +01:00
to target ``arm64`` architecture.
2016-02-11 22:03:01 +01:00
- `Fuse <http://fuse.sourceforge.net>`__ for mounting and umounting
2016-02-06 01:54:33 +01:00
the dmg image.
2016-02-11 22:03:01 +01:00
- `darling-dmg <https://github.com/darlinghq/darling-dmg>`__, which
2016-02-06 01:54:33 +01:00
needs to be built from source. The procedure for that is explained
below.
2015-12-12 17:57:44 +01:00
- For building darling-dmg, you'll need the development packages of
2016-02-11 22:03:01 +01:00
the following libraries: fuse, icu, openssl, zlib, bzip2.
2015-12-12 17:57:44 +01:00
2016-02-11 22:03:01 +01:00
- `cctools-port <https://github.com/tpoechtrager/cctools-port>`__
2015-12-12 17:57:44 +01:00
for the needed build tools. The procedure for building is quite
peculiar and is described below.
2016-02-11 22:03:01 +01:00
- This also has some extra dependencies: automake, autogen, libtool.
2015-12-12 17:57:44 +01:00
Configuring the environment
---------------------------
darling-dmg
~~~~~~~~~~~
2016-02-11 22:03:01 +01:00
Clone the repository on your machine:
2015-12-12 17:57:44 +01:00
::
2016-02-11 22:03:01 +01:00
$ git clone https://github.com/darlinghq/darling-dmg.git
2015-12-12 17:57:44 +01:00
2016-02-11 22:03:01 +01:00
Build it:
2015-12-12 17:57:44 +01:00
::
$ cd darling-dmg
$ mkdir build
$ cd build
2016-02-11 22:03:01 +01:00
$ cmake .. -DCMAKE_BUILD_TYPE=Release
$ make -j 4 # The number is the amount of cores your processor has, for faster build
2015-12-12 17:57:44 +01:00
$ cd ../..
Preparing the SDK
~~~~~~~~~~~~~~~~~
2016-02-11 22:03:01 +01:00
Mount the XCode image:
2015-12-12 17:57:44 +01:00
::
$ mkdir xcode
$ ./darling-dmg/build/darling-dmg /path/to/Xcode_7.1.1.dmg xcode
2016-02-11 22:03:01 +01:00
[...]
2015-12-12 17:57:44 +01:00
Everything looks OK, disk mounted
2016-02-11 22:03:01 +01:00
Extract the iOS SDK:
2015-12-12 17:57:44 +01:00
::
$ mkdir -p iPhoneSDK/iPhoneOS9.1.sdk
$ cp -r xcode/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/* iPhoneSDK/iPhoneOS9.1.sdk
$ cp -r xcode/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/* iPhoneSDK/iPhoneOS9.1.sdk/usr/include/c++
2016-02-11 22:03:01 +01:00
$ fusermount -u xcode # unmount the image
2015-12-12 17:57:44 +01:00
2016-02-11 22:03:01 +01:00
Pack the SDK:
2015-12-12 17:57:44 +01:00
::
$ cd iPhoneSDK
$ tar -cf - * | xz -9 -c - > iPhoneOS9.1.sdk.tar.xz
Toolchain
~~~~~~~~~
2016-02-11 22:03:01 +01:00
Build cctools:
2015-12-12 17:57:44 +01:00
::
$ git clone https://github.com/tpoechtrager/cctools-port.git
$ cd cctools-port/usage_examples/ios_toolchain
$ ./build.sh /path/iPhoneOS9.1.sdk.tar.xz arm64
2016-02-11 22:03:01 +01:00
Copy the tools to a nicer place. Note that the SCons scripts for
2015-12-12 17:57:44 +01:00
building will look under ``usr/bin`` inside the directory you provide
for the toolchain binaries, so you must copy to such subdirectory, akin
to the following commands:
::
$ mkdir -p /home/user/iostoolchain/usr
$ cp -r target/bin /home/user/iostoolchain/usr/
Now you should have the iOS toolchain binaries in
``/home/user/iostoolchain/usr/bin``.
Compiling Godot for iPhone
--------------------------
Once you've done the above steps, you should keep two things in your
environment: the built toolchain and the iPhoneOS SDK directory. Those
can stay anywhere you want since you have to provide their paths to the
SCons build command.
2016-02-11 22:03:01 +01:00
For the iPhone platform to be detected, you need the ``OSXCROSS_IOS``
2015-12-12 17:57:44 +01:00
environment variable defined to anything.
::
$ export OSXCROSS_IOS=anything
2016-02-11 22:03:01 +01:00
Now you can compile for iPhone using SCons like the standard Godot
2015-12-12 17:57:44 +01:00
way, with some additional arguments to provide the correct paths:
::
2016-07-13 16:53:13 +02:00
$ scons -j 4 platform=iphone arch=arm target=release_debug IPHONESDK="/path/to/iPhoneSDK" IPHONEPATH="/path/to/iostoolchain" ios_triple="arm-apple-darwin11-"
$ scons -j 4 platform=iphone arch=arm64 target=release_debug IPHONESDK="/path/to/iPhoneSDK" IPHONEPATH="/path/to/iostoolchain" ios_triple="arm-apple-darwin11-"
2015-12-12 17:57:44 +01:00
Producing fat binaries
~~~~~~~~~~~~~~~~~~~~~~
2016-02-24 08:09:26 +01:00
Apple requires a fat binary with both architectures (``armv7`` and
2015-12-12 17:57:44 +01:00
``arm64``) in a single file. To do this, use the
``arm-apple-darwin11-lipo`` executable. The following example assumes
you are in the root Godot source directory:
::
2016-07-13 16:53:13 +02:00
$ /path/to/iostoolchain/usr/bin/arm-apple-darwin11-lipo -create bin/godot.iphone.opt.debug.arm bin/godot.iphone.opt.debug.arm64 -output bin/godot.iphone.opt.debug.fat
2015-12-12 17:57:44 +01:00
2016-02-11 22:03:01 +01:00
Then you will have an iOS fat binary in ``bin/godot.iphone.opt.debug.fat``.