summary refs log tree commit diff
path: root/pkgs/development/tools/dtools/default.nix
blob: 28d0c57f2e3bb44bea5a78a2b2c43c304adad46d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
{stdenv, lib, fetchFromGitHub, dmd, curl}:

stdenv.mkDerivation rec {
  name = "dtools-${version}";
  version = "2.075.1";

  src = fetchFromGitHub {
    owner = "dlang";
    repo = "tools";
    rev = "v${version}";
    sha256 = "0lxn400s9las9hq6h9vj4mis2jr662k2yw0zcrvqcm1yg9pd245d";
  };

  postPatch = ''
      substituteInPlace posix.mak \
          --replace "../dmd/generated/\$(OS)/release/\$(MODEL)/dmd" ${dmd.out}/bin/dmd

      substituteInPlace posix.mak \
          --replace gcc $CC
  '';

  nativeBuildInputs = [ dmd ];
  buildInputs = [ curl ];

  buildPhase = ''
    make -f posix.mak DMD=${dmd.out}/bin/dmd INSTALL_DIR=$out
  '';

  doCheck = true;

  checkPhase = ''
      export BITS=${builtins.toString stdenv.hostPlatform.parsed.cpu.bits}
      export OSNAME=${if stdenv.hostPlatform.isDarwin then "osx" else stdenv.hostPlatform.parsed.kernel.name}
      ./generated/$OSNAME/$BITS/rdmd -main -unittest rdmd.d
      ${dmd.out}/bin/dmd rdmd_test.d
      ./rdmd_test
    '';

  installPhase = ''
    mkdir -p $out/bin
    ${
      let bits = builtins.toString stdenv.hostPlatform.parsed.cpu.bits;
      osname = if stdenv.hostPlatform.isDarwin then "osx" else stdenv.hostPlatform.parsed.kernel.name; in
      "find $PWD/generated/${osname}/${bits} -perm /a+x -type f -exec cp {} $out/bin \\;"
    }
	'';

  meta = {
    description = "Ancillary tools for the D programming language compiler";
    homepage = https://github.com/dlang/tools;
    license = lib.licenses.boost;
    platforms = stdenv.lib.platforms.unix;
  };
}