OCaml compiler codebase compilation time

I’m playing around with error message formatting in ocaml/printtyp.ml at trunk · ocaml/ocaml · GitHub , and even a one-line change in this file entails several minutes of recompilation when running the make command. Is the default make target not doing incremental recompilation? Do I need to run some other command for that?

Are you using parallel compilation (make -j)?


If you change one of the files in the compiler, then it may change the output of the compiler so everything that depends on one of the non-bootstrap compilers must be rebuilt.
If you want fast iterations, you can run make core to build just the bytecode compiler. If you need a full build, and you’re confident that you can reuse the previous artifacts, then you can try some make hacks (something like make core && make ocamlopt && make -o ocamlopt might work).

Thanks both for the hints. I’m now using:

$ time make -j 4 ocamlopt.opt

It has dropped the build time from about 2:30 minutes to about 1:15 minutes.

One more question, when I try to use the bytecode-compiled versions of the compiler (ocamlc and ocamlopt), I get an error message:

$ ./ocamlopt
the file './ocamlopt' has not the right magic number: expected Caml1999X029, got Caml1999X032

Is this expected? I found that only ocamlc.opt or ocamlopt.opt work without this error.

Yes. The binaries are meant to be installed; to use them before they’re installed, you need a bit of extra work.
For the native versions, the main thing to watch for is that when they’re not installed, they will fail to look up the standard library files properly. You can work around that by passing some extra flags: -nostdlib -I ./stdlib/
For the bytecode versions, in addition to the above issue you also need to call the right interpreter to use them. So instead of ./ocamlopt it should be ./runtime/ocamlrun ./ocamlopt. Otherwise, it will try to run them using the interpreter in the installation directory, and if there is an old one already there you will get the error message that you saw.
As a special case, if you want to run the toplevel that you just built there is a make runtop rule that will take care of all these details; but there is no equivalent for the other tools (as far as I know).