Merge pull request #119126 from fabaff/pycomfoconnect
[NixPkgs.git] / pkgs / development / compilers / haxe / default.nix
blob73b82ff48dbfb10568a18b3757eb3d197342c9be
1 { lib, stdenv, fetchFromGitHub, coreutils, ocaml-ng, zlib, pcre, neko, mbedtls }:
3 let
4   ocamlDependencies = version:
5     if lib.versionAtLeast version "4.0"
6     then with ocaml-ng.ocamlPackages; [
7       ocaml
8       findlib
9       sedlex_2
10       xml-light
11       ptmap
12       camlp5
13       sha
14       dune_2
15       luv
16       ocaml_extlib
17     ] else with ocaml-ng.ocamlPackages_4_05; [
18       ocaml
19       camlp4
20     ];
22   defaultPatch = ''
23     substituteInPlace extra/haxelib_src/src/haxelib/client/Main.hx \
24       --replace '"neko"' '"${neko}/bin/neko"'
25   '';
27   generic = { sha256, version, prePatch ? defaultPatch }:
28     stdenv.mkDerivation {
29       pname = "haxe";
30       inherit version;
32       buildInputs = [ zlib pcre neko ]
33         ++ lib.optional (lib.versionAtLeast version "4.1") [ mbedtls ]
34         ++ ocamlDependencies version;
36       src = fetchFromGitHub {
37         owner = "HaxeFoundation";
38         repo = "haxe";
39         rev = version;
40         fetchSubmodules = true;
41         inherit sha256;
42       };
44       inherit prePatch;
46       buildFlags = [ "all" "tools" ];
48       installPhase = ''
49         install -vd "$out/bin" "$out/lib/haxe/std"
50         cp -vr haxe haxelib std "$out/lib/haxe"
52         # make wrappers which provide a temporary HAXELIB_PATH with symlinks to multiple repositories HAXELIB_PATH may point to
53         for name in haxe haxelib; do
54         cat > $out/bin/$name <<EOF
55         #!{bash}/bin/bash
57         if [[ "\$HAXELIB_PATH" =~ : ]]; then
58           NEW_HAXELIB_PATH="\$(${coreutils}/bin/mktemp -d)"
60           IFS=':' read -ra libs <<< "\$HAXELIB_PATH"
61           for libdir in "\''${libs[@]}"; do
62             for lib in "\$libdir"/*; do
63               if [ ! -e "\$NEW_HAXELIB_PATH/\$(${coreutils}/bin/basename "\$lib")" ]; then
64                 ${coreutils}/bin/ln -s "--target-directory=\$NEW_HAXELIB_PATH" "\$lib"
65               fi
66             done
67           done
68           export HAXELIB_PATH="\$NEW_HAXELIB_PATH"
69           $out/lib/haxe/$name "\$@"
70           rm -rf "\$NEW_HAXELIB_PATH"
71         else
72           exec $out/lib/haxe/$name "\$@"
73         fi
74         EOF
75         chmod +x $out/bin/$name
76         done
77       '';
79       setupHook = ./setup-hook.sh;
81       dontStrip = true;
83       # While it might be a good idea to run the upstream test suite, let's at
84       # least make sure we can actually run the compiler.
85       doInstallCheck = true;
86       installCheckPhase = ''
87         # Get out of the source directory to make sure the stdlib from the
88         # sources doesn't interfere with the installed one.
89         mkdir installcheck
90         pushd installcheck > /dev/null
91         cat >> InstallCheck.hx <<EOF
92         class InstallCheck {
93           public static function main() trace("test");
94         }
95         EOF
96         "$out/bin/haxe" -js installcheck.js -main InstallCheck
97         grep -q 'console\.log.*test' installcheck.js
98         popd > /dev/null
99       '';
101       meta = with lib; {
102         description = "Programming language targeting JavaScript, Flash, NekoVM, PHP, C++";
103         homepage = "https://haxe.org";
104         license = with licenses; [ gpl2Plus mit ]; # based on upstream opam file
105         maintainers = [ maintainers.marcweber maintainers.locallycompact ];
106         platforms = platforms.linux ++ platforms.darwin;
107       };
108     };
109 in {
110   # this old version is required to compile some libraries
111   haxe_3_2 = generic {
112     version = "3.2.1";
113     sha256 = "1x9ay5a2llq46fww3k07jxx8h1vfpyxb522snc6702a050ki5vz3";
114     prePatch = ''
115       sed -i -e 's|"/usr/lib/haxe/std/";|"'"$out/lib/haxe/std/"'";\n&|g' main.ml
116       substituteInPlace extra/haxelib_src/src/tools/haxelib/Main.hx \
117         --replace '"neko"' '"${neko}/bin/neko"'
118     '';
119   };
120   haxe_3_4 = generic {
121     version = "3.4.6";
122     sha256 = "1myc4b8fwp0f9vky17wv45n34a583f5sjvajsc93f5gm1wanp4if";
123     prePatch = ''
124       ${defaultPatch}
125       sed -i -re 's!(let +prefix_path += +).*( +in)!\1"'"$out/"'"\2!' src/main.ml
126     '';
127   };
128   haxe_4_2 = generic {
129     version = "4.2.1";
130     sha256 = "sha256-0j6M21dh8DB1gC/bPYNJrVuDbJyqQbP+61ItO5RBUcA=";
131   };