1{
2 lib,
3 stdenv,
4 fetchurl,
5 curl,
6 tzdata,
7 autoPatchelfHook,
8 fixDarwinDylibNames,
9 glibc,
10 version,
11 hashes,
12}:
13
14let
15 inherit (stdenv) hostPlatform;
16 OS = if hostPlatform.isDarwin then "osx" else hostPlatform.parsed.kernel.name;
17 MODEL = toString hostPlatform.parsed.cpu.bits;
18in
19
20# On linux pargets like `pkgsLLVM.dmd` `cc` does not expose `libgcc`
21# and can't build `dmd`.
22assert hostPlatform.isLinux -> (stdenv.cc.cc ? libgcc);
23stdenv.mkDerivation {
24 pname = "dmd-bootstrap";
25 inherit version;
26
27 src = fetchurl rec {
28 name = "dmd.${version}.${OS}.tar.xz";
29 url = "http://downloads.dlang.org/releases/2.x/${version}/${name}";
30 sha256 = hashes.${OS} or (throw "missing bootstrap sha256 for OS ${OS}");
31 };
32
33 dontConfigure = true;
34 dontBuild = true;
35
36 nativeBuildInputs =
37 lib.optionals hostPlatform.isLinux [
38 autoPatchelfHook
39 ]
40 ++ lib.optionals hostPlatform.isDarwin [
41 fixDarwinDylibNames
42 ];
43 propagatedBuildInputs = [
44 curl
45 tzdata
46 ]
47 ++ lib.optionals hostPlatform.isLinux [
48 glibc
49 stdenv.cc.cc.libgcc
50 ];
51
52 installPhase = ''
53 runHook preInstall
54
55 mkdir -p $out
56
57 # try to copy model-specific binaries into bin first
58 mv ${OS}/bin${MODEL} $out/bin || true
59
60 mv src license.txt ${OS}/* $out/
61
62 # move man into place
63 mkdir -p $out/share
64 mv man $out/share/
65
66 # move docs into place
67 mkdir -p $out/share/doc
68 mv html/d $out/share/doc/
69
70 # fix paths in dmd.conf (one level less)
71 substituteInPlace $out/bin/dmd.conf --replace "/../../" "/../"
72
73 runHook postInstall
74 '';
75
76 # Stripping on Darwin started to break libphobos2.a
77 # Undefined symbols for architecture x86_64:
78 # "_rt_envvars_enabled", referenced from:
79 # __D2rt6config16rt_envvarsOptionFNbNiAyaMDFNbNiQkZQnZQq in libphobos2.a(config_99a_6c3.o)
80 dontStrip = hostPlatform.isDarwin;
81
82 meta = with lib; {
83 description = "Digital Mars D Compiler Package";
84 # As of 2.075 all sources and binaries use the boost license
85 license = licenses.boost;
86 maintainers = [ maintainers.lionello ];
87 homepage = "https://dlang.org/";
88 platforms = [
89 "x86_64-darwin"
90 "i686-linux"
91 "x86_64-linux"
92 ];
93 };
94}