Merge pull request #119126 from fabaff/pycomfoconnect
[NixPkgs.git] / pkgs / development / compilers / ponyc / default.nix
blob9fc8188daa101adc7d783d174f7356cbbc05f223
1 { lib, stdenv, fetchFromGitHub, fetchurl, makeWrapper, pcre2, coreutils, which, openssl, libxml2, cmake, z3, substituteAll,
2   cc ? stdenv.cc, lto ? !stdenv.isDarwin }:
4 stdenv.mkDerivation (rec {
5   pname = "ponyc";
6   version = "0.38.3";
8   src = fetchFromGitHub {
9     owner = "ponylang";
10     repo = pname;
11     rev = version;
12     sha256 = "14kivmyphi7gbd7mgd4cnsiwl4cl7wih8kwzh7n79s2s4c5hj4ak";
14 # Due to a bug in LLVM 9.x, ponyc has to include its own vendored patched
15 # LLVM.  (The submodule is a specific tag in the LLVM source tree).
17 # The pony developers are currently working to get off 9.x as quickly
18 # as possible so hopefully in a few revisions this package build will
19 # become a lot simpler.
21 # https://reviews.llvm.org/rG9f4f237e29e7150dfcf04ae78fa287d2dc8d48e2
23     fetchSubmodules = true;
24   };
26   ponygbenchmark = fetchurl {
27     url = "https://github.com/google/benchmark/archive/v1.5.0.tar.gz";
28     sha256 = "06i2cr4rj126m1zfz0x1rbxv1mw1l7a11mzal5kqk56cdrdicsiw";
29     name = "v1.5.0.tar.gz";
30   };
32   nativeBuildInputs = [ cmake makeWrapper which ];
33   buildInputs = [ libxml2 z3 ];
34   propagatedBuildInputs = [ cc ];
36   # Sandbox disallows network access, so disabling problematic networking tests
37   patches = [
38     ./disable-tests.patch
39     (substituteAll {
40       src = ./make-safe-for-sandbox.patch;
41       googletest = fetchurl {
42         url = "https://github.com/google/googletest/archive/release-1.8.1.tar.gz";
43         sha256 = "17147961i01fl099ygxjx4asvjanwdd446nwbq9v8156h98zxwcv";
44         name = "release-1.8.1.tar.gz";
45       };
46     })
47   ];
49   postUnpack = ''
50     mkdir -p source/build/build_libs/gbenchmark-prefix/src
51     tar -C source/build/build_libs/gbenchmark-prefix/src -zxvf "$ponygbenchmark"
52     mv source/build/build_libs/gbenchmark-prefix/src/benchmark-1.5.0 \
53        source/build/build_libs/gbenchmark-prefix/src/benchmark
54   '';
56   dontConfigure = true;
58   postPatch = ''
59     # Patching Vendor LLVM
60     patchShebangs --host build/build_libs/gbenchmark-prefix/src/benchmark/tools/*.py
61     patch -d lib/llvm/src/ -p1 < lib/llvm/patches/2020-09-01-is-trivially-copyable.diff
62     patch -d lib/llvm/src/ -p1 < lib/llvm/patches/2020-01-07-01-c-exports.diff
63     patch -d lib/llvm/src/ -p1 < lib/llvm/patches/2019-12-23-01-jit-eh-frames.diff
65     substituteInPlace packages/process/_test.pony \
66         --replace '"/bin/' '"${coreutils}/bin/' \
67         --replace '=/bin' "${coreutils}/bin"
68     substituteInPlace src/libponyc/pkg/package.c \
69         --replace "/usr/local/lib" "" \
70         --replace "/opt/local/lib" ""
71   '';
74   preBuild = ''
75     make libs build_flags=-j$NIX_BUILD_CORES
76     make configure build_flags=-j$NIX_BUILD_CORES
77   '';
79   makeFlags = [
80     "PONYC_VERSION=${version}"
81     "prefix=${placeholder "out"}"
82   ]
83     ++ lib.optionals stdenv.isDarwin [ "bits=64" ]
84     ++ lib.optionals (stdenv.isDarwin && (!lto)) [ "lto=no" ];
86   doCheck = true;
88   NIX_CFLAGS_COMPILE = [ "-Wno-error=redundant-move" "-Wno-error=implicit-fallthrough" ];
90   installPhase = "make config=release prefix=$out "
91     + lib.optionalString stdenv.isDarwin "bits=64 "
92     + lib.optionalString (stdenv.isDarwin && (!lto)) "lto=no "
93     + '' install
95     wrapProgram $out/bin/ponyc \
96       --prefix PATH ":" "${stdenv.cc}/bin" \
97       --set-default CC "$CC" \
98       --prefix PONYPATH : "${lib.makeLibraryPath [ pcre2 openssl (placeholder "out") ]}"
99   '';
101   # Stripping breaks linking for ponyc
102   dontStrip = true;
104   meta = with lib; {
105     description = "Pony is an Object-oriented, actor-model, capabilities-secure, high performance programming language";
106     homepage = "https://www.ponylang.org";
107     license = licenses.bsd2;
108     maintainers = with maintainers; [ kamilchm patternspandemic redvers ];
109     platforms = [ "x86_64-linux" "x86_64-darwin" ];
110   };