Tips on building a custom toplevel with Jbuilder and Utop

I have found it relatively easy to follow the Jbuilder and Utop instructions to,
respectively, build developing library and compile byte code for a custom
toplevel. However, I have not been able to figure out how to put these two pats
together! I expect it should be relatively easy to set things up so one can
follow this work flow:

  1. Run jbuilder build @install to recompile both the library and the
    toplevel bitecode file.
  2. Open the Utop toplevel, with the library’s containing module already
    available for use.

I have not been able to find any instructions on how to realize this. Your tips
and advice will be much appreciated, and I’ll do what I can to make what I learn
here available to help out those who have similar difficulties in the future.

Edited to remove unnecessary detail and make the question more approachable
and more generally useful.

1 Like

The instructions on accomplishing this are sketched out fairly clearly in this comment:

It should be simple enough to just follow them by creating an appropriate executable stanza and toplevel module that will initialize the include paths and launch utop.

I won’t expand on this too much as it will be a lot easier to run toplevles for development fairly soon in jbuilder.

1 Like

Thanks for the pointer, @rgrinberg! Your work on this feature should be a big help when it is done.

However, for the time being, it sounds like the real answer to my question is, “You are mistaken. There is no easy and elegant way to achieve this workflow at the moment. You have to either wait for future development, or develop a much deeper understanding of jbuilder and roll your own solution”.

Needless to say, I am a bit disappointed. But I do understand that the OCaml ecosystem is under development and steadily evolving. (I suspect that I switched out solvuu-build for jbuilder too quickly: I was able to achieve this workflow in the former without much hassle. solvuu-build realizes this through .ocamlinit generation rather than via a custom toplevel.)

I have spent about a week puzzling out how to move my project to jbuilder. This has been interesting, and rewarding, but I am eager to make some concrete progress before devoting another week to learning more of the intricacies of the build system.

For a very hacky solution to my current problem, I believe that this ugly command

$ jbuilder clean && cd lib && jbuilder clean && jbuilder build @install && jbuilder install && cd .. && jbuilder build myutop.bc && ./myutop

combined with a #require "mylibrary"" in the project's.ocamlinit`, will serve as a band-aid.

I’ll be watching your PR for the introduction of a better solution, tho!

I wonder if anyone here would be interested or surprised to learn that I am feeling nostalgic for SML/NJ’s Compilation Manager. I think I was able to get going with that substantially quicker than I have with any of the three OCaml build systems I’ve tried out… :thinking:. (Of course, I believe one pays a price in lack of features.)