1{ stdenv, lib, python3, cmake, libllvm, ocaml, findlib, ctypes }:
2
3let version = lib.getVersion libllvm; in
4
5stdenv.mkDerivation {
6 pname = "ocaml-llvm";
7 inherit version;
8
9 inherit (libllvm) src;
10
11 nativeBuildInputs = [ cmake python3 ocaml findlib ];
12 buildInputs = [ ctypes ];
13 propagatedBuildInputs = [ libllvm ];
14
15 strictDeps = true;
16
17 preConfigure = lib.optionalString (lib.versionAtLeast version "13.0.0") ''
18 cd llvm
19 '';
20
21 cmakeFlags = [
22 "-DBUILD_SHARED_LIBS=YES" # fixes bytecode builds
23 "-DLLVM_OCAML_OUT_OF_TREE=TRUE"
24 "-DLLVM_OCAML_INSTALL_PATH=${placeholder "out"}/ocaml"
25 "-DLLVM_OCAML_EXTERNAL_LLVM_LIBDIR=${lib.getLib libllvm}/lib"
26 ];
27
28 buildFlags = [ "ocaml_all" ];
29
30 installFlags = [ "-C" "bindings/ocaml" ];
31
32 postInstall = ''
33 mkdir -p $OCAMLFIND_DESTDIR/
34 mv $out/ocaml $OCAMLFIND_DESTDIR/llvm
35 mv $OCAMLFIND_DESTDIR/llvm/META{.llvm,}
36 mv $OCAMLFIND_DESTDIR/llvm/stublibs $OCAMLFIND_DESTDIR/stublibs
37 '';
38
39 passthru = {
40 inherit libllvm;
41 };
42
43 meta = {
44 inherit (libllvm.meta) license homepage;
45 inherit (ocaml.meta) platforms;
46 description = "OCaml bindings distributed with LLVM";
47 maintainers = with lib.maintainers; [ vbgl ];
48 };
49
50}