Difference between revisions of "GDC/Installation/Android"

From D Wiki
Jump to: navigation, search
m
(Update Android info. Lots of things changed :-))
Line 2: Line 2:
  
 
= GDC on Android =
 
= GDC on Android =
Note: This tutorial should give you a usable GDC for Android. GDC on Android is not supported in any way, and especially druntime and phobos may need some updates to be usable.
+
Note: This tutorial should give you a usable GDC for Android. GDC on Android is not supported and especially phobos may need some updates to be usable.
  
 
= Binaries =
 
= Binaries =
http://www.mediafire.com/?2cex2faqx327l
+
Not yet available
  
= Differences to normal GDC =
+
= Building a toolchain with GDC for the Android NDK =
* version(Android) is defined
 
* doesn't link -lpthread and -lrt by default (not available on android)
 
* Note: Android/bionic does not claim to be posix compliant, so there's some work needed to make druntime & phobos work
 
 
 
= Building a toolchain with gdc for the Android NDK =
 
 
== Linux host ==
 
== Linux host ==
The official Android NDK r7 uses an old GCC version (4.4.3) which isn't supported by GDC. We'll build a new toolchain based on GCC 4.6.2
+
Install all packages required for building the NDK. Then:
 
 
=== Needed Packages ===
 
This tutorial was tested on Debian Testing. You'll need at least the following packages:
 
<syntaxhighlight lang="bash">
 
build-essential libncurses5-dev texinfo
 
</syntaxhighlight>
 
 
 
=== Getting the sources ===
 
First we'll need a directory in which we'll put all our files. Just choose any directory and replace all instances of $BASE_DIR in the tutorial with your directory. 
 
<syntaxhighlight lang="bash">
 
BASE_DIR=/home/jpf/android-ndk
 
</syntaxhighlight>
 
  
Now let's download and patch the sources:
 
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
cd $BASE_DIR
+
mkdir workdir
mkdir toolchain-src
+
cd workdir
cd toolchain-src
+
git clone https://android.googlesource.com/platform/ndk
 
+
git clone https://android.googlesource.com/platform/development
git clone https://android.googlesource.com/toolchain/build.git
+
mkdir src
 
+
mkdir dest
mkdir gmp && cd gmp
+
./ndk/build/tools/download-toolchain-sources.sh /home/build/workdir/src
wget ftp://ftp.gmplib.org/pub/gmp-5.0.3/gmp-5.0.3.tar.bz2
+
./ndk/build/tools/gen-platforms.sh --minimal
cd ../
 
 
 
mkdir gdb && cd gdb
 
wget ftp://ftp.gnu.org/gnu/gdb/gdb-7.4.tar.bz2
 
tar xjf gdb-7.4.tar.bz2
 
cd ../
 
 
 
mkdir mpc && cd mpc
 
wget http://www.multiprecision.org/mpc/download/mpc-0.9.tar.gz
 
cd ../
 
 
 
mkdir mpfr && cd mpfr
 
wget http://www.mpfr.org/mpfr-3.0.1/mpfr-3.0.1.tar.bz2
 
cd ../
 
  
mkdir binutils
+
git clone git@github.com:D-Programming-GDC/GDC.git
cd binutils/
+
cd GDC
wget http://sourceware.mirrors.tds.net/pub/sourceware.org/binutils/snapshots/binutils-2.22.51.tar.bz2
+
git checkout gdc-4.9
tar xjf binutils-2.22.51.tar.bz2
+
./setup-gcc.sh /home/build/workdir/src/gcc/gcc-4.9
 
cd ../
 
cd ../
  
wget http://gcc.gnu.org/bugzilla/attachment.cgi?id=24879 -O gcc-android.patch
+
./ndk/build/tools/build-gcc.sh /home/build/workdir/src /home/build/workdir/dest arm-linux-androideabi-4.9 --verbose --try-64
mkdir gcc
 
cd gcc/
 
wget ftp://ftp.gnu.org//gnu/gcc/gcc-4.6.2/gcc-4.6.2.tar.bz2
 
tar xjf gcc-4.6.2.tar.bz2
 
cd gcc-4.6.2
 
