Search code examples
ocamlopamutop

Use utop with local ocaml build?


I've compiled a custom version of ocaml 4.04.0 (which someone else wrote). I can run it and interact with it using rlwrap and ledit, but I would rather run it with utop. (I don't need autocompletion; command editing is nicer in utop than in rlwrap or ledit.)

utop clearly depends on opam by default, since it runs whatever version of ocaml has been set up using opam switch. However, I've had difficulty finding any documentation about the relationship between utop and opam, or about how I can get utop to run a version of ocaml that hasn't been set up by opam. man utop, opam --help, and repeated web searches have turned up nothing. Although it seems like a bad idea, I tried simply replacing the file ocaml in .opam/4.04.0/bin with the custom executable, but the extra package that's built in to the executable is not available then, so my guess about what utop is running is clearly wrong. I tried just running utop with the custom ocaml file as an argument: utop ./ocaml. I didn't think this would work, based on the utop man page, and it didn't. The next step seems to be reading the utop source, but as a newcomer to ocaml, I'm reluctant to take that dive, and it seems like it should not be necessary.

How can I run utop with my own ocaml executable?


Solution

  • Utop does not depend on opam: utop is built directly on top of OCaml's compiler library. Consequently, it does not run the standard ocaml toplevel in anyway. If you want to use utop with your custom version of OCaml, you need to build a version of utop using the corresponding custom compiler library.

    The easiest way to do this might be to create your own opam compiler entry, for instance by using opam-compiler-conf, and then switch to this version of the compiler using opam switch.