@@ -0,0 +1,98 @@
1+{ stdenv, fetchFromGitHub, cmake, llvm, dmd, curl, tzdata, python,
2+ lit, gdb, unzip, darwin }:
3+
4+stdenv.mkDerivation rec {
5+ name = "ldc-${version}";
6+ version = "1.3.0";
7+
8+ srcs = [
9+ (fetchFromGitHub {
10+ owner = "ldc-developers";
11+ repo = "ldc";
12+ rev = "v${version}";
13+ sha256 = "1ac3j4cwwgjpayhijxx4d6478bc3iqksjxkd7xp7byx7k8w1ppdl";
14+ })
15+ (fetchFromGitHub {
16+ owner = "ldc-developers";
17+ repo = "druntime";
18+ rev = "ldc-v${version}";
19+ sha256 = "1m13370wnj3sizqk3sdpzi9am5d24srf27d613qblhqa9n8vwz30";
20+ })
21+ (fetchFromGitHub {
22+ owner = "ldc-developers";
23+ repo = "phobos";
24+ rev = "ldc-v${version}";
25+ sha256 = "0fhcdfi7a00plwj27ysfyv783nhk0kspq7hawf6vbsl3s1nyvn8g";
26+ })
27+ (fetchFromGitHub {
28+ owner = "ldc-developers";
29+ repo = "dmd-testsuite";
30+ rev = "ldc-v${version}";
31+ sha256 = "0dmdkp220gqhxjrmrjfkf0vsvylwfaj70hswavq4q3v4dg17pzmj";
32+ })
33+ ];
34+
35+ sourceRoot = ".";
36+
37+ postUnpack = ''
38+ mv ldc-v${version}-src/* .
39+
40+ mv druntime-ldc-v${version}-src/* runtime/druntime
41+
42+ mv phobos-ldc-v${version}-src/* runtime/phobos
43+
44+ mv dmd-testsuite-ldc-v${version}-src/* tests/d2/dmd-testsuite
45+
46+ # Remove cppa test for now because it doesn't work.
47+ rm tests/d2/dmd-testsuite/runnable/cppa.d
48+ rm tests/d2/dmd-testsuite/runnable/extra-files/cppb.cpp
49+ '';
50+
51+ postPatch = ''
52+ substituteInPlace runtime/phobos/std/net/curl.d \
53+ --replace libcurl.so ${curl.out}/lib/libcurl.so
54+
55+ # Ugly hack to fix the hardcoded path to zoneinfo in the source file.
56+ # https://issues.dlang.org/show_bug.cgi?id=15391
57+ substituteInPlace runtime/phobos/std/datetime.d \
58+ --replace /usr/share/zoneinfo/ ${tzdata}/share/zoneinfo/
59+ ''
60+
61+ + stdenv.lib.optionalString stdenv.hostPlatform.isDarwin ''
62+ substituteInPlace driver/tool.cpp \
63+ --replace "gcc" "clang"
64+ '';
65+
66+ nativeBuildInputs = [ cmake llvm dmd python lit gdb unzip ]
67+
68+ ++ stdenv.lib.optional stdenv.hostPlatform.isDarwin (with darwin.apple_sdk.frameworks; [
69+ Foundation
70+ ]);
71+
72+ buildInputs = [ curl tzdata stdenv.cc ];
73+
74+ preConfigure = ''
75+ cmakeFlagsArray=("-DINCLUDE_INSTALL_DIR=$out/include/dlang/ldc")
76+ '';
77+
78+ postConfigure = ''
79+ export DMD=$PWD/bin/ldc2
80+ '';
81+
82+ makeFlags = [ "DMD=$DMD" ];
83+
84+ doCheck = true;
85+
86+ checkPhase = ''
87+ ctest -j $NIX_BUILD_CORES -V DMD=$DMD
88+ '';
89+
90+ meta = with stdenv.lib; {
91+ description = "The LLVM-based D compiler";
92+ homepage = https://github.com/ldc-developers/ldc;
93+ # from https://github.com/ldc-developers/ldc/blob/master/LICENSE
94+ license = with licenses; [ bsd3 boost mit ncsa gpl2Plus ];
95+ maintainers = with maintainers; [ ThomasMader ];
96+ platforms = platforms.unix;
97+ };
98+}