Building LDC runtime libraries

From D Wiki
Revision as of 21:39, 24 August 2017 by Kinke (talk | contribs) (Prerequisites)
Jump to: navigation, search

Starting with v1.4, LDC ships with the ldc-build-runtime tool. It allows LDC users to easily build tailored LDC runtime libraries (and optionally their accompanying testrunners) themselves.

Use cases

  • Enabling LTO (Link-Time Optimization) for the runtime libraries by recompiling them with -flto. Linking against these may result in significant performance gains and smaller binaries.
  • Enabling sanitizer checks via -fsanitize.
  • Cross-compilation/linking, as a set of existing druntime/Phobos libraries for the selected target platform is required as prerequisite for cross-linking D executables and shared libraries.
    • This scenario also includes porting LDC to a new target platform, i.e., working on the runtime libraries on an arbitrary already supported host platform while possibly patching the host LDC in parallel (ABI etc.) until the runtime libraries can be successfully cross-built to the new target and ideally all testrunners run successfully (in an emulator or natively on the target).

Prerequisites

  • CMake
  • Either Make or Ninja (recommended, enable with --ninja)
  • C toolchain (compiler, linker and libraries): gcc, clang, Microsoft Visual C++, …
  • tar (can be worked around on Windows via --ldcSrcDir=/path/to/ldc-src)

How it works

If run without special command-line options, ldc-build-runtime automates:

  • Creating a build directory
  • Downloading & extracting the LDC source archive matching the LDC version
  • Invoking CMake to generate the Makefile for the runtime libraries
  • Invoking Make/Ninja to build the runtime libraries

Usage

The primary aim is to allow specifying additional compiler/linker command-line options and customizing CMake variables.
Use ldc-build-runtime -h for the full list of command-line options.

Basic usage:

ldc-build-runtime -j4 [--testrunners] --dFlags=… --cFlags=… --linkerFlags=… CMAKE_VAR1=value1 CMAKE_VAR2=value2 …

Basic usage for cross-compilation:

CC=cross-gcc ldc-build-runtime -j4 --dFlags="-mtriple=…;…" --cFlags=… --linkerFlags=… TARGET_SYSTEM=… …

See Joakim's forum post for a real-world command-line for cross-compiling to Android.

If you built LDC yourself from a non-tagged source, you will most likely get an error when trying to download the LDC source archive. In that case, use the --ldcSrcDir=/path/to/ldc-src option to reuse your source tree.