patch -p1 -i ../../gcc-android.patch
 
cd ../../
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
We'll now patch GCC to add support for D. Note: Skip this code snippet to simply build a GCC 4.6.2 toolchain without D. It's recommended to get a toolchain without D working first.
+
=== Building unittests ===
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
hg clone https://bitbucket.org/jpf/gdc
+
cd /tmp/ndk-/build/toolchain/gcc-4.9/arm-linux-androideabi/libphobos/libdruntime
cd gdc
+
make unittest
hg update android
+
cd /tmp/ndk-/build/toolchain/gcc-4.9/arm-linux-androideabi/libphobos/src
cd ../
+
make unittest
 
 
cd gcc/gcc-4.6.2/
 
ln -s ../../../gdc/d gcc/d
 
./gcc/d/setup-gcc.sh
 
cd ../../
 
 
 
wget https://raw.github.com/gist/1737240/08b7eaf3db7de800107c50ca84f379d587171818/gistfile1.diff -O build-d.patch
 
cd build
 
patch -p1 -i ../build-d.patch
 
cd ../
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== Getting the android NDK ===
+
=== Debugging help ===
Now you'll have to download the official Android NDK r7 and extract it to BASE_DIR
 
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
cd $BASE_DIR
+
adb push unittest /data/local/tmp
wget http://dl.google.com/android/ndk/android-ndk-r7-linux-x86.tar.bz2
+
# gdbserver is in standard NDK builds
tar xjf android-ndk-r7-linux-x86.tar.bz2
+
adb push prebuilt/android-arm/gdbserver/gdbserver /data/local/tmp
</syntaxhighlight>
+
adb forward tcp:5039 tcp:5039
  
We'll have to apply a small patch as well:
+
adb shell
<syntaxhighlight lang="bash">
+
su
wget https://raw.github.com/gist/1737276/4af76432e838d7356d068568009f6adc3829cc01/gistfile1.diff -O build-mpc.patch
+
cd /data/local/tmp
cd android-ndk-r7
+
./unittest
patch -p1 -i ../build-mpc.patch
+
./gdbserver :5039 unittest
cd ../
 
</syntaxhighlight>
 
  
Note: Your BASE_DIR directory should now look like this:
+
./toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gdb unittest
 +
<gdb> target extended-remote :5039
 +
<gdb> continue
  
|-toolchain-src
+
# Usually android devices dont have hardware watchpoints, to disable:
|---gdb
+
<gdb> set can-use-hw-watchpoints 0
|-----gdb-7.4
 
|---mpfr
 
|---gcc
 
|-----gcc-4.6.2
 
|---binutils
 
|-----binutils-2.22.51
 
|---gdc
 
|---gmp
 
|---build
 
|---mpc
 
|-android-ndk-r7
 
 
 
 
 
=== Build the toolchain ===
 
<syntaxhighlight lang="bash">
 
cd android-ndk-r7/build/tools/
 
NUM_JOBS=1 DFLAGS="-fno-section-anchors" ./build-gcc.sh --gmp-version=5.0.3 --mpfr-version=3.0.1 --mpc-version=0.9 --binutils-version=2.22.51 --gdb-version=7.4 $BASE_DIR/toolchain-src $BASE_DIR/android-ndk-r7 arm-linux-androideabi-4.6.2
 
</syntaxhighlight>
 
 
 
Once the build is finished, your toolchain is in BASE_DIR/android-ndk-r7/toolchains/arm-linux-androideabi-4.6.2/prebuilt/linux-x86
 
 
 
== Windows host ==
 
We'll compile the windows toolchain on a linux host. Debian Testing was used to test this tutorial.
 
 
 
=== Follow the linux build instructions ===
 
Follow the linux instructions till the "Build the toolchain" section.
 
 
 
=== Additional packages ===
 
We'll need the following additional packages for the windows build:
 
<syntaxhighlight lang="bash">
 
gcc-mingw32 mingw32-binutils mingw32-runtime
 
 
</syntaxhighlight>
 
</syntaxhighlight>
 
=== Additional patches ===
 
We'll also need one additional patch:
 
 
<syntaxhighlight lang="bash">
 
