lol
1{ lib, stdenv, fetchFromGitHub, fetchurl, makeWrapper, pcre2, coreutils, which, openssl, libxml2, cmake, z3, substituteAll, python3,
2 cc ? stdenv.cc, lto ? !stdenv.isDarwin }:
3
4stdenv.mkDerivation (rec {
5 pname = "ponyc";
6 version = "0.50.0";
7
8 src = fetchFromGitHub {
9 owner = "ponylang";
10 repo = pname;
11 rev = version;
12 sha256 = "sha256-FnzlFTiJrqoUfnys+q9is6OH9yit5ExDiRszQ679QbY=";
13
14 fetchSubmodules = true;
15 };
16
17 ponygbenchmark = fetchFromGitHub {
18 owner = "google";
19 repo = "benchmark";
20 rev = "v1.5.4";
21 sha256 = "1dbjdjzkpbsq3jl9ksyg8mw759vkac8qzq1557m73ldnavbhz48x";
22 };
23
24 nativeBuildInputs = [ cmake makeWrapper which python3 ];
25 buildInputs = [ libxml2 z3 ];
26
27 # Sandbox disallows network access, so disabling problematic networking tests
28 patches = [
29 ./disable-tests.patch
30 (substituteAll {
31 src = ./make-safe-for-sandbox.patch;
32 googletest = fetchFromGitHub {
33 owner = "google";
34 repo = "googletest";
35 rev = "release-1.10.0";
36 sha256 = "1zbmab9295scgg4z2vclgfgjchfjailjnvzc6f5x9jvlsdi3dpwz";
37 };
38 })
39 ];
40
41 postUnpack = ''
42 mkdir -p source/build/build_libs/gbenchmark-prefix/src
43 cp -r "$ponygbenchmark"/ source/build/build_libs/gbenchmark-prefix/src/benchmark
44 chmod -R u+w source/build/build_libs/gbenchmark-prefix/src/benchmark
45 '';
46
47 dontConfigure = true;
48
49 postPatch = ''
50 # Patching Vendor LLVM
51 patchShebangs --host build/build_libs/gbenchmark-prefix/src/benchmark/tools/*.py
52 patch -d lib/llvm/src/ -p1 < lib/llvm/patches/2020-07-28-01-c-exports.diff
53 substituteInPlace packages/process/_test.pony \
54 --replace '"/bin/' '"${coreutils}/bin/' \
55 --replace '=/bin' "${coreutils}/bin"
56 substituteInPlace src/libponyc/pkg/package.c \
57 --replace "/usr/local/lib" "" \
58 --replace "/opt/local/lib" ""
59 '';
60
61
62 preBuild = ''
63 make libs build_flags=-j$NIX_BUILD_CORES
64 make configure build_flags=-j$NIX_BUILD_CORES
65 '';
66
67 makeFlags = [
68 "PONYC_VERSION=${version}"
69 "prefix=${placeholder "out"}"
70 ]
71 ++ lib.optionals stdenv.isDarwin [ "bits=64" ]
72 ++ lib.optionals (stdenv.isDarwin && (!lto)) [ "lto=no" ];
73
74 doCheck = true;
75
76 NIX_CFLAGS_COMPILE = [ "-Wno-error=redundant-move" "-Wno-error=implicit-fallthrough" ];
77
78 installPhase = "make config=release prefix=$out "
79 + lib.optionalString stdenv.isDarwin "bits=64 "
80 + lib.optionalString (stdenv.isDarwin && (!lto)) "lto=no "
81 + '' install
82 wrapProgram $out/bin/ponyc \
83 --prefix PATH ":" "${stdenv.cc}/bin" \
84 --set-default CC "$CC" \
85 --prefix PONYPATH : "${lib.makeLibraryPath [ pcre2 openssl (placeholder "out") ]}"
86 '';
87
88 # Stripping breaks linking for ponyc
89 dontStrip = true;
90
91 meta = with lib; {
92 description = "Pony is an Object-oriented, actor-model, capabilities-secure, high performance programming language";
93 homepage = "https://www.ponylang.org";
94 license = licenses.bsd2;
95 maintainers = with maintainers; [ kamilchm patternspandemic redvers ];
96 platforms = [ "x86_64-linux" "x86_64-darwin" ];
97 };
98})