Apple’s release of the iPhone 5S and iPad Mini Retina marked the start of the iOS 64-bit era; the Apple A7 is a 64-bit ARM processor. While the new processor architecture was certainly welcome, it meant that the jailbreaking community would have to do a little bit of work.
Many developers in the jailbreaking community do not use Mac OS X. (I’ll try not to start a flame war here :P) Whether due to preference or monetary constraints (or in my case, a web application that involves compiling), they develop for iOS using Linux or other platforms. Unfortunately, building on other platforms depends on Apple releasing the source code of many toolchain components, including Clang, LLVM, and ld64. So far, Apple has failed to release any source code to the public. Apple has said that releasing the LLVM backend for ARM64 “…will take at least several months to work out all the details.” At the time of this post, that was half a year ago, so it appears they’re too busy making high-tech jewelry and beginner-level SSL bugs to support our community.
Luckily, I stumbled upon the Darling project. I recently found myself needing to compile tweaks on my Ubuntu 12.04 LTS server, and after the trouble I went through to set it up, I thought I would write a tutorial for others to follow. I will cover installing Darling, its dependencies, and setting up theos to work with the makeshift toolchain.
Keep in mind, these are the steps I, myself had to take for setting it up on an x86_64 Ubuntu 12.04 server, so you may have take some different steps in order to set it up on your system. So, let’s get started.
Dependencies
Darling has quite a few dependencies. We’re going to need to download and build quite a few of them, so prepare yourself for a good amount of building.
First, install a few of the various development tools we’re going to need:
$ sudo apt-get install build-essential git subversion clang3.3 nasm cmake pkg-config
Now, we’re going to need a few more libraries for installation:
$ sudo apt-get install libudev-dev libkqueue-dev libltdl-dev libgl1-mesa-dev
libbsd
Darling requires libbsd of version 0.4.2 or higher. As Ubuntu Precise’s repository only has version 0.3.0, I had to download and build libbsd manually. If you’re on Ubuntu 12.10 or higher, you can skip this step and just install libbsd-dev via APT.
$ wget http://libbsd.freedesktop.org/releases/libbsd-0.4.2.tar.gz
$ tar xvf libbsd-0.4.2.tar.gz
$ cd libbsd-0.4.2
$ ./configure
$ make
$ sudo make install
$ cd ..
GNUstep
Darling depends on quite a few GNUstep libraries. The installation of these can be found on the Darling website here, but I’ll post what I did anyway. (Note: For whatever reason, libobjc2’s headers were installed to /usr/local/include/GNUstep. That’s why I change some of the include paths.)
$ sudo apt-get install libxml2-dev libgnutls-dev libicu-dev libcairo-dev \
libjpeg-dev libpng-dev libtiff-dev libbsd-dev libudev-dev \
liblcms-dev libkqueue-dev libssl-dev libbz2-dev uuid-dev \
libncurses-dev libxrandr-dev libavcodec-dev libavformat-dev
gnustep-make
$ svn co http://svn.gna.org/svn/gnustep/tools/make/trunk/ gnustep-make
$ cd gnustep-make
$ CC=clang CXX=clang++ ./configure
$ sudo make install
$ cd ..
libobjc2
$ svn co http://svn.gna.org/svn/gnustep/libs/libobjc2/trunk/ gnustep-libobjc2
$ cd gnustep-libobjc2
$ OBJCFLAGS=-fblocks CC=clang CXX=clang++ cmake .
$ rm GNUmakefile
$ make
$ sudo make install
$ cd ..
gnustep-base
$ svn co http://svn.gna.org/svn/gnustep/libs/base/trunk/ gnustep-base
$ cd gnustep-base
$ OBJCFLAGS=-fblocks CC=clang CXX=clang++ CPPFLAGS=-I/usr/local/include/GNUstep ./configure
$ make
$ sudo make install
$ cd ..
gnustep-gui
$ svn co http://svn.gna.org/svn/gnustep/libs/gui/trunk/ gnustep-gui
$ cd gnustep-gui
$ OBJCFLAGS=-fblocks CC=clang CXX=clang++ CPPFLAGS=-I/usr/local/include/GNUstep ./configure
$ make LD_LIBRARY_PATH=’/usr/local/lib’
$ sudo make install
$ cd ..
gnustep-corebase
$ svn co http://svn.gna.org/svn/gnustep/libs/corebase/trunk/ gnustep-corebase
$ cd gnustep-corebase
$ OBJCFLAGS=-fblocks CC=clang CXX=clang++ ./configure
$ make
$ sudo make install
$ cd ..
Darling
First, clone the Darling repository:
$ git clone https://github.com/LubosD/darling.git
Now, we can move onto building Darling.
$ cd darling
$ CC=clang CXX=clang++ cmake .
$ make
If everything went well, you should see no errors. You can then proceed to install Darling.
$ sudo make install
$ cd ..
Make sure it works by running
$ dyld
If you see something along the lines of ‘This is Darling dyld for…‘, Darling has been successfully installed. If you’ve made it this far, sit back and relax, because the hard part is over.
I had one small error while building Darling. CMake was searching for libobjc2’s headers in the wrong directory. To solve this, I opened cmake_modules/FindLibobjc2.cmake with a text editor and changed /usr/include/GNUstep to /usr/local/include/GNUstep.
Theos
Next, we need to setup theos. I’ve modified theos to work with Darling and Apple’s toolchain. Clone my fork like so:
$ git clone https://github.com/eswick/theos-darling.git /opt/theos
You’re going to need two more things; Apple’s toolchain and the iOS SDK.
Toolchain
Libraries, libraries, libraries…
Clang/LLVM depends on libc++, so we’re going to need to download, build, and install it. Download the source code like so:
$ mkdir libcxx_build
$ cd libcxx_build
$ svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx
Next, you’ll need to find out where your libstdc++ headers are located.
$ echo | g++ -Wp,-v -x c++ - -fsyntax-only
Then, run CMake with the correct header path, and build as normal.
$ CC=clang CXX=clang++ cmake -G "Unix Makefiles" -DLIBCXX_CXX_ABI=libstdc++ -DLIBCXX_LIBSUPCXX_INCLUDE_PATHS="/usr/include/c++/4.6/;/usr/include/c++/4.6/x86_64-linux-gnu/" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr libcxx
$ make
$ sudo make install
Once you have libc++ installed, you should be ready to install Apple’s toolchain. You’ll need to place XcodeDefault.xctoolchain from Xcode.app/Contents/Developer/Toolchains (on your Mac) in $THEOS/toolchain.
SDK
$THEOS/sdk needs to point to (or be) the root of the iOS SDK. For example, I placed the SDK at /var/sdks/iPhoneOS7.0.sdk and ran $ ln -s /var/sdks/iPhoneOS7.0.sdk /opt/theos/sdk.
Profit
If you’ve made it this far, congratulations! At this point, you should be able to build theos projects like normal, with ARM64 support.
Huge thanks to the Darling team for making this possible!