1{ stdenv, fetchFromGitHub, llvm, makeWrapper, pcre2, coreutils, which, libressl,
2 cc ? stdenv.cc, lto ? !stdenv.isDarwin }:
3
4stdenv.mkDerivation ( rec {
5 name = "ponyc-${version}";
6 version = "0.21.3";
7
8 src = fetchFromGitHub {
9 owner = "ponylang";
10 repo = "ponyc";
11 rev = version;
12 sha256 = "0cdp6wbpirl3jnlqkm0hbxyz67v00nwhi4hvk4sq2g74f36j2bnm";
13 };
14
15 buildInputs = [ llvm makeWrapper which ];
16 propagatedBuildInputs = [ cc ];
17
18 # Disable problematic networking tests
19 patches = [ ./disable-tests.patch ];
20
21 preBuild = ''
22 # Fix tests
23 substituteInPlace packages/process/_test.pony \
24 --replace '"/bin/' '"${coreutils}/bin/'
25 substituteInPlace packages/process/_test.pony \
26 --replace '=/bin' "${coreutils}/bin"
27
28
29 # Fix llvm-ar check for darwin
30 substituteInPlace Makefile \
31 --replace "llvm-ar-3.8" "llvm-ar"
32
33 # Remove impure system refs
34 substituteInPlace src/libponyc/pkg/package.c \
35 --replace "/usr/local/lib" ""
36 substituteInPlace src/libponyc/pkg/package.c \
37 --replace "/opt/local/lib" ""
38
39 for file in `grep -irl '/usr/local/opt/libressl/lib' ./*`; do
40 substituteInPlace $file --replace '/usr/local/opt/libressl/lib' "${stdenv.lib.getLib libressl}/lib"
41 done
42
43 # Fix ponypath issue
44 substituteInPlace Makefile \
45 --replace "PONYPATH=." "PONYPATH=.:\$(PONYPATH)"
46
47 export LLVM_CONFIG=${llvm}/bin/llvm-config
48 '' + stdenv.lib.optionalString ((!stdenv.isDarwin) && (!cc.isClang) && lto) ''
49 export LTO_PLUGIN=`find ${cc.cc}/ -name liblto_plugin.so`
50 '' + stdenv.lib.optionalString ((!stdenv.isDarwin) && (cc.isClang) && lto) ''
51 export LTO_PLUGIN=`find ${cc.cc}/ -name LLVMgold.so`
52 '';
53
54 makeFlags = [ "config=release" ] ++ stdenv.lib.optionals stdenv.isDarwin [ "bits=64" ]
55 ++ stdenv.lib.optionals (stdenv.isDarwin && (!lto)) [ "lto=no" ];
56
57 enableParallelBuilding = true;
58
59 doCheck = true;
60
61 checkTarget = "test-ci";
62
63 preCheck = ''
64 export PONYPATH="$out/lib:${stdenv.lib.makeLibraryPath [ pcre2 libressl ]}"
65 '';
66
67 installPhase = ''
68 make config=release prefix=$out ''
69 + stdenv.lib.optionalString stdenv.isDarwin '' bits=64 ''
70 + stdenv.lib.optionalString (stdenv.isDarwin && (!lto)) '' lto=no ''
71 + '' install
72
73 wrapProgram $out/bin/ponyc \
74 --prefix PATH ":" "${stdenv.cc}/bin" \
75 --set-default CC "$CC" \
76 --prefix PONYPATH : "$out/lib" \
77 --prefix PONYPATH : "${stdenv.lib.getLib pcre2}/lib" \
78 --prefix PONYPATH : "${stdenv.lib.getLib libressl}/lib"
79 '';
80
81 # Stripping breaks linking for ponyc
82 dontStrip = true;
83
84 meta = with stdenv.lib; {
85 description = "Pony is an Object-oriented, actor-model, capabilities-secure, high performance programming language";
86 homepage = http://www.ponylang.org;
87 license = licenses.bsd2;
88 maintainers = with maintainers; [ doublec kamilchm patternspandemic ];
89 platforms = [ "x86_64-linux" "x86_64-darwin" ];
90 };
91})