2022-08-06 15:07:57 +00:00
{ version
2024-04-02 04:20:38 +00:00
, dmdHash
, phobosHash
2022-08-06 15:07:57 +00:00
} :
{ stdenv
, lib
, fetchFromGitHub
2021-02-01 07:30:27 +00:00
, removeReferencesTo
2022-08-06 15:07:57 +00:00
, makeWrapper
, which
, writeTextFile
, curl
, tzdata
, gdb
, Foundation
, callPackage
, targetPackages
, fetchpatch
, bash
, installShellFiles
, git
, unzip
2021-02-01 07:30:27 +00:00
, dmdBootstrap ? callPackage ./bootstrap.nix { }
2024-04-02 04:20:38 +00:00
, dmdBin ? " ${ dmdBootstrap } / b i n "
2022-08-06 15:07:57 +00:00
} :
let
dmdConfFile = writeTextFile {
name = " d m d . c o n f " ;
text = ( lib . generators . toINI { } {
Environment = {
DFLAGS = '' - I @ o u t @ / i n c l u d e / d m d - L - L @ o u t @ / l i b - f P I C ${ lib . optionalString ( ! targetPackages . stdenv . cc . isClang ) " - L - - e x p o r t - d y n a m i c " } '' ;
} ;
} ) ;
} ;
bits = builtins . toString stdenv . hostPlatform . parsed . cpu . bits ;
osname =
if stdenv . hostPlatform . isDarwin then
" o s x "
else
stdenv . hostPlatform . parsed . kernel . name ;
pathToDmd = " \$ { N I X _ B U I L D _ T O P } / d m d / g e n e r a t e d / ${ osname } / r e l e a s e / ${ bits } / d m d " ;
in
2024-04-02 04:20:38 +00:00
stdenv . mkDerivation ( finalAttrs : {
2022-08-06 15:07:57 +00:00
pname = " d m d " ;
inherit version ;
enableParallelBuilding = true ;
srcs = [
( fetchFromGitHub {
owner = " d l a n g " ;
repo = " d m d " ;
2024-04-02 04:20:38 +00:00
rev = " v ${ finalAttrs . version } " ;
hash = dmdHash ;
2022-08-06 15:07:57 +00:00
name = " d m d " ;
} )
( fetchFromGitHub {
owner = " d l a n g " ;
repo = " p h o b o s " ;
2024-04-02 04:20:38 +00:00
rev = " v ${ finalAttrs . version } " ;
hash = phobosHash ;
2022-08-06 15:07:57 +00:00
name = " p h o b o s " ;
} )
] ;
sourceRoot = " . " ;
# https://issues.dlang.org/show_bug.cgi?id=19553
hardeningDisable = [ " f o r t i f y " ] ;
2022-10-26 16:49:13 +00:00
patches = lib . optionals ( lib . versionOlder version " 2 . 0 8 8 . 0 " ) [
2022-08-06 15:07:57 +00:00
# Migrates D1-style operator overloads in DMD source, to allow building with
# a newer DMD
2022-10-26 16:49:13 +00:00
( fetchpatch {
2022-08-06 15:07:57 +00:00
url = " h t t p s : / / g i t h u b . c o m / d l a n g / d m d / c o m m i t / c 4 d 3 3 e 5 e b 4 6 c 1 2 3 7 6 1 a c 5 0 1 e 8 c 5 2 f 3 3 8 5 0 4 8 3 a 8 a . p a t c h " ;
2022-10-26 16:49:13 +00:00
stripLen = 1 ;
extraPrefix = " d m d / " ;
2024-04-02 04:20:38 +00:00
hash = " s h a 2 5 6 - N 2 1 m A P f a T o + z G C i p 4 n j e j a s r a V 5 I s W V q l G R 5 e O d F Z Z E = " ;
2022-10-26 16:49:13 +00:00
} )
] ;
2022-08-06 15:07:57 +00:00
postPatch = ''
2023-09-19 05:30:57 +00:00
patchShebangs dmd/compiler/test / { runnable , fail_compilation , compilable , tools } { , /extra-files } /* . s h
rm dmd/compiler/test/runnable/gdb1.d
rm dmd/compiler/test/runnable/gdb10311.d
rm dmd/compiler/test/runnable/gdb14225.d
rm dmd/compiler/test/runnable/gdb14276.d
rm dmd/compiler/test/runnable/gdb14313.d
rm dmd/compiler/test/runnable/gdb14330.d
rm dmd/compiler/test/runnable/gdb15729.sh
rm dmd/compiler/test/runnable/gdb4149.d
rm dmd/compiler/test/runnable/gdb4181.d
2023-12-11 03:32:23 +00:00
rm dmd/compiler/test/compilable/ddocYear.d
2022-08-06 15:07:57 +00:00
# Disable tests that rely on objdump whitespace until fixed upstream:
# https://issues.dlang.org/show_bug.cgi?id=23317
2023-09-19 05:30:57 +00:00
rm dmd/compiler/test/runnable/cdvecfill.sh
rm dmd/compiler/test/compilable/cdcmp.d
2024-04-02 04:20:38 +00:00
'' + l i b . o p t i o n a l S t r i n g ( l i b . v e r s i o n A t L e a s t v e r s i o n " 2 . 0 8 9 . 0 " & & l i b . v e r s i o n O l d e r v e r s i o n " 2 . 0 9 2 . 2 " ) ''
2023-09-19 05:30:57 +00:00
rm dmd/compiler/test/dshell/test6952.d
2022-08-06 15:07:57 +00:00
'' + l i b . o p t i o n a l S t r i n g ( l i b . v e r s i o n A t L e a s t v e r s i o n " 2 . 0 9 2 . 2 " ) ''
2024-04-02 04:20:38 +00:00
substituteInPlace dmd/compiler/test/dshell/test6952.d - - replace-fail " / u s r / b i n / e n v b a s h " " ${ bash } / b i n / b a s h "
'' + l i b . o p t i o n a l S t r i n g s t d e n v . h o s t P l a t f o r m . i s L i n u x ''
substituteInPlace phobos/std/socket.d - - replace-fail " a s s e r t ( i h . a d d r L i s t [ 0 ] = = 0 x 7 F _ 0 0 _ 0 0 _ 0 1 ) ; " " "
2022-08-06 15:07:57 +00:00
'' + l i b . o p t i o n a l S t r i n g s t d e n v . h o s t P l a t f o r m . i s D a r w i n ''
2024-04-02 04:20:38 +00:00
substituteInPlace phobos/std/socket.d - - replace-fail " f o r e a c h ( n a m e ; n a m e s ) " " n a m e s = [ ] ; f o r e a c h ( n a m e ; n a m e s ) "
2022-08-06 15:07:57 +00:00
'' ;
nativeBuildInputs = [
makeWrapper
which
installShellFiles
] ++ lib . optionals ( lib . versionOlder version " 2 . 0 8 8 . 0 " ) [
git
] ;
buildInputs = [
curl
tzdata
] ++ lib . optionals stdenv . hostPlatform . isDarwin [
Foundation
] ;
2023-01-21 12:00:00 +00:00
nativeCheckInputs = [
2022-08-06 15:07:57 +00:00
gdb
] ++ lib . optionals ( lib . versionOlder version " 2 . 0 8 9 . 0 " ) [
unzip
] ;
buildFlags = [
" B U I L D = r e l e a s e "
" E N A B L E _ R E L E A S E = 1 "
" P I C = 1 "
] ;
# Build and install are based on http://wiki.dlang.org/Building_DMD
buildPhase = ''
runHook preBuild
export buildJobs = $ NIX_BUILD_CORES
2024-04-02 04:20:38 +00:00
[ - z " $ e n a b l e P a r a l l e l B u i l d i n g " ] && buildJobs = 1
2022-08-06 15:07:57 +00:00
2024-04-02 04:46:00 +00:00
$ { dmdBin } /rdmd dmd/compiler/src/build.d - j $ buildJobs $ buildFlags \
HOST_DMD = $ { dmdBin } /dmd
make - C dmd/druntime - j $ buildJobs DMD = $ { pathToDmd } $ buildFlags
2022-08-06 15:07:57 +00:00
echo $ { tzdata } /share/zoneinfo / > TZDatabaseDirFile
2024-04-02 04:46:00 +00:00
echo $ { lib . getLib curl } /lib/libcurl $ { stdenv . hostPlatform . extensions . sharedLibrary } \
> LibcurlPathFile
make - C phobos - j $ buildJobs $ buildFlags \
DMD = $ { pathToDmd } DFLAGS = " - v e r s i o n = T Z D a t a b a s e D i r - v e r s i o n = L i b c u r l P a t h - J $ P W D "
2022-08-06 15:07:57 +00:00
runHook postBuild
'' ;
doCheck = true ;
2024-04-02 04:20:38 +00:00
# many tests are disabled because they are failing
2022-08-06 15:07:57 +00:00
# NOTE: Purity check is disabled for checkPhase because it doesn't fare well
# with the DMD linker. See https://github.com/NixOS/nixpkgs/issues/97420
checkPhase = ''
runHook preCheck
export checkJobs = $ NIX_BUILD_CORES
2024-04-02 04:20:38 +00:00
[ - z " $ e n a b l e P a r a l l e l C h e c k i n g " ] && checkJobs = 1
2022-08-06 15:07:57 +00:00
2024-04-02 04:46:00 +00:00
CC = $ CXX HOST_DMD = $ { pathToDmd } NIX_ENFORCE_PURITY = \
$ { dmdBin } /rdmd dmd/compiler/test/run.d - j $ checkJobs
2022-08-06 15:07:57 +00:00
NIX_ENFORCE_PURITY = \
2024-04-02 04:46:00 +00:00
make - C phobos unittest - j $ checkJobs $ checkFlags \
DFLAGS = " - v e r s i o n = T Z D a t a b a s e D i r - v e r s i o n = L i b c u r l P a t h - J $ P W D "
2022-08-06 15:07:57 +00:00
2023-01-28 08:57:12 +00:00
runHook postCheck
2022-08-06 15:07:57 +00:00
'' ;
installPhase = ''
runHook preInstall
install - Dm755 $ { pathToDmd } $ out/bin/dmd
installManPage dmd/docs/man/man * /*
mkdir - p $ out/include/dmd
2023-10-14 17:13:02 +00:00
cp - r { dmd/druntime/import /* , p h o b o s / { s t d , e t c } } $ o u t / i n c l u d e / d m d /
2022-08-06 15:07:57 +00:00
mkdir $ out/lib
cp phobos/generated / $ { osname } /release / $ { bits } /libphobos2. * $ out/lib /
wrapProgram $ out/bin/dmd \
2024-04-02 04:20:38 +00:00
- - prefix PATH : " ${ targetPackages . stdenv . cc } / b i n " \
2022-08-06 15:07:57 +00:00
- - set-default CC " ${ targetPackages . stdenv . cc } / b i n / c c "
substitute $ { dmdConfFile } " $ o u t / b i n / d m d . c o n f " - - subst-var out
runHook postInstall
'' ;
2021-02-01 07:30:27 +00:00
preFixup = ''
2024-04-02 04:20:38 +00:00
find $ out/bin - type f - exec $ { removeReferencesTo } /bin/remove-references-to - t $ { dmdBin } /dmd ' { } ' +
2021-02-01 07:30:27 +00:00
'' ;
disallowedReferences = [ dmdBootstrap ] ;
2024-06-14 23:29:45 +00:00
passthru = {
inherit dmdBootstrap ;
} ;
2022-08-06 15:07:57 +00:00
meta = with lib ; {
description = " O f f i c i a l r e f e r e n c e c o m p i l e r f o r t h e D l a n g u a g e " ;
homepage = " h t t p s : / / d l a n g . o r g / " ;
2024-07-04 22:08:43 +00:00
changelog = " h t t p s : / / d l a n g . o r g / c h a n g e l o g / ${ finalAttrs . version } . h t m l " ;
2022-08-06 15:07:57 +00:00
# Everything is now Boost licensed, even the backend.
# https://github.com/dlang/dmd/pull/6680
license = licenses . boost ;
2024-04-02 04:20:38 +00:00
mainProgram = " d m d " ;
2024-03-08 19:54:52 +00:00
maintainers = with maintainers ; [ lionello dukc jtbx ] ;
2022-08-06 15:07:57 +00:00
platforms = [ " x 8 6 _ 6 4 - l i n u x " " i 6 8 6 - l i n u x " " x 8 6 _ 6 4 - d a r w i n " ] ;
2024-07-31 19:27:10 +00:00
# ld: section __DATA/__thread_bss has type zero-fill but non-zero file offset file '/private/tmp/nix-build-dmd-2.109.1.drv-0/.rdmd-301/rdmd-build.d-A1CF043A7D87C5E88A58F3C0EF5A0DF7/objs/build.o' for architecture x86_64
# clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
broken = stdenv . hostPlatform . isDarwin && stdenv . hostPlatform . isx86_64 ;
2022-08-06 15:07:57 +00:00
} ;
2024-04-02 04:20:38 +00:00
} )