1{ stdenv, fetchgit, fetchurl, cmake, llvm, curl, tzdata
2, python, libconfig, lit, gdb, unzip, darwin, bash
3, callPackage
4, bootstrapVersion ? false
5, version ? "1.7.0"
6, ldcSha256 ? "1g8qvmlzvsp030z2rw6lis4kclsd9mlmnbim5kas0k1yr9063m3w"
7}:
8
9let
10
11 bootstrapLdc = if !bootstrapVersion then
12 # LDC 0.17.x is the last version which doesn't need a working D compiler to
13 # build so we use that version to bootstrap the actual build.
14 callPackage ./default.nix {
15 bootstrapVersion = true;
16 version = "0.17.5";
17 ldcSha256 = "0200r5y8hs5yv2cx24csgyh00dlg18877b9cfblixypr6nhl19bs";
18 }
19 else
20 "";
21
22 ldcBuild = stdenv.mkDerivation rec {
23 name = "ldcBuild-${version}";
24
25 enableParallelBuilding = true;
26
27 src = fetchurl {
28 url = "https://github.com/ldc-developers/ldc/releases/download/v${version}/ldc-${version}-src.tar.gz";
29 sha256 = ldcSha256;
30 };
31
32 sourceRoot = ".";
33
34 postUnpack = ''
35 cd ldc-${version}-src/
36
37 patchShebangs .
38
39 # Remove cppa test for now because it doesn't work.
40 rm tests/d2/dmd-testsuite/runnable/cppa.d
41 rm tests/d2/dmd-testsuite/runnable/extra-files/cppb.cpp
42 ''
43
44 + stdenv.lib.optionalString (bootstrapVersion) ''
45 # ... runnable/variadic.d ()
46 #Test failed. The logged output:
47 #/tmp/nix-build-ldcBuild-0.17.5.drv-0/ldc-0.17.5-src/build/bin/ldmd2 -conf= -m64 -Irunnable -od/tmp/nix-build-ldcBuild-0.17.5.drv-0/ldc-0.17.5-src/build/dmd-testsuite/runnable -of/tmp/nix-build-ldcBuild-0.17.5.drv-0/ldc-0.17.5-src/build/dmd-testsuite/runnable/variadic_0 runnable/variadic.d
48 #Error: integer constant expression expected instead of <cant>
49 #Error: integer constant expression expected instead of <cant>
50 #Error: integer constant expression expected instead of <cant>
51 #Error: integer constant expression expected instead of <cant>
52 #Error: integer constant expression expected instead of <cant>
53 #runnable/variadic.d(84): Error: template instance variadic.Foo3!(int, int, int) error instantiating
54 #
55 #
56 #==============================
57 #Test failed: expected rc == 0, exited with rc == 1
58 rm tests/d2/dmd-testsuite/runnable/variadic.d
59 ''
60
61 + stdenv.lib.optionalString (!bootstrapVersion) ''
62 # http://forum.dlang.org/thread/xtbbqthxutdoyhnxjhxl@forum.dlang.org
63 rm -r tests/dynamiccompile
64 '';
65
66 ROOT_HOME_DIR = "$(echo ~root)";
67
68 datetimePath = if bootstrapVersion then
69 "phobos/std/datetime.d"
70 else
71 "phobos/std/datetime/timezone.d";
72
73 postPatch = ''
74 substituteInPlace runtime/${datetimePath} \
75 --replace "import core.time;" "import core.time;import std.path;"
76
77 substituteInPlace runtime/${datetimePath} \
78 --replace "tzName == \"leapseconds\"" "baseName(tzName) == \"leapseconds\""
79
80 substituteInPlace runtime/phobos/std/net/curl.d \
81 --replace libcurl.so ${curl.out}/lib/libcurl.so
82
83 # Ugly hack to fix the hardcoded path to zoneinfo in the source file.
84 # https://issues.dlang.org/show_bug.cgi?id=15391
85 substituteInPlace runtime/${datetimePath} \
86 --replace /usr/share/zoneinfo/ ${tzdata}/share/zoneinfo/
87
88 substituteInPlace tests/d2/dmd-testsuite/Makefile \
89 --replace "SHELL=/bin/bash" "SHELL=${bash}/bin/bash"
90 ''
91
92 + stdenv.lib.optionalString stdenv.hostPlatform.isLinux ''
93 # See https://github.com/NixOS/nixpkgs/issues/29443
94 substituteInPlace runtime/phobos/std/path.d \
95 --replace "\"/root" "\"${ROOT_HOME_DIR}"
96
97 # Can be remove with front end version >= 2.078.0
98 substituteInPlace runtime/druntime/src/core/memory.d \
99 --replace "assert(z is null);" "//assert(z is null);"
100 ''
101
102 + stdenv.lib.optionalString (bootstrapVersion && stdenv.hostPlatform.isDarwin) ''
103 # https://github.com/ldc-developers/ldc/pull/2306
104 # Can be removed on bootstrap version > 0.17.5
105 substituteInPlace gen/programs.cpp \
106 --replace "gcc" "clang"
107
108 # Was not able to compile on darwin due to "__inline_isnanl"
109 # being undefined.
110 substituteInPlace dmd2/root/port.c --replace __inline_isnanl __inline_isnan
111 ''
112
113 + stdenv.lib.optionalString (!bootstrapVersion) ''
114 # TODO Can be removed with the next ldc version > 1.7.0
115 # https://github.com/ldc-developers/ldc/issues/2493
116 substituteInPlace tests/d2/dmd-testsuite/Makefile \
117 --replace "# disable tests based on arch" "DISABLED_TESTS += test_cdvecfill"
118 ''
119
120 + stdenv.lib.optionalString (bootstrapVersion) ''
121 substituteInPlace runtime/${datetimePath} \
122 --replace "import std.traits;" "import std.traits;import std.path;"
123
124 substituteInPlace runtime/${datetimePath} \
125 --replace "tzName == \"+VERSION\"" "baseName(tzName) == \"leapseconds\" || tzName == \"+VERSION\""
126 '';
127
128 nativeBuildInputs = [ cmake llvm bootstrapLdc python lit gdb unzip ]
129
130 ++ stdenv.lib.optional (bootstrapVersion) [
131 libconfig
132 ]
133
134 ++ stdenv.lib.optional stdenv.hostPlatform.isDarwin (with darwin.apple_sdk.frameworks; [
135 Foundation
136 ]);
137
138
139 buildInputs = [ curl tzdata stdenv.cc ];
140
141 preConfigure = ''
142 cmakeFlagsArray=("-DINCLUDE_INSTALL_DIR=$out/include/dlang/ldc"
143 "-DCMAKE_BUILD_TYPE=Release"
144 "-DCMAKE_SKIP_RPATH=ON"
145 "-DBUILD_SHARED_LIBS=OFF"
146 "-DLDC_WITH_LLD=OFF"
147 # Xcode 9.0.1 fixes that bug according to ldc release notes
148 "-DRT_ARCHIVE_WITH_LDC=OFF"
149 )
150 '';
151
152
153 postConfigure = ''
154 export DMD=$PWD/bin/ldmd2
155 '';
156
157 makeFlags = [ "DMD=$DMD" ];
158
159 doCheck = true;
160
161 checkPhase = ''
162 # Build and run LDC D unittests.
163 ctest --output-on-failure -R "ldc2-unittest"
164 # Run LIT testsuite.
165 ctest -V -R "lit-tests"
166 # Run DMD testsuite.
167 DMD_TESTSUITE_MAKE_ARGS=-j$NIX_BUILD_CORES ctest -V -R "dmd-testsuite"
168 '';
169
170 meta = with stdenv.lib; {
171 description = "The LLVM-based D compiler";
172 homepage = https://github.com/ldc-developers/ldc;
173 # from https://github.com/ldc-developers/ldc/blob/master/LICENSE
174 license = with licenses; [ bsd3 boost mit ncsa gpl2Plus ];
175 maintainers = with maintainers; [ ThomasMader ];
176 platforms = [ "x86_64-linux" "i686-linux" "x86_64-darwin" ];
177 };
178 };
179
180 # Need to test Phobos in a fixed-output derivation, otherwise the
181 # network stuff in Phobos would fail if sandbox mode is enabled.
182 ldcUnittests = stdenv.mkDerivation rec {
183 name = "ldcUnittests-${version}";
184
185 enableParallelBuilding = ldcBuild.enableParallelBuilding;
186 preferLocalBuild = true;
187 inputString = ldcBuild.outPath;
188 outputHashAlgo = "sha256";
189 outputHash = builtins.hashString "sha256" inputString;
190
191 src = ldcBuild.src;
192
193 sourceRoot = ".";
194
195 postUnpack = ldcBuild.postUnpack;
196
197 postPatch = ldcBuild.postPatch;
198
199 nativeBuildInputs = ldcBuild.nativeBuildInputs
200
201 ++ [
202 ldcBuild
203 ];
204
205 buildInputs = ldcBuild.buildInputs;
206
207 preConfigure = ''
208 cmakeFlagsArray=( "-DINCLUDE_INSTALL_DIR=$out/include/dlang/ldc"
209 "-DCMAKE_BUILD_TYPE=Release"
210 "-DCMAKE_SKIP_RPATH=ON"
211 "-DBUILD_SHARED_LIBS=OFF"
212 "-DLDC_WITH_LLD=OFF"
213 # Xcode 9.0.1 fixes that bug according to ldc release notes
214 "-DRT_ARCHIVE_WITH_LDC=OFF"
215 "-DD_COMPILER=${ldcBuild}/bin/ldmd2"
216 )
217 '';
218
219 postConfigure = ldcBuild.postConfigure;
220
221 makeFlags = ldcBuild.makeFlags;
222
223 buildCmd = if bootstrapVersion then
224 "ctest -V -R \"build-druntime-ldc-unittest|build-phobos2-ldc-unittest\""
225 else
226 "make -j$NIX_BUILD_CORES DMD=${ldcBuild}/bin/ldc2 druntime-test-runner druntime-test-runner-debug phobos2-test-runner phobos2-test-runner-debug";
227
228 testCmd = if bootstrapVersion then
229 "ctest -j$NIX_BUILD_CORES --output-on-failure -E \"dmd-testsuite|lit-tests|ldc2-unittest|llvm-ir-testsuite\""
230 else
231 "ctest -j$NIX_BUILD_CORES --output-on-failure -E \"dmd-testsuite|lit-tests|ldc2-unittest\"";
232
233 buildPhase = ''
234 ${buildCmd}
235 ${testCmd}
236 '';
237
238 installPhase = ''
239 echo -n $inputString > $out
240 '';
241 };
242
243in
244
245stdenv.mkDerivation rec {
246 inherit ldcUnittests;
247 name = "ldc-${version}";
248 phases = "installPhase";
249 buildInputs = ldcBuild.buildInputs;
250
251 installPhase = ''
252 mkdir $out
253 cp -r --symbolic-link ${ldcBuild}/* $out/
254 '';
255
256 meta = ldcBuild.meta;
257}
258