cd $BASE_DIR/toolchain-src
 
wget https://gist.github.com/raw/1752754/9d9c28a04a8c68192b5578a296fb2191954a545f/gistfile1.diff -O build-mingw.patch
 
cd build
 
patch -p3 -i ../build-mingw.patch
 
cd ../
 
</syntaxhighlight>
 
 
Depending on your build system, you'll have to apply another patch: if you have a **i386-linux-gnu-gcc** executable,  you must not apply this patch. But if your gcc is called '''i486-linux-gnu-gcc''' you must apply it.
 
<syntaxhighlight lang="bash">
 
cd $BASE_DIR
 
wget https://gist.github.com/raw/1752778/64e05067505211842a4bcb6dc574c799ac273b74/gistfile1.diff -O build-i486-host.patch
 
cd android-ndk-r7
 
patch -p2 -i ../build-i486-host.patch
 
cd ../
 
</syntaxhighlight>
 
 
=== Build the toolchain ===
 
<syntaxhighlight lang="bash">
 
cd android-ndk-r7/build/tools/
 
NUM_JOBS=1 DFLAGS="-fno-section-anchors" ./build-gcc.sh --gmp-version=5.0.3 --mpfr-version=3.0.1 --mpc-version=0.9 --binutils-version=2.22.51 --gdb-version=7.4 --mingw $BASE_DIR/toolchain-src $BASE_DIR/android-ndk-r7 arm-linux-androideabi-4.6.2
 
</syntaxhighlight>
 
 
Once the build is finished, your toolchain is in BASE_DIR/android-ndk-r7/toolchains/arm-linux-androideabi-4.6.2/prebuilt/windows
 
 
BTW: This build system can now be used to build both windows & linux binaries. Just add or remove --mingw from the ./build-gcc.sh command.
 
  
 
= TODO =
 
= TODO =
* Compiler
 
** Fix #120
 
** Run unittests
 
* druntime
 
** Uses ~__get_stack_base instead of ~__libc_stack_end. It should be tested to verify it is working correctly
 
** Building gcc/config/unix.d fails, so the patch simply skips that file. This should be investigated further and fixed correctly.
 
*** druntime depends on some functions which are not in bionic. It builds, but user apps don't link.
 
 
* phobos
 
* phobos
** disabled for now
+
* shared libraries

Revision as of 23:38, 28 March 2015


GDC on Android

Note: This tutorial should give you a usable GDC for Android. GDC on Android is not supported and especially phobos may need some updates to be usable.

Binaries

Not yet available

Building a toolchain with GDC for the Android NDK

Linux host

Install all packages required for building the NDK. Then:

mkdir workdir
cd workdir
git clone https://android.googlesource.com/platform/ndk
git clone https://android.googlesource.com/platform/development
mkdir src
mkdir dest
./ndk/build/tools/download-toolchain-sources.sh /home/build/workdir/src
./ndk/build/tools/gen-platforms.sh --minimal

git clone git@github.com:D-Programming-GDC/GDC.git
cd GDC
git checkout gdc-4.9
./setup-gcc.sh /home/build/workdir/src/gcc/gcc-4.9
cd ../

./ndk/build/tools/build-gcc.sh /home/build/workdir/src /home/build/workdir/dest arm-linux-androideabi-4.9 --verbose --try-64

Building unittests

cd /tmp/ndk-/build/toolchain/gcc-4.9/arm-linux-androideabi/libphobos/libdruntime
make unittest
cd /tmp/ndk-/build/toolchain/gcc-4.9/arm-linux-androideabi/libphobos/src
make unittest

Debugging help

adb push unittest /data/local/tmp
# gdbserver is in standard NDK builds
adb push prebuilt/android-arm/gdbserver/gdbserver /data/local/tmp 
adb forward tcp:5039 tcp:5039

adb shell
su
cd /data/local/tmp
./unittest
./gdbserver :5039 unittest

./toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gdb unittest
<gdb> target extended-remote :5039
<gdb> continue

# Usually android devices dont have hardware watchpoints, to disable:
<gdb> set can-use-hw-watchpoints 0

TODO

  • phobos
  • shared libraries