Difference between revisions of "LDC cross-compilation for ARM GNU/Linux"

From D Wiki
Jump to: navigation, search
(Link to ldc-build-runtime page instead)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
 +
<span style="color:red">'''This page is outdated and we are working on much better cross-compilation support, [[Building LDC runtime libraries|try the new runtime cross-compilation tool instead]].'''</span>
 +
 +
 
This page will show you how to build a ldc cross-compiler for ARM architecture on GNU/Linux, so that you can build an executable binary with the druntime/phobos and run it on your ARM target.
 
This page will show you how to build a ldc cross-compiler for ARM architecture on GNU/Linux, so that you can build an executable binary with the druntime/phobos and run it on your ARM target.
  

Latest revision as of 15:41, 19 September 2017

This page is outdated and we are working on much better cross-compilation support, try the new runtime cross-compilation tool instead.


This page will show you how to build a ldc cross-compiler for ARM architecture on GNU/Linux, so that you can build an executable binary with the druntime/phobos and run it on your ARM target.

Prerequisites

  • Linux host, where you'll build and run ldc.
  • C/C++ toolchain, to build llvm and parts of ldc.
  • A pre-built D compiler for GNU/Linux, needed because the ldc frontend is written in D.
  • Common development tools, such as CMake and git, and ldc uses libconfig++
  • ldc/druntime/phobos source
  • llvm 3.8 source, either from the official release or git.
  • GNU ARM toolchain that supports your ARM target [1]
    • In this example, GNU ARM Embedded Toolchain 4.3.3-2009-q1 is used, installed on the host at /opt/arm-2009q1
  • An ARM target with a running GNU/Linux installed on it (like an Ubuntu distribution installed on a Raspberry Pi)

Compile llvm

Get the source for llvm, either the latest official 3.8.0 release or a git repository, like this llvm mirror. Build llvm as you would normally, with the ARM target:

curl -O http://llvm.org/releases/3.8.0/llvm-3.8.0.src.tar.xz
tar xvf llvm-3.8.0.src.tar.xz

mkdir llvm-3.8.0.arm_obj/
cd llvm-3.8.0.arm_obj/
cmake ../llvm-3.8.0.src -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=ARM
make -j5

Build ldc for GNU/ARM

Clone the ldc repository, check out the release-1.0.0 branch, apply the ARM patch, set the DMD environment variable to the path of your pre-built D compiler, and build ldc, druntime and phobos as usual:

cd ..
git clone --recursive https://github.com/ldc-developers/ldc.git
cd ldc/
git checkout -b ddmd origin/release-1.0.0
git submodule update
curl -O https://gist.githubusercontent.com/claudemr/3367c13095b15d449b1591eb38d098d9/raw/3517a5db2228e57da9dd8880a82d6bfe6f0e38f1/ldc_1.0.0_gnu_arm
git apply ldc_1.0.0_gnu_arm

mkdir build_arm
cd build_arm
export DMD=/path/to/your/dmd2/linux/bin64/dmd
cmake .. -DLLVM_CONFIG=../../llvm-3.8.0.arm_obj/bin/llvm-config
make druntime-ldc phobos2-ldc -j5

Build a command-line executable

Now that we have a D cross-compiler and cross-compiled the standard library for GNU/ARM, let's try building a small program, the classic Hello world:

./bin/ldc2 -v -mtriple=arm-none-linux-gnueabi -gcc=/opt/arm-2009q1/bin/arm-none-linux-gnueabi-gcc helloworld.d

Push and run this program on an ARM device with GNU/Linux

Directions for future work

  • Run druntime and phobos unit-tests.