1{ stdenv, fetchgit, fetchurl, python2, makeWrapper, pkgconfig, gcc,
2 pypy, libffi, libedit, libuv, boost, zlib,
3 variant ? "jit", buildWithPypy ? false }:
4
5let
6 commit-count = "1364";
7 common-flags = "--thread --gcrootfinder=shadowstack --continuation";
8 variants = {
9 jit = { flags = "--opt=jit"; target = "target.py"; };
10 jit-preload = { flags = "--opt=jit"; target = "target_preload.py"; };
11 no-jit = { flags = ""; target = "target.py"; };
12 no-jit-preload = { flags = ""; target = "target_preload.py"; };
13 };
14 pixie-src = fetchgit {
15 url = "https://github.com/pixie-lang/pixie.git";
16 rev = "5eb0ccbe8b0087d3a5f2d0bbbc6998d624d3cd62";
17 sha256 = "0pf31x5h2m6dpxlidv98qay1y179qw40cw4cb4v4xa88gmq2f3vm";
18 };
19 pypy-tag = "91db1a9";
20 pypy-src = fetchurl {
21 name = "pypy-src-${pypy-tag}";
22 url = "https://bitbucket.org/pypy/pypy/get/${pypy-tag}.tar.bz2";
23 sha256 = "0ylbqvhbcp5m09l15i2q2h3a0vjd055x2r37cq71lkhgmmaxrwbq";
24 };
25 libs = [ libffi libedit libuv boost.dev boost.out zlib ];
26 include-path = stdenv.lib.concatStringsSep ":"
27 (map (p: "${p}/include") libs);
28 library-path = stdenv.lib.concatStringsSep ":"
29 (map (p: "${p}/lib") libs);
30 bin-path = stdenv.lib.concatStringsSep ":"
31 (map (p: "${p}/bin") [ gcc ]);
32 build = {flags, target}: stdenv.mkDerivation rec {
33 name = "pixie-${version}";
34 version = "0-r${commit-count}-${variant}";
35 nativeBuildInputs = [ makeWrapper pkgconfig ];
36 buildInputs = libs;
37 PYTHON = if buildWithPypy
38 then "${pypy}/pypy-c/.pypy-c-wrapped"
39 else "${python2.interpreter}";
40 unpackPhase = ''
41 cp -R ${pixie-src} pixie-src
42 mkdir pypy-src
43 (cd pypy-src
44 tar --strip-components=1 -xjf ${pypy-src})
45 chmod -R +w pypy-src pixie-src
46 '';
47 patchPhase = ''
48 (cd pixie-src
49 patch -p1 < ${./load_paths.patch}
50 libraryPaths='["${libuv}" "${libedit}" "${libffi.dev}" "${boost.dev}" "${boost.out}" "${zlib.dev}"]'
51 export libraryPaths
52 substituteAllInPlace ./pixie/ffi-infer.pxi)
53 '';
54 buildPhase = ''(
55 PYTHONPATH="`pwd`/pypy-src:$PYTHONPATH";
56 RPYTHON="`pwd`/pypy-src/rpython/bin/rpython";
57 cd pixie-src
58 $PYTHON $RPYTHON ${common-flags} ${target}
59 find pixie -name "*.pxi" -exec ./pixie-vm -c {} \;
60 )'';
61 LD_LIBRARY_PATH = library-path;
62 C_INCLUDE_PATH = include-path;
63 LIBRARY_PATH = library-path;
64 PATH = bin-path;
65 installPhase = ''
66 mkdir -p $out/share $out/bin
67 cp pixie-src/pixie-vm $out/share/pixie-vm
68 cp -R pixie-src/pixie $out/share/pixie
69 makeWrapper $out/share/pixie-vm $out/bin/pixie \
70 --prefix LD_LIBRARY_PATH : ${LD_LIBRARY_PATH} \
71 --prefix C_INCLUDE_PATH : ${C_INCLUDE_PATH} \
72 --prefix LIBRARY_PATH : ${LIBRARY_PATH} \
73 --prefix PATH : ${PATH}
74 '';
75 doCheck = true;
76 checkPhase = ''
77 RES=$(./pixie-src/pixie-vm -e "(print :ok)")
78 if [ "$RES" != ":ok" ]; then
79 echo "ERROR Unexpected output: '$RES'"
80 return 1
81 else
82 echo "$RES"
83 fi
84 '';
85 meta = {
86 description = "A clojure-like lisp, built with the pypy vm toolkit";
87 homepage = https://github.com/pixie-lang/pixie;
88 license = stdenv.lib.licenses.lgpl3;
89 platforms = ["x86_64-linux" "i686-linux" "x86_64-darwin"];
90 maintainers = with stdenv.lib.maintainers; [ bendlas ];
91 };
92 };
93in build (builtins.getAttr variant variants)