1{ lib
2, stdenv
3, fetchFromGitHub
4, cmake
5, coreutils
6, libxml2
7, lto ? !stdenv.isDarwin
8, makeWrapper
9, openssl
10, pcre2
11, pony-corral
12, python3
13, substituteAll
14, which
15, z3
16}:
17
18stdenv.mkDerivation (rec {
19 pname = "ponyc";
20 version = "0.54.0";
21
22 src = fetchFromGitHub {
23 owner = "ponylang";
24 repo = pname;
25 rev = version;
26 hash = "sha256-qFPubqGfK0WCun6QA1OveyDJj7Wf6SQpky7pEb7qsf4=";
27 fetchSubmodules = true;
28 };
29
30 ponygbenchmark = fetchFromGitHub {
31 owner = "google";
32 repo = "benchmark";
33 rev = "v1.8.0";
34 hash = "sha256-pUW9YVaujs/y00/SiPqDgK4wvVsaM7QUp/65k0t7Yr0=";
35 };
36
37 nativeBuildInputs = [ cmake makeWrapper which python3 ];
38 buildInputs = [ libxml2 z3 ];
39
40 # Sandbox disallows network access, so disabling problematic networking tests
41 patches = [
42 ./disable-tests.patch
43 (substituteAll {
44 src = ./make-safe-for-sandbox.patch;
45 googletest = fetchFromGitHub {
46 owner = "google";
47 repo = "googletest";
48 # GoogleTest follows Abseil Live at Head philosophy, use latest commit from main branch as often as possible.
49 rev = "1a727c27aa36c602b24bf170a301aec8686b88e8"; # unstable-2023-03-07
50 hash = "sha256-/FWBSxZESwj/QvdNK5BI2EfonT64DP1eGBZR4O8uJww=";
51 };
52 })
53 ];
54
55 postUnpack = ''
56 mkdir -p source/build/build_libs/gbenchmark-prefix/src
57 cp -r "$ponygbenchmark"/ source/build/build_libs/gbenchmark-prefix/src/benchmark
58 chmod -R u+w source/build/build_libs/gbenchmark-prefix/src/benchmark
59 '';
60
61 dontConfigure = true;
62
63 postPatch = ''
64 substituteInPlace packages/process/_test.pony \
65 --replace '"/bin/' '"${coreutils}/bin/' \
66 --replace '=/bin' "${coreutils}/bin"
67 substituteInPlace src/libponyc/pkg/package.c \
68 --replace "/usr/local/lib" "" \
69 --replace "/opt/local/lib" ""
70 '';
71
72 preBuild = ''
73 make libs build_flags=-j$NIX_BUILD_CORES
74 make configure build_flags=-j$NIX_BUILD_CORES
75 '';
76
77 makeFlags = [
78 "PONYC_VERSION=${version}"
79 "prefix=${placeholder "out"}"
80 ] ++ lib.optionals stdenv.isDarwin ([ "bits=64" ] ++ lib.optional (!lto) "lto=no");
81
82 env.NIX_CFLAGS_COMPILE = toString [ "-Wno-error=redundant-move" "-Wno-error=implicit-fallthrough" ];
83
84 doCheck = true;
85
86 installPhase = "make config=release prefix=$out "
87 + lib.optionalString stdenv.isDarwin ("bits=64 " + (lib.optionalString (!lto) "lto=no "))
88 + '' install
89 wrapProgram $out/bin/ponyc \
90 --prefix PATH ":" "${stdenv.cc}/bin" \
91 --set-default CC "$CC" \
92 --prefix PONYPATH : "${lib.makeLibraryPath [ pcre2 openssl (placeholder "out") ]}"
93 '';
94
95 # Stripping breaks linking for ponyc
96 dontStrip = true;
97
98 passthru.tests.pony-corral = pony-corral;
99
100 meta = with lib; {
101 description = "Pony is an Object-oriented, actor-model, capabilities-secure, high performance programming language";
102 homepage = "https://www.ponylang.org";
103 license = licenses.bsd2;
104 maintainers = with maintainers; [ kamilchm patternspandemic redvers ];
105 platforms = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" ];
106 };
107})