summaryrefslogtreecommitdiffstats
path: root/pkgs/development/ocaml-modules/llvm/default.nix
blob: ced262a7824c5774373ba3399280cc2f2d2ed064 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
{
  stdenv,
  lib,
  python3,
  cmake,
  libllvm,
  ocaml,
  findlib,
  ctypes,
}:

let
  version = lib.getVersion libllvm;
in

stdenv.mkDerivation {
  pname = "ocaml-llvm";
  inherit version;

  inherit (libllvm) src;

  nativeBuildInputs = [
    cmake
    python3
    ocaml
    findlib
  ];
  buildInputs = [ ctypes ];
  propagatedBuildInputs = [ libllvm ];

  strictDeps = true;

  preConfigure = lib.optionalString (lib.versionAtLeast version "13.0.0") ''
    cd llvm
  '';

  cmakeFlags = [
    "-DBUILD_SHARED_LIBS=YES" # fixes bytecode builds
    "-DLLVM_OCAML_OUT_OF_TREE=TRUE"
    "-DLLVM_OCAML_INSTALL_PATH=${placeholder "out"}/ocaml"
    "-DLLVM_OCAML_EXTERNAL_LLVM_LIBDIR=${lib.getLib libllvm}/lib"
  ];

  buildFlags = [ "ocaml_all" ];

  installFlags = [
    "-C"
    "bindings/ocaml"
  ];

  postInstall = ''
    mkdir -p $OCAMLFIND_DESTDIR/
    mv $out/ocaml $OCAMLFIND_DESTDIR/llvm
    mv $OCAMLFIND_DESTDIR/llvm/META{.llvm,}
    mv $OCAMLFIND_DESTDIR/llvm/stublibs $OCAMLFIND_DESTDIR/stublibs
  '';

  passthru = {
    inherit libllvm;
  };

  meta = {
    inherit (libllvm.meta) license homepage;
    inherit (ocaml.meta) platforms;
    description = "OCaml bindings distributed with LLVM";
    maintainers = with lib.maintainers; [ vbgl ];
  };

}