D on Dreamcast

From dreamcast.wiki
Jump to navigation Jump to search

Introduction

D is a flexible systems programming language, which allows writing fast software, fast. Getting DLang on the Dreamcast is in of itself simple, using the GCC D compiler (GDC), but as of current the D runtime and standard library are unavailable. As such alternatives need to be used, without the garbage collector you'd find in stock DLang.

Currently, building the compiler on Windows is very difficult and it's recommended to build it on macOS or Linux, or via WSL.

Prerequisites

A few utilities for D are needed to get started, namely dub, the D package manager. You can get this by going to https://dlang.org and downloading the DMD or LDC2 distributions of D. You will not need the compilers or standard libraries that come with either package for dreamcast development, but they may be useful for developing tooling. Dub comes bundled with both DMD and LDC2, there's no precompiled GDC package and it is considerably more difficult to get a full D environment set up the manual route, so it is not recommended.

You will additionally need to get the dc-chain script installed, together with a copy of git. See (the C/C++) getting started guide and follow it till the Configuring the dc-chain script section.

Building the D cross compiler

Once you have the D utilities, dc-chain and git installed and you have the dc-chain config available, you will need to modify the build script.

Find the following text in config.mk:

# Languages (c|c++|objc|obj-c++|d)
# Set the languages to build for sh-elf gcc compilation pass 2. The default is
# to build everything used by all KOS examples; however, only C is actually
# required for KOS itself. D may also be enabled optionally on POSIX platforms
# which have its external dependencies installed.
pass2_languages=c,c++,objc,obj-c++

Add D to the pass2_languages like so:

pass2_languages=c,c++,objc,obj-c++,d

Once this is done you can continue building and installing the compiler to /opt/toolchains/dc!

With this done you should have a functional D toolchain for the SEGA Dreamcast installed.

Post Build

You can use the dkos and numem packages to develop software for the Dreamcast, do note that DKOS is still in development and some features are still missing, contributions are welcome!

DKOS depends on a custom runtime called tinyd-rt, which automatically should get fetched on build.