D on Dreamcast: Difference between revisions

From dreamcast.wiki
Jump to navigation Jump to search
(Add TOC)
Line 18: Line 18:
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.
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.


Put the following text in to config.mk:
Find the following text in config.mk:
  # Sega Dreamcast Toolchains Maker (dc-chain)
  # Languages (c|c++|objc|obj-c++|d)
  # This file is part of KallistiOS.
  # 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
# Created by Jim Ursetto (2004)
  # required for KOS itself. D may also be enabled optionally on POSIX platforms
# Initially adapted from Stalin's build script version 0.3.
  # which have its external dependencies installed.
#
  pass2_languages=c,c++,objc,obj-c++
 
# Toolchain versions for SH
Add D to the pass2_languages like so:
sh_binutils_ver=2.41
sh_gcc_ver=13.2.0
newlib_ver=4.3.0.20230120
gdb_ver=13.2
# Tarball extensions to download for SH
sh_binutils_download_type=xz
sh_gcc_download_type=xz
newlib_download_type=gz
gdb_download_type=xz
# Toolchain for ARM
# The ARM version of gcc/binutils is separated as support for the ARM7DI core
  # used in the Dreamcast's AICA is not available in versions of GCC beyond 8.5.0.
arm_binutils_ver=2.41
arm_gcc_ver=8.5.0
# Tarball extensions to download for ARM
arm_binutils_download_type=xz
arm_gcc_download_type=xz
# GCC custom dependencies
# Specify here if you want to use custom GMP, MPFR and MPC libraries when
# building GCC. It is recommended that you leave this variable commented, in
# which case these dependencies will be automatically downloaded by using the
# '/contrib/download_prerequisites' shell script provided within the GCC packages.
# The ISL dependency isn't mandatory; if desired, you may comment the version
  # numbers (i.e. 'sh_isl_ver' and 'arm_isl_ver') to disable the ISL library.
#use_custom_dependencies=1
# GCC dependencies for SH
sh_gmp_ver=6.2.1
sh_mpfr_ver=4.1.0
sh_mpc_ver=1.2.1
sh_isl_ver=0.24
# Tarball extensions to download for GCC dependencies for SH
sh_gmp_download_type=bz2
sh_mpfr_download_type=bz2
sh_mpc_download_type=gz
sh_isl_download_type=bz2
# GCC dependencies for ARM
arm_gmp_ver=6.1.0
arm_mpfr_ver=3.1.4
arm_mpc_ver=1.0.3
arm_isl_ver=0.18
# Tarball extensions to download for GCC dependencies for ARM
arm_gmp_download_type=bz2
arm_mpfr_download_type=bz2
arm_mpc_download_type=gz
arm_isl_download_type=bz2
# Download protocol (http|https|ftp)
# Specify here the protocol you want to use for downloading the packages.
download_protocol=https
# Force downloader (curl|wget)
# You may specify here 'wget' or 'curl'. If this variable is empty or commented,
# web downloader tool will be auto-detected in the following order: cURL, Wget.
# You must have either Wget or cURL installed to use dc-chain.
  #force_downloader=wget
# Specify GNU Mirror override
# The default mirror for GNU sources is `ftpmirror.gnu.org`
# Setting this will allow overriding the default mirror which
# may be desirable if you have a prefered mirror.
#gnu_mirror=mirrors.kernel.org
# Toolchains base
# Indicate the root directory where toolchains will be installed
# This should match your 'environ.sh' configuration
  toolchains_base=/opt/toolchains/dc
# Verbose (1|0)
# Display output to screen as well as log files
verbose=1
# Erase (1|0)
# Erase build directories on the fly to save space
erase=1
# Install mode (install-strip|install)
# Use 'install-strip' mode for removing debugging symbols of the toolchains.
# Use 'install' only if you want to enable debug symbols for the toolchains.
# This may be useful only if you plan to debug the toolchain itself.
install_mode=install-strip
# Make jobs (-jn|<empty>)
# Set this value to -jn where n is the number of jobs you want to run with make.
# If you only want one job, just set this to nothing (i.e, "makejobs=").
# Tracking down problems with multiple make jobs is much more difficult than
# with just one running at a time. So, if you run into trouble, then you should
# clear this variable and try again with just one job running.
# Please note, this value may be overriden in some cases; as issues were
# detected on some OS.
makejobs=-j16
# Languages (c|c++|objc|obj-c++)
# Set the languages to build for pass 2 of building gcc for sh-elf. The default
# here is to build C, C++, Objective C, and Objective C++. You may want to take
# out the latter two if you're not worried about them and/or you're short on
# hard drive space.
  pass2_languages=c,c++,objc,obj-c++,d
  pass2_languages=c,c++,objc,obj-c++,d
# GCC threading model (single|kos|posix*)
# With GCC 4.x versions and up, the patches provide a 'kos' thread model, so you
# should use it. If you really don't want threading support for C++ (or
# Objective C/Objective C++), you can set this to 'single'. With GCC 3.x, you
# probably want 'posix' here; but this mode is deprecated as the GCC 3.x branch
# is not anymore supported.
thread_model=kos
# Automatic patching for KOS (1|0)
# Uncomment this if you want to disable applying KOS patches to the toolchain
# source files before building. This will disable usage of the 'kos' thread model.
#use_kos_patches=0
# Automatic fixup SH-4 Newlib (1|0)
# Uncomment this if you want to disable the automatic fixup sh4 newlib needed by
# KallistiOS. This will keep the generated toolchain completely raw. This will
# also disable the 'kos' thread model. Don't mess with that flag unless you know
# exactly what you are doing.
#auto_fixup_sh4_newlib=0
# C99 Format Specifier Support (1|0)
# Define this to build SH4 Newlib with additional support for the C99 format
# specifiers, used by printf and friends. These include support for size_t,
# ptrdiff_t, intmax_t, and sized integral types.
#newlib_c99_formats=1
# Optimize Newlib for Space (1|0)
# Define this to enable optimizing for space when building Newlib. This will
# build Newlib with compiler flags which favor smaller code sizes over faster
# performance.
#newlib_opt_space=1
# MinGW/MSYS
# Standalone binaries (1|0)
# Define this if you want a standalone, no dependency binaries (i.e. static)
# When the binaries are standalone, it can be run outside MinGW/MSYS
# environment. This is NOT recommended. Use it if you know what you are doing.
#standalone_binary=1
# Force installation of BFD for SH (1|0)
# Uncomment this if you want to force the installation of 'libbfd' for the SH
# toolchain. This is required for MinGW/MSYS and can't be disabled in this
# scenario. This option is here mainly if you want to force the installation of
# 'libbfd' under other environments; but this won't be necessary in most cases,
# as 'libelf' is used almost everywhere. Please note, 'libbfd' couldn't be
# portable if you built it on another environment. Don't mess with that flag
# unless you know exactly what you are doing.
#sh_force_libbfd_installation=1


Additionally, add <code>--disable-libphobos \</code> to the configure step in <code>scripts/gcc-pass2.mk</code>
Once this is done you can continue building and installing the compiler to <code>/opt/toolchains/dc</code>!
Once this is done you can continue building and installing the compiler to <code>/opt/toolchains/dc</code>!



Revision as of 03:43, 27 April 2024

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.