1 { lib, stdenv, fetchFromGitHub, coreutils, ocaml-ng, zlib, pcre, neko, mbedtls }:
4 ocamlDependencies = version:
5 if lib.versionAtLeast version "4.0"
6 then with ocaml-ng.ocamlPackages; [
17 ] else with ocaml-ng.ocamlPackages_4_05; [
23 substituteInPlace extra/haxelib_src/src/haxelib/client/Main.hx \
24 --replace '"neko"' '"${neko}/bin/neko"'
27 generic = { sha256, version, prePatch ? defaultPatch }:
32 buildInputs = [ zlib pcre neko ]
33 ++ lib.optional (lib.versionAtLeast version "4.1") [ mbedtls ]
34 ++ ocamlDependencies version;
36 src = fetchFromGitHub {
37 owner = "HaxeFoundation";
40 fetchSubmodules = true;
46 buildFlags = [ "all" "tools" ];
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
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"
68 export HAXELIB_PATH="\$NEW_HAXELIB_PATH"
69 $out/lib/haxe/$name "\$@"
70 rm -rf "\$NEW_HAXELIB_PATH"
72 exec $out/lib/haxe/$name "\$@"
75 chmod +x $out/bin/$name
79 setupHook = ./setup-hook.sh;
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.
90 pushd installcheck > /dev/null
91 cat >> InstallCheck.hx <<EOF
93 public static function main() trace("test");
96 "$out/bin/haxe" -js installcheck.js -main InstallCheck
97 grep -q 'console\.log.*test' installcheck.js
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;
110 # this old version is required to compile some libraries
113 sha256 = "1x9ay5a2llq46fww3k07jxx8h1vfpyxb522snc6702a050ki5vz3";
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"'
122 sha256 = "1myc4b8fwp0f9vky17wv45n34a583f5sjvajsc93f5gm1wanp4if";
125 sed -i -re 's!(let +prefix_path += +).*( +in)!\1"'"$out/"'"\2!' src/main.ml
130 sha256 = "sha256-0j6M21dh8DB1gC/bPYNJrVuDbJyqQbP+61ItO5RBUcA=";