summaryrefslogtreecommitdiff
path: root/pkgs/development/compilers/haxe/default.nix
blob: f7a7bafc31e84d6b7854e4716a94d3a925b24596 (plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
{
  lib,
  stdenv,
  fetchFromGitHub,
  coreutils,
  ocaml-ng,
  dune,
  zlib,
  pcre2,
  neko,
  mbedtls,
}:
let
  ocamlDependencies =
    version: with ocaml-ng.ocamlPackages; [
      ocaml
      findlib
      sedlex
      xml-light
      ptmap
      camlp5
      sha
      luv
      extlib
    ];

  generic =
    {
      hash,
      version,
    }:
    stdenv.mkDerivation {
      pname = "haxe";
      inherit version;

      buildInputs = [
        zlib
        neko
        dune
        pcre2
        mbedtls
      ]
      ++ ocamlDependencies version;

      src = fetchFromGitHub {
        owner = "HaxeFoundation";
        repo = "haxe";
        rev = version;
        fetchSubmodules = true;
        inherit hash;
      };

      prePatch = ''
        substituteInPlace extra/haxelib_src/src/haxelib/client/Main.hx \
          --replace-fail '"neko"' '"${neko}/bin/neko"'
      '';

      buildFlags = [
        "all"
        "tools"
      ];

      installPhase = ''
        install -vd "$out/bin" "$out/lib/haxe/std"
        cp -vr haxe haxelib std "$out/lib/haxe"

        # make wrappers which provide a temporary HAXELIB_PATH with symlinks to multiple repositories HAXELIB_PATH may point to
        for name in haxe haxelib; do
        cat > $out/bin/$name <<EOF
        #!{bash}/bin/bash

        if [[ "\$HAXELIB_PATH" =~ : ]]; then
          NEW_HAXELIB_PATH="\$(${coreutils}/bin/mktemp -d)"

          IFS=':' read -ra libs <<< "\$HAXELIB_PATH"
          for libdir in "\''${libs[@]}"; do
            for lib in "\$libdir"/*; do
              if [ ! -e "\$NEW_HAXELIB_PATH/\$(${coreutils}/bin/basename "\$lib")" ]; then
                ${coreutils}/bin/ln -s "--target-directory=\$NEW_HAXELIB_PATH" "\$lib"
              fi
            done
          done
          export HAXELIB_PATH="\$NEW_HAXELIB_PATH"
          $out/lib/haxe/$name "\$@"
          rm -rf "\$NEW_HAXELIB_PATH"
        else
          exec $out/lib/haxe/$name "\$@"
        fi
        EOF
        chmod +x $out/bin/$name
        done
      '';

      setupHook = ./setup-hook.sh;

      dontStrip = true;

      # While it might be a good idea to run the upstream test suite, let's at
      # least make sure we can actually run the compiler.
      doInstallCheck = true;
      installCheckPhase = ''
        # Get out of the source directory to make sure the stdlib from the
        # sources doesn't interfere with the installed one.
        mkdir installcheck
        pushd installcheck > /dev/null
        cat >> InstallCheck.hx <<EOF
        class InstallCheck {
          public static function main() trace("test");
        }
        EOF
        "$out/bin/haxe" -js installcheck.js -main InstallCheck
        grep -q 'console\.log.*test' installcheck.js
        popd > /dev/null
      '';

      meta = {
        description = "Programming language targeting JavaScript, Flash, NekoVM, PHP, C++";
        homepage = "https://haxe.org";
        license = with lib.licenses; [
          gpl2Plus
          mit
        ]; # based on upstream opam file
        maintainers = [
          lib.maintainers.locallycompact
          lib.maintainers.logo
          lib.maintainers.bwkam
        ];
        platforms = lib.platforms.linux ++ lib.platforms.darwin;
      };
    };
in
{
  haxe_4_3 = generic {
    version = "4.3.7";
    hash = "sha256-sQb7MCoH2dZOvNmDQ9P0yFYrSXYOMn4FS/jlyjth39Y=";
  };
}