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