Building the Llvm tutorial with dune

Hi everyone,
I was trying to go through the LLVM OCaml tutorial here, but I wanted to build it using dune instead of ocamlbuild as is done in the tutorial. The error I’m getting is that there is no implementation for Llvm_analysis:

Error: No implementations provided for the following modules:
         Llvm_analysis referenced from lib/kaleidoscope_lib.cmxa(Kaleidoscope_lib__Codegen)

Any suggestions on how to fix this?

Here is the dune file for my lib:

(library
 (name kaleidoscope_lib)
 (libraries 
   angstrom
   async
   core
   llvm)
 (preprocess (pps ppx_jane ppx_expect ppx_let))
 (inline_tests))

If I delete all the uses of Llvm_analysis, but leave in the uses of Llvm, then everything builds fine.

I can also see the files llvm_analysis.cmi, llvm_analysis.cmx, and lllvm_analysis.mli in ~/.opam/4.06.0/lib/llvm, as well as llvm_analysis.a, llvm_analysis.cma, and llvm_analysis.cmxa in ~/.opam/4.06.0/lib/llvm/shared, so I don’t think anything’s missing.

For reference, this is the build setup from the tutorial (note that I’m using angstrom for my parser instead of camlp4):

_tags:

<{lexer,parser}.ml>: use_camlp4, pp(camlp4of)
<*.{byte,native}>: g++, use_llvm, use_llvm_analysis

myocamlbuild.ml:

(* myocamlbuild.ml *)
open Ocamlbuild_plugin;;

ocaml_lib ~extern:true "llvm";;
ocaml_lib ~extern:true "llvm_analysis";;

flag ["link"; "ocaml"; "g++"] (S[A"-cc"; A"g++"]);; 

What happens if you add llvm_analysis in the list of libraries in the dune file?

It can’t find the library (it’s not an opam package, just a module in the llvm package).

File "lib/dune", line 8, characters 3-16:
8 |    llvm_analysis)
       ^^^^^^^^^^^^^
Error: Library "llvm_analysis" not found.
Hint: try: dune external-lib-deps --missing lib/.utop/utop.exe

I also checked out dune rules which has several references to llvm/shared/llvm.cmxa, but not llvm/shared/llvm_analysis.cmxa.

Could you post the META file for the llvm library? It will be located in $ ocamlfind query llvm. Also, what is the output of $ ocamlfind list | grep -i llvm? It’s strange that llvm_analysis is not found and yet the ocamlbuild build sees it.

Anyway, my guess is that the problem lies in the META file of the llvm package.

1 Like

I believe you use llvm.analysis rather than llvm_analysis in your dune file. I can’t confirm this right now, so apologies if I’m mis-remembering.

1 Like

Continuing the discussion from Building the Llvm tutorial with dune:

ocamlfind query llvm returns ~/.opam/4.06.0/lib/llvm which has no META file:

$ ls -I *.a -I *.mli -I *.cmi -I *.cmx ~/.opam/4.06.0/lib/llvm
opam.config
shared
static

(also note that opam.config is empty).

$ ocamlfind list | grep -i llvm
llvm                (version: 6.0.0)
llvm.all_backends   (version: 6.0.0)
llvm.analysis       (version: 6.0.0)
llvm.bitreader      (version: 6.0.0)
llvm.bitwriter      (version: 6.0.0)
llvm.executionengine (version: 6.0.0)
llvm.ipo            (version: 6.0.0)
llvm.irreader       (version: 6.0.0)
llvm.linker         (version: 6.0.0)
llvm.passmgr_builder (version: 6.0.0)
llvm.scalar_opts    (version: 6.0.0)
llvm.target         (version: 6.0.0)
llvm.transform_utils (version: 6.0.0)
llvm.vectorize      (version: 6.0.0)
llvm_AArch64        (version: 6.0.0)
llvm_AMDGPU         (version: 6.0.0)
llvm_ARM            (version: 6.0.0)
llvm_BPF            (version: 6.0.0)
llvm_Hexagon        (version: 6.0.0)
llvm_Lanai          (version: 6.0.0)
llvm_MSP430         (version: 6.0.0)
llvm_Mips           (version: 6.0.0)
llvm_NVPTX          (version: 6.0.0)
llvm_PowerPC        (version: 6.0.0)
llvm_Sparc          (version: 6.0.0)
llvm_SystemZ        (version: 6.0.0)
llvm_X86            (version: 6.0.0)
llvm_XCore          (version: 6.0.0)

So that lists llvm.analysis as @zshipko mentioned. Also I should mention that I didn’t actually check that the ocamlbuild setup works, so maybe it has the same problem. Thanks for all the suggestions.

1 Like

Yes that worked. Thanks for the help.

BTW, last time I checked llvm used the old META file layout, so its META file was META.llvm in the library directory rather than llvm/META

On a wider note, the LLVM tutorial is based on very old OCaml features. It uses camlp4 for example. It probably should be updated by someone.

Ah yes, META.llvm is in lib directory. In addition to using old OCaml features, the tutorial also seems to be based on outdated LLVM as well.