Build LDC for Android
This page will show you how to build a ldc cross-compiler for Android/ARM on linux, along with how to build and run both the druntime/phobos tests and an Android D app using the cross-compiler.
Almost all the druntime/phobos unit tests pass on Android/ARM. One of the native OpenGL sample apps from the Android NDK has been ported to D, I'll port some more soon. Remaining work to be done is listed last.
You can also try out dmd for Android/x86.
- linux host, where you'll build ldc
- You can use a virtual machine like VirtualBox/VMware, with at least 512 MB of memory and 1 GB of swap, particularly if building the phobos unit tests, and 10 GB of disk space.
- C++ compiler and toolchain, to build ldc
- Common development tools, such as CMake and git, and ldc uses libconfig++
- ldc/druntime/phobos source
- Get the source using git, as these Android patches have only been tested on the master branch of each repo.
- llvm 3.6 source, either from the official release or git
- llvm 3.7 or later will work too, but you'll have to update the small llvm patch so it still applies.
- Android native toolchain, the NDK and optionally the SDK
- The SDK is only necessary if you want to package a GUI app; the NDK is enough if you just want to build a command-line binary, such as a test runner. The "SDK Tools only" version of the SDK is all that's necessary, if you don't plan on using their IDE integration. I will only write about using the command-line tools. The SDK requires JDK 7: follow their instructions to make sure it's installed right.
- Android/ARM, whether a device or emulator
- The SDK comes with an emulator. I've only used actual hardware, so that's what I'll discuss.
Get the source for llvm, either the last official 3.6.2 release or a git repository like the official Android llvm, which has some modifications but shouldn't really change much. Download the patch for llvm, apply it, and then build llvm normally with the ARM target:
tar xvf llvm-3.6.2.src.tar.xz cd llvm-3.6.2.src curl -O https://gist.githubusercontent.com/joakim-noah/1fb23fba1ba5b7e87e1a/raw/4bc1439defd2bd962710e8710d3ac26d342f0b87/android_tls git apply android_tls mkdir build cd build cmake .. -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=ARM make -j5
Build ldc for Android/ARM
cd ../.. git clone --recursive https://github.com/ldc-developers/ldc.git cd ldc git checkout -b android c769251cc git submodule update curl -O https://gist.githubusercontent.com/joakim-noah/63693ead3aa62216e1d9/raw/0c5e1e976c9c1781dc898a5fe1509f690b0b4324/ldc_android_arm git apply ldc_android_arm mkdir build cd build export NDK=/path/to/your/android-ndk-r10e cmake .. -DLLVM_CONFIG=../../llvm-3.6.2.src/build/bin/llvm-config make ldc2 -j5
cd ../runtime/druntime curl -O https://gist.githubusercontent.com/joakim-noah/d936d6a339426ad1fac3/raw/ef212405065767e05c69dc6b67990ff56faf6a87/druntime_ldc_arm git apply druntime_ldc_arm cd ../phobos curl -O https://gist.githubusercontent.com/joakim-noah/5c03801fa6c59b1e90df/raw/27b8bd0b6f43e805df59c56e3c4b6acf8e95541e/phobos_ldc_arm git apply phobos_ldc_arm cd ../../build make druntime-ldc phobos2-ldc -j5
Build a command-line executable
Let's try building a classic benchmark.