https://wiki.dlang.org/api.php?action=feedcontributions&user=Thomad&feedformat=atomD Wiki - User contributions [en]2024-03-29T10:08:15ZUser contributionsMediaWiki 1.31.2https://wiki.dlang.org/?title=Building_under_Posix&diff=9451Building under Posix2018-12-28T16:12:24Z<p>Thomad: /* Document TZDatabaseDir and LibcurlPath options */</p>
<hr />
<div>== Prerequisites ==<br />
<br />
To build D on POSIX, you will need to have <tt>make</tt>, <tt>g++</tt>, <tt>libcurl4-openssl-dev</tt>, and <tt>git</tt> installed on your system, as well as a working GitHub account. To install the appropriate dependencies on e.g. Ubuntu:<br />
<br />
sudo apt-get install curl git make g++ libcurl4-openssl-dev<br />
<br />
On OS X with Homebrew:<br />
<br />
$ xcode-select --install<br />
$ brew install git openssl<br />
<br />
To build the 32-bit phobos on a 64-bit machine, some 32-bit packages are also needed:<br />
<br />
sudo apt-get install gcc-multilib g++-multilib libc6-dev-i386 linux-libc-dev:i386 libcurl4-gnutls-dev:i386<br />
<br />
Other versions and variations of <tt>libcurl</tt> may work as well.<br />
<br />
== Building D ==<br />
<br />
=== Fetch repositories from GitHub ===<br />
<br />
Let's start by getting the current development (master) branch of the D repositories from GitHub. Assume the root directory for everything D-related is <tt>~/dlang</tt> (replace appropriately). This is easily done by running at a command prompt:<br />
<br />
<syntaxhighlight lang=bash><br />
cd ~/dlang<br />
git clone https://github.com/dlang/dmd<br />
git clone https://github.com/dlang/druntime<br />
git clone https://github.com/dlang/phobos<br />
git clone https://github.com/dlang/tools<br />
</syntaxhighlight><br />
<br />
After this step completes successfully, the <tt>~/dlang</tt> should be up and filled with good stuff.<br />
<br />
=== Bootstrap <tt>dmd</tt> ===<br />
<br />
This step is interesting because in order to build <tt>dmd</tt>, <tt>dmd</tt> is necessary. Fortunately, the steps of downloading and using a preexisting <tt>dmd</tt> compiler are automated (only for platforms for which [https://dlang.org/download there are official builds: Windows, macOS, linux, and FreeBSD]). All you need to do is run this command:<br />
<br />
<syntaxhighlight lang=bash><br />
cd ~/dlang/dmd<br />
make -f posix.mak -j8 AUTO_BOOTSTRAP=1<br />
</syntaxhighlight><br />
<br />
That's going to take a while. The build produces the compiler binary situated in an OS-dependent directory such as <tt>~/dlang/dmd/generated/linux/release/64/dmd</tt>.<br />
<br />
To make <tt>dmd</tt> builds faster in the future, you need to obviate the need for bootstrapping. Install <tt>dmd</tt> from the [http://dlang.org/download.html download page] or simply put the freshly built <tt>dmd</tt> binary in a place accessible through <tt>$PATH</tt> (a popular choice is <tt>~/bin</tt>).<br />
<br />
=== Build <tt>phobos</tt> ===<br />
<br />
Most D programs use D's standard library <tt>phobos</tt>. To build it, run:<br />
<br />
<syntaxhighlight lang=bash><br />
cd ~/dlang/phobos<br />
make -f posix.mak -j8<br />
</syntaxhighlight><br />
<br />
The build produces (with similar anticlimacticity) static and shared libraries such as <tt>~/dlang/phobos/generated/linux/release/64/libphobos2.a</tt> and <tt>~/code/phobos/generated/linux/release/64/libphobos2.so</tt>.<br />
<br />
As part of the build <tt>druntime</tt> will be built automatically, e.g. the generated <tt>druntime</tt> interfaces can be found at <tt>~/dlang/druntime/import</tt>.<br />
The generated <tt>druntime</tt> libraries like <tt>~/dlang/druntime/generated/linux/release/64/libdruntime.a</tt> get bundled with built <tt>phobos</tt> libraries.<br />
<br />
==== TZDatabaseDir ====<br />
<br />
Phobos needs to find the tzdata dir on Posix systems. Normally it is located on standard paths and Phobos uses those. But on some systems such as NixOS for example, there is no such standard path and to build Phobos properly, it's needed to specify the absolute path to the directory.<br />
This is possible by writing the path to a file named <tt>TZDatabaseDirFile</tt> and telling the compiler to use this file as an import for the path via the <tt>DFLAGS</tt> argument listed below. The <tt>-J</tt> argument defines the path where the compiler should look for the <tt>TZDatabaseDirFile</tt>.<br />
<syntaxhighlight lang=bash><br />
cd ~/dlang/phobos<br />
make -f posix.mak -j8 DFLAGS="-version=TZDatabaseDir -J/tmp/"<br />
</syntaxhighlight><br />
<br />
==== LibcurlPath ====<br />
<br />
For the same reason as for the tzdata dir, it's possible to specify the absolute path to the libcurl library.<br />
This is possible by writing the path to a file named <tt>LibcurlPathFile</tt> and using the <tt>DFLAGS</tt> argument as in the <tt>TZDatabaseDir</tt> case.<br />
<syntaxhighlight lang=bash><br />
cd ~/dlang/phobos<br />
make -f posix.mak -j8 DFLAGS="-version=LibcurlPath -J/tmp/"<br />
</syntaxhighlight><br />
<br />
=== Building <tt>dmd</tt> for Windows on Linux ===<br />
<br />
Most Linux developers do not have a Windows machine to test their changes on both platforms, fortunately there is a tool called Wine (Windows Emulator) which enables running Windows specific binaries on Linux. In order to be able to build and run the Windows dmd version on Linux, you must go through the following steps: (it is assumed that all the above steps have been completed)<br />
<br />
1. Install Wine following the instructions found [https://wiki.winehq.org/Ubuntu here].<br />
<br />
2. Download [http://dlang.org/download.html the Windows dmd installer]<br />
<br />
3. Install dmd for Windows using Wine<br />
<br />
wine /path/to/dmd/installer.exe<br />
<br />
This command will start the dmd Windows installation as if you were on Windows. Wine creates a typical Windows directory structure located in ~/.wine/drive_c where drive_c is the directory which corresponds to C:\ on Windows. The default installation directory is C:\D, the rest of this document assumes that. Add the optional "DMC" package during the installation.<br />
<br />
4. Now that the Windows compiler is installed, all we need to do is to properly set the environment variables needed by win32.mak. Wine forwards all the existing environment variables, except a few special ones : <b>PATH</b>, <b>TEMP</b>, <b>SYSTEM</b>. However, <b>WINEPATH</b> can be used instead of <b>PATH</b>. Assuming that D is installed in C:\, you need to set the following environment variables:<br />
<br />
<syntaxhighlight lang=bash><br />
export DM_HOME=C:/D<br />
export HOST_DC=dmd<br />
export WINEPATH="C:\DMC\dm\bin\;C:\D\dmd2\windows\bin"<br />
</syntaxhighlight><br />
<br />
5. At this point we should be good to go: <br />
<br />
<syntaxhighlight lang=bash><br />
cd /path/to/dmd<br />
wine make -fwin32.mak<br />
</syntaxhighlight><br />
<br />
The command above builds the executable <tt>/path/to/dmd/generated/windows/release/32/dmd.exe</tt>. <br />
<br />
6. To build druntime with the newly generated compiler, run:<br />
<br />
<syntaxhighlight lang=bash><br />
cd /path/to/druntime<br />
wine make -fwin32.mak<br />
</syntaxhighlight><br />
<br />
7. Finally, to build phobos again using the newly generated compiler, run:<br />
<br />
<syntaxhighlight lang=bash><br />
cd /path/to/phobos<br />
wine make -fwin32.mak<br />
</syntaxhighlight><br />
<br />
'''NOTE''' : building the latest development version of the compiler in linux, under wine, requires that the latest windows release version of the compiler is installed via wine.<br />
<br />
== Where to go from here ==<br />
<br />
If you want to contribute to a D project, please continue with the [[Starting_as_a_Contributor| starting as a contributor]] guide.<br />
If you want to contribute to Phobos, you may also read the [[Contributing to Phobos|contributing to Phobos guide]].</div>Thomadhttps://wiki.dlang.org/?title=Compilers&diff=9051Compilers2018-03-04T14:05:51Z<p>Thomad: Add Nix/NixOS information</p>
<hr />
<div>__NOTOC__<br />
{{:Compilers_Widget}}<br />
<table style="width:100%;" cellspacing="10"><br />
<tr><br />
<td style="width:33%; vertical-align: top; padding: 10px 10px; background: #f9f9f9; border: 1px solid #ccc; border-top: 1px solid #eee; border-bottom: 2px solid #999;"><br />
= [[DMD|DMD &raquo;]] =<br />
'''Digital Mars D compiler''' <br/>The official reference D compiler.<br />
<div style="text-align: right;">[[DMD|DMD Portal &raquo;]]</div><br />
</td><br />
<br />
<td style="width:33%; vertical-align: top; padding: 10px 10px; background: #f9f9f9; border: 1px solid #ccc; border-top: 1px solid #eee; border-bottom: 2px solid #999;"><br />
<br />
<br />
<br />
[[Category:Compiler]]<br />
<br />
= [[GDC|GDC &raquo;]] =<br />
'''GCC D compiler'''<br/><br />
The DMD compiler front end coupled with the GCC compiler back end. Fast and open source.<br />
<div style="text-align: right;">[[GDC|GDC Portal &raquo;]]</div><br />
</td><br />
<br />
<td style="width:33%; vertical-align: top; padding: 10px 10px; background: #f9f9f9; border: 1px solid #ccc; border-top: 1px solid #eee; border-bottom: 2px solid #999;"><br />
= [[LDC|LDC &raquo;]] =<br />
'''LLVM D compiler'''<br/><br />
The DMD compiler front end coupled with the LLVM compiler back end. Fast and open source.<br />
<div style="text-align: right;">[[LDC|LDC Portal &raquo;]]</div><br />
</td><br />
<br />
</tr><br />
</table><br />
<br />
== Which compiler should I use? ==<br />
If you're a beginner DMD is the recommended choice, as it is the implementation closest to the D Language Specification. Otherwise it depends on what you need, what platforms you intend to develop for, and your personal preferences. GDC and LDC both generate substantially faster binaries than DMD.<br />
<br />
== Comparison ==<br />
<br />
{| class="wikitable" style="width: 65em"<br />
!<br />
!DMD<br />
!GDC<br />
!LDC<br />
|---<br />
|'''Platforms'''<br />
|<br />
*Windows<br />
*Linux<br />
*OS X<br />
*FreeBSD<br />
|<br />
*Windows (alpha)<br />
*Linux<br />
*OS X (untested)<br />
*FreeBSD (untested)<br />
|<br />
*Windows<br />
*Linux<br />
*OS X<br />
*FreeBSD<br />
*OpenSolaris<br />
*iOS (alpha)<br />
*Android<br />
|---<br />
<br />
|'''Architectures'''<br />
|<br />
* i386<br />
* amd64<br />
|<br />
Complete (runtime / standard library) support:<br />
* i386<br />
* amd64<br />
* x32<br />
* armel<br />
* armhf<br />
<br />
Partial or bare-metal only support (packages for gdc in [https://packages.debian.org/sid/gdc-5 debian]):<br />
* alpha<br />
* arm64 (aarch64)<br />
* hppa<br />
* hurd-i386<br />
* kfreebsd-amd64<br />
* kfreebsd-i386<br />
* m68k<br />
* mips<br />
* mipsel<br />
* ppc<br />
* pcc64<br />
* ppc64el<br />
* s390x<br />
* sparc64<br />
|<br />
Complete (runtime / standard library) support:<br />
* i386<br />
* amd64<br />
* armel<br />
* armhf<br />
<br />
Near-complete support:<br />
* arm64 (aarch64)<br />
* ppc<br />
* ppc64<br />
* ppc64el<br />
* mips64<br />
<br />
Partial or bare-metal only support:<br />
* mips<br />
* s390x<br />
|---<br />
|'''Distribution'''<br />
|<br />
*Source<br />
*Multi-platform source/binary archive<br />
*Multi-platform installer ([https://github.com/jacob-carlborg/dvm DVM])<br />
*Windows installer<br />
*OS X package (.dmg)<br />
*Debian/Ubuntu package (.deb)<br />
*Fedora package (.rpm)<br />
*OpenSUSE (.rpm) package<br />
*Debian/Ubuntu repository via http://d-apt.sourceforge.net<br />
*OS-X homebrew and macports repositories<br />
*Nix/NixOS package (for NixOS, other Linux and OS X)<br />
|<br />
*Source<br />
*Windows / Linux binary archive<br />
*Debian/Ubuntu repository<br />
*Gentoo repository<br />
*Archlinux repository<br />
|<br />
*Source<br />
*Windows / Linux / OS X binary archive<br />
*Debian/Ubuntu repository<br />
*Fedora repository<br />
*Gentoo repository<br />
*FreeBSD repository<br />
*[[Installing_LDC_on_GNU_Guix|GNU Guix]]<br />
*Nix/NixOS package (for NixOS, other Linux and OS X)<br />
|---<br />
|'''Backend'''<br />
| [https://github.com/D-Programming-Language/dmd/tree/master/src/backend DMD] ([http://digitalmars.com/download/freecompiler.html DMC] fork)<br />
| [http://gcc.gnu.org/ GCC]<br />
| [http://llvm.org/ LLVM]<br />
|---<br />
|'''License'''<br />
| Boost<br />
| GPL 3 or later<br />
| LDC-specific code: 3-clause BSD<br />
|---<br />
|'''Inline assembler'''<br />
|<br />
* DMD Intel-like syntax (i386/amd64)<br />
|<br />
* GCC syntax (all targets)<br />
|<br />
* DMD Intel-like syntax (i386/amd64)<br />
* GCC syntax (all targets)<br />
* [[LDC inline IR|LLVM inline IR]]<br />
|---<br />
|'''SIMD'''<br />
| Partial (?)<br />
| Partial (?)<br />
| Partial (?)<br />
|---<br />
|'''Phobos as a shared library'''<br />
|<br />
* Linux<br />
* FreeBSD ?<br />
|<br />
|<br />
* Linux<br />
|---<br />
|'''Building D code as shared library'''<br />
|<br />
* Linux<br />
* FreeBSD ?<br />
* Windows ?<br />
|<br />
|<br />
* Linux<br />
* OS X<br />
|---<br />
|'''Dynamic loading of D shared libraries'''<br />
|<br />
* Linux<br />
|<br />
|<br />
* Linux<br />
* OS X<br />
|---<br />
!colspan="4" align="center"|<br/>'''Linux specific'''<br />
|---<br />
|'''Object file format'''<br />
| ELF<br />
| ELF<br />
| ELF<br />
|---<br />
!colspan="4" align="center"|<br/>'''Mac specific'''<br />
|---<br />
|'''Object file format'''<br />
| Mach-O<br />
| Mach-O<br />
| Mach-O<br />
|---<br />
!colspan="4" align="center"|<br/>'''Windows specific'''<br />
|---<br />
|'''Object file format'''<br />
| OMF (32) / COFF (32 & 64)<br />
| COFF<br />
| COFF<br />
|}<br />
<br />
==Package and/or binary availability, by platform and compiler==<br />
<br />
<div style="background:#ffd; padding: 0.5ex 0.5ex;"><br />
<span style="font-size: 1.4em; color: #ca4;">&#9888;</span> This list had outdated information about package version - thus version information has been removed. Please check the most recent available package yourself on the linked pages.<br />
</div><br />
<br />
<br />
Some unofficial repositories and downloads are listed here, but of course many more do exist. With a little searching, you may be able to find something more up to date for your chosen OS.<br />
<br />
Very old compilers are (mostly) omitted, as they are unlikely to be of interest to users.<br />
<br />
{| class="wikitable" style="width: 65em"<br />
!rowspan="2"|<br/>Platform<br />
!colspan="3" align="center"|Compiler<br />
|---<br />
!DMD<br />
!GDC<br />
!LDC<br />
|---<br />
!Windows<br />
|<br />
*[http://dlang.org/download.html Manual download]<br />
*[https://chocolatey.org Chocolatey]<br />
|<br />
*[http://gdcproject.org/downloads Manual download]<br />
|<br />
*[https://github.com/ldc-developers/ldc/releases Manual download]<br />
|---<br />
!OS X<br />
|<br />
*[http://brew.sh Homebrew]<br />
*[https://www.macports.org MacPorts]<br />
*[https://nixos.org/nixos/packages.html#dmd Nix]<br />
*[http://dlang.org/download.html Manual download]<br />
|<br />
|<br />
*[http://brew.sh Homebrew]<br />
*[https://nixos.org/nixos/packages.html#ldc Nix]<br />
*[https://github.com/ldc-developers/ldc/releases Manual download]<br />
|---<br />
!iOS<br />
|<br />
|<br />
|<br />
*[https://github.com/smolt/ldc-iphone-dev/releases Manual download]<br />
|---<br />
!Android<br />
|<br />
|<br />
|<br />
*[https://github.com/ldc-developers/ldc/releases Manual download]<br />
*[[Build D for Android|Instructions on setup]], including a native package<br />
|---<br />
!Linux (generic)<br />
|<br />
*[http://dlang.org/download.html Manual download]<br />
|<br />
*[http://gdcproject.org/downloads Manual download]<br />
|<br />
*[https://github.com/ldc-developers/ldc/releases Manual download]<br />
*[[LDC cross-compilation for ARM GNU/Linux|Source]] (ARM/Linux cross-compiler)<br />
|---<br />
!Cross-platform<br />
|<br />
* [https://github.com/jacob-carlborg/dvm DVM] (Any version)<br />
|<br />
|<br />
|---<br />
!colspan="4" | Distribution-specific packages<br />
|---<br />
!Debian<br />
|<br />
*[http://dlang.org/download.html Manual download]<br />
*[http://d-apt.sourceforge.net APT repository]<br />
|<br />
* [https://packages.debian.org/jessie/gdc stable]<br />
* [https://packages.debian.org/stretch/gdc testing]<br />
* [https://packages.debian.org/sid/gdc unstable]<br />
|<br />
* [https://packages.debian.org/jessie/ldc stable]<br />
* [https://packages.debian.org/sid/ldc unstable]<br />
|---<br />
!Ubuntu<br />
|<br />
*[http://dlang.org/download.html Manual download]<br />
*[http://d-apt.sourceforge.net APT repository]<br />
|<br />
[http://packages.ubuntu.com/search?keywords=ldc gdc]<br />
|<br />
[http://packages.ubuntu.com/search?keywords=ldc ldc]<br />
|---<br />
!Fedora<br />
|<br />
*[http://dlang.org/download.html Manual download]<br />
|<br />
|<br />
See https://apps.fedoraproject.org/packages/ldc<br />
|---<br />
!OpenSuse<br />
|<br />
*[https://build.opensuse.org/package/show/devel:languages:D/dmd devel:languages:D]<br />
|<br />
|<br />
*[https://build.opensuse.org/project/show/devel:languages:D devel:languages:D]<br />
*[https://build.opensuse.org/project/show/home:marc_schuetz:branches:devel:languages:D home:marc_schuetz]<br />
|---<br />
!CentOS<br />
|<br />
*[http://dlang.org/download.html Manual download]<br />
|<br />
|<br />
|---<br />
!Arch Linux<br />
|<br />
*Community<br />
|<br />
*Community<br />
*AUR ([https://aur.archlinux.org/packages/gdc-git/ git HEAD])<br />
|<br />
*Community<br />
*AUR ([https://aur.archlinux.org/packages/ldc-git/ git HEAD])<br />
|---<br />
!Gentoo<br />
|colspan="3" align=center | see https://wiki.gentoo.org/wiki/Dlang<br />
|---<br />
!FreeBSD<br />
|<br />
*[http://dlang.org/download.html Manual download]<br />
*Ports<br />
|<br />
|<br />
*[https://www.freshports.org/lang/ldc Ports]<br />
|}<br />
<br />
== Experimental compilers and forks ==<br />
<br />
* [[SDC|SDC (Stupid D Compiler)]] - from-scratch D compiler implementation, written in idiomatic D.<br />
* [https://github.com/smolt/ldc-iphone-dev LDC for iOS] - LDC-based toolkit for cross-compiling to iOS<br />
* [https://github.com/joakim-noah/android/releases D for Android] - Toolkit for cross-compiling to Android (x86 using DMD and ARM using LDC)<br />
* [https://github.com/Syniurge/Calypso Calypso] - LDC fork which provides direct Clang interoperability, allowing the use of C headers directly.<br />
* DCompute ([[LDC CUDA and SPIRV]]) - Library and LDC fork to "target CUDA and SPIR to enable hassle free native execution on the gpu" -upstreamed into LDC<br />
* [https://github.com/yebblies/dmd/tree/microd MicroD] - DMD fork which outputs C source code instead of object files<br />
* [https://github.com/adamdruppe/dtojs dtojs] - DMD fork which outputs JavaScript source code instead of object files<br />
* [[DIL]] - D compiler written in D2/Tango (inactive project)<br />
<br />
Category page: [[Experimental compilers]]<br />
<br />
[[Category:Compiler]]</div>Thomad