24 , dmdBootstrap ? callPackage ./bootstrap.nix { }
25 , dmd_bin ? "${dmdBootstrap}/bin"
29 dmdConfFile = writeTextFile {
31 text = (lib.generators.toINI { } {
33 DFLAGS = ''-I@out@/include/dmd -L-L@out@/lib -fPIC ${lib.optionalString (!targetPackages.stdenv.cc.isClang) "-L--export-dynamic"}'';
38 bits = builtins.toString stdenv.hostPlatform.parsed.cpu.bits;
40 if stdenv.isDarwin then
43 stdenv.hostPlatform.parsed.kernel.name;
45 pathToDmd = "\${NIX_BUILD_TOP}/dmd/generated/${osname}/release/${bits}/dmd";
48 stdenv.mkDerivation rec {
52 enableParallelBuilding = true;
66 sha256 = phobosSha256;
73 # https://issues.dlang.org/show_bug.cgi?id=19553
74 hardeningDisable = [ "fortify" ];
76 patches = lib.optionals (lib.versionOlder version "2.088.0") [
77 # Migrates D1-style operator overloads in DMD source, to allow building with
80 url = "https://github.com/dlang/dmd/commit/c4d33e5eb46c123761ac501e8c52f33850483a8a.patch";
83 sha256 = "sha256-N21mAPfaTo+zGCip4njejasraV5IsWVqlGR5eOdFZZE=";
88 patchShebangs dmd/compiler/test/{runnable,fail_compilation,compilable,tools}{,/extra-files}/*.sh
90 rm dmd/compiler/test/runnable/gdb1.d
91 rm dmd/compiler/test/runnable/gdb10311.d
92 rm dmd/compiler/test/runnable/gdb14225.d
93 rm dmd/compiler/test/runnable/gdb14276.d
94 rm dmd/compiler/test/runnable/gdb14313.d
95 rm dmd/compiler/test/runnable/gdb14330.d
96 rm dmd/compiler/test/runnable/gdb15729.sh
97 rm dmd/compiler/test/runnable/gdb4149.d
98 rm dmd/compiler/test/runnable/gdb4181.d
100 # Disable tests that rely on objdump whitespace until fixed upstream:
101 # https://issues.dlang.org/show_bug.cgi?id=23317
102 rm dmd/compiler/test/runnable/cdvecfill.sh
103 rm dmd/compiler/test/compilable/cdcmp.d
106 + lib.optionalString (lib.versionOlder version "2.091.0") ''
107 # This one has tested against a hardcoded year, then against a current year on
108 # and off again. It just isn't worth it to patch all the historical versions
109 # of it, so just remove it until the most recent change.
110 rm dmd/compiler/test/compilable/ddocYear.d
111 '' + lib.optionalString (lib.versionAtLeast version "2.089.0" && lib.versionOlder version "2.092.2") ''
112 rm dmd/compiler/test/dshell/test6952.d
113 '' + lib.optionalString (lib.versionAtLeast version "2.092.2") ''
114 substituteInPlace dmd/compiler/test/dshell/test6952.d --replace "/usr/bin/env bash" "${bash}/bin/bash"
117 + lib.optionalString stdenv.isLinux ''
118 substituteInPlace phobos/std/socket.d --replace "assert(ih.addrList[0] == 0x7F_00_00_01);" ""
119 '' + lib.optionalString stdenv.isDarwin ''
120 substituteInPlace phobos/std/socket.d --replace "foreach (name; names)" "names = []; foreach (name; names)"
123 nativeBuildInputs = [
127 ] ++ lib.optionals (lib.versionOlder version "2.088.0") [
134 ] ++ lib.optionals stdenv.isDarwin [
138 nativeCheckInputs = [
140 ] ++ lib.optionals (lib.versionOlder version "2.089.0") [
150 # Build and install are based on http://wiki.dlang.org/Building_DMD
154 export buildJobs=$NIX_BUILD_CORES
155 if [ -z $enableParallelBuilding ]; then
159 ${dmd_bin}/rdmd dmd/compiler/src/build.d -j$buildJobs HOST_DMD=${dmd_bin}/dmd $buildFlags
160 make -C dmd/druntime -f posix.mak DMD=${pathToDmd} $buildFlags -j$buildJobs
161 echo ${tzdata}/share/zoneinfo/ > TZDatabaseDirFile
162 echo ${lib.getLib curl}/lib/libcurl${stdenv.hostPlatform.extensions.sharedLibrary} > LibcurlPathFile
163 make -C phobos -f posix.mak $buildFlags -j$buildJobs DMD=${pathToDmd} DFLAGS="-version=TZDatabaseDir -version=LibcurlPath -J$PWD"
170 checkFlags = buildFlags;
172 # many tests are disbled because they are failing
174 # NOTE: Purity check is disabled for checkPhase because it doesn't fare well
175 # with the DMD linker. See https://github.com/NixOS/nixpkgs/issues/97420
179 export checkJobs=$NIX_BUILD_CORES
180 if [ -z $enableParallelChecking ]; then
184 NIX_ENFORCE_PURITY= \
185 make -C dmd/compiler/test $checkFlags CC=$CXX SHELL=$SHELL -j$checkJobs N=$checkJobs
187 NIX_ENFORCE_PURITY= \
188 make -C phobos -f posix.mak unittest $checkFlags -j$checkJobs DFLAGS="-version=TZDatabaseDir -version=LibcurlPath -J$PWD"
196 install -Dm755 ${pathToDmd} $out/bin/dmd
198 installManPage dmd/docs/man/man*/*
200 mkdir -p $out/include/dmd
201 cp -r {dmd/druntime/import/*,phobos/{std,etc}} $out/include/dmd/
204 cp phobos/generated/${osname}/release/${bits}/libphobos2.* $out/lib/
206 wrapProgram $out/bin/dmd \
207 --prefix PATH ":" "${targetPackages.stdenv.cc}/bin" \
208 --set-default CC "${targetPackages.stdenv.cc}/bin/cc"
210 substitute ${dmdConfFile} "$out/bin/dmd.conf" --subst-var out
216 find $out/bin -type f -exec ${removeReferencesTo}/bin/remove-references-to -t ${dmd_bin}/dmd '{}' +
219 disallowedReferences = [ dmdBootstrap ];
222 description = "Official reference compiler for the D language";
223 homepage = "https://dlang.org/";
224 # Everything is now Boost licensed, even the backend.
225 # https://github.com/dlang/dmd/pull/6680
226 license = licenses.boost;
227 maintainers = with maintainers; [ ThomasMader lionello dukc jtbx ];
228 platforms = [ "x86_64-linux" "i686-linux" "x86_64-darwin" ];