OCaml for Windows installation confusion

At LexiFi we have been writing OCaml under Windows for a long time and are quite experienced with it. I know of at least one other large industrial player that uses OCaml on Windows as their main environment cc @keleshev.

If I had to summarize the situation of OCaml on Windows I would say that once you get past the installation of the dev environment (C toolchain + Cygwin), the experience is quite similar to Linux. The compiler, standard library, dune and merlin, all work flawlessly on Windows. OPAM is not 100% ready yet on Windows (we don’t use it) but it has never been easier to work “monorepo” style using dune.

For beginners the main stumbling block is setting up the dev environment (C toolchain + Cygwin). On Linux installing a C toolchain is not needed because the compiler is installed by default, but this is not the case on Windows. As for Cygwin, it is strictly speaking only necessary when building the compiler itself. Once the compiler is installed you are free to never use Cygwin again…

So if you want a Rust-style experience for beginners you need to figure out how to provide a point-and-click installer that does the following things:

  1. installs the C toolchain,
  2. installs Cygwin and builds & installs the OCaml compiler using it
  3. installs dune and merlin

At this point you will be left with a very capable environment for writing OCaml programs using common editors such as VS Code.

Regarding 1. above (the C toolchain), there are two main options. If you want a completely freestanding C toolchain you must use the native MSVC compiler command-line tools, which you can get from https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line

If you are willing to use Cygwin for your day-to-day developing (as opposed to only using it when building the compiler), then you have a second option which is to use the mingw64 compiler. This compiler also produces native Windows binaries, but the advantage is that it is essentially gcc so you get an user experience which you may be used to from Linux. As it runs under Cygwin, this option may appeal to those that prefer to insulate themselves as much as possible from Windows specificities.

It depends what you mean by “on Windows”. If all you want is to develop “on” a Windows machine, yes by all means WSL is a good option. But the binaries you produce are Linux binaries, so they won’t run on Windows outside of the WSL environment.

Only if you insist on using OPAM for your development. It is perfectly feasible to develop on Windows “monorepo” style without using OPAM. The experience may not be as pleasent as it would be on Linux and depending on how much you rely on external libraries it may be more or less convenient, but it works quite well in general.

Cheers,
Nicolas

8 Likes