Precompiling OCaml for Windows

Alas, I will need the OCaml compiler on an array of Windows machines. The installation procedure with Diskuv is very long and I am not even sure I would have the sufficient authorisations to run it on said computers.

However, I do not actually need the opam, dune, etc. machinery : just the ocaml REPL and ocamlc.

Is this a good (or at least not disastrous) and feasible idea to install OCaml via Diskuv on one machine, and then drop the compiled compiler and its libs to that array of machines, like a “portable” application ?

In principle, that approach would probably work as long as you used the exact same paths on all machines. Additionally, you would need to add DiskuvOCamlHome and DiskuvOCamlVersion to the environment variables, in addition to two directories prefixed to the PATH environment variables.

But I see two problems that you’d have to overcome:

  • how would you have the exact same paths if you don’t have authorizations on other machines? Usually that is difficult without Administrator rights on Windows. Hopefully you have a shared drive that others can access.
  • the tricky thing is actually Visual Studio. I don’t think you can just copy that. And you need Admin to install it. (Also, that has licenses around redistribution you have to respect). You should try that first to make sure it works.

Easier way: Just run winget install Diskuv.OCaml on the remote PCs. And assuming there is a Windows domain, you can do that across a fleet.

Why do I need Visual Studio ?

DKML uses Visual Studio. That is explained in GitHub - diskuv/dkml-installer-ocaml: The Windows-friendly distribution of OCaml (first paragraph), with alternatives if that is not your cup of tea.

You may want to have a look at the README.win32.adoc file in the source distribution, e.g. this table indicates what you need depending on what you want.

From that page,

The native-code compiler (ocamlopt ) and static linking of OCaml bytecode with C code (ocamlc -custom ) require a Microsoft Visual C/C++ Compiler and the flexlink tool (see above).

But @ysalmon you mentioned you need only ocaml (REPL) and ocamlc (bytecode compiler)? If that’s really all you need, then you might not actually need MSVC++


@yawaramin is right; totally missed that you are only talking about the bytecode. (@dbuenzli 's link has good info, even if it looks terribly outdated.) If you stick to copying that it should work without Visual Studio.

And file a ticket at Issues · diskuv/dkml-installer-ocaml · GitHub. For example, Release 4.14.0-v1.1.0-prerel1 · diskuv/dkml-component-ocamlrun · GitHub has downloadable ocamlrun.exe and the standard library. I think you are just asking for that + ocaml.exe + ocamlc.exe, probably in .zip format for normal Windows use. If you can say how that will be sufficient for you in the ticket, that will be helpful in deciding if a “light” version is warranted.

Edit: And you’ll need to set environment variables with that approach. OCAMLLIB to <dir>\lib\ocaml and add the <dir>\lib\ocaml\stublibs to your PATH.

3 Likes

Thank you so much everybody !

I was aware Visual Studio was used by DKML to compile the OCaml compiler ; I was not aware the resulting ocaml.exe and ocamlc.exe would also need it to run.

The context is a light course where we use OCaml for an introduction to functional programming : our lab sessions will consist in programming some functions in eg. Emacs+Tuareg and testing them on some test examples ; students will never produce a full program and never compile it (the notion of a compiler is already above the scope of the course). Come to think about it, I do not even need a ocamlc.exe : if I need to give some .cmo files to my students, I can prepare them on my machine, where I have OPAM.

The technical context is :

  • in the lab, I have write access to some shared drive but not administrative access to the machines, so I plan to drop an OCaml compiler and a well-configured Emacs+Tuareg somewhere (I think I can eschew setting PATH by configuring Tuareg to run ocaml with the appropriate -I parameters) ;
  • it is also a good thing if students can get things running on their own machine by unzipping a file rather than several steps of installation/compilation (despite taking this course, they are principally math students and not always tech savvy at all
).

I see that OCaml for Windows - Installation, while being announced as discontinued since Aug 2021, still allows to get a 4.14.0 compiler, which is entirely sufficient (and so much better than the 4.0.1 which is currently available at our lab).

Which one can run from Windows by saying C:\OCaml64\usr\local\bin\ocaml-env.exe exec ocaml and it seems to find its stdlib.

1 Like

Vous ĂȘtes professeur Ă  Rennes semble-t-il (dĂ©solĂ© si c’est incorrect 
)

Connaissez-vous la Page web de Jean Mouric ?
Il serait professeur de mathématiques à Rennes et propose depuis de nombreuses années
des distributions binaires OCaml pour Windows 10 ou 11 x64, GNU/Linux et MacOS.

Et ces distributions vont de caml-light (si,si, j’ai essayĂ©, ça marche) jusqu’à la derniĂšre version OCaml 5.0.0 (sortie il y a 15 jours,pas encore essayé ) La version 4.14.0 est OK.
Il y a un travail hallucinant sur ce site (pas toujours Ă©vident Ă  suivre mais bon !).

Rem:
Ce programme (WinCaml) est utilisé en classe de MP2I au lycée Clémenceau, Nantes (2022-2023)
pour l’enseignement d’OCaml.

Vive la Bretagne :black_flag:󠁊ó Č󠁹ó Č󠁄󠁿

1 Like

The https://jean-mouric.pagesperso-orange.fr/archives/ocamlmgw64-win10-4140.zip works well as long as you unzip it directly in your C:\ drive root directory. And it looks well maintained. It has graphics and zarith bundled as well. Seems like a great option for your use case!

1 Like

Oui, je connais, et le travail de Jean Mouric est ce qui nous a permis de survivre jusqu’à aujourd’hui ! Mais les distrib qu’il publie ont le dĂ©faut de ne fonctionner que si on les installe sous C:\. Et moi c’est dans K:\ que je peux Ă©crire.

Anyway, I think I got a working recipe :

  • on a Windows machine with sufficient privileges (in my case a VM),
  • use OCaml for Windows - Installation or the manual installation instruction there to get a Cygwin with a working opam (note that using the installer to install elsewhere than the default path caused an error pertaining to curl not being available
)
  • mount a network share to the path that will be accessible live
  • in cygwin, create an opam switch for the desired compiler in the path of the network share
  • in that switch, install the required compiler and maybe modules (in my case, I installed utop)

Since setting PATH correctly on the machines may or may not be an option, create .bat files. In my case, I have a utop.bat with the following

@echo off
set CAML_LD_LIBRARY_PATH=K:\Applications_INFO\OCaml\win10\_opam\lib\stublibs;K:\Applications_INFO\OCaml\win10\_opam\lib\ocaml\stublibs;K:\Applications_INFO\OCaml\win10\_opam\lib\ocaml
set OCAMLLIB=K:\Applications_INFO\OCaml\win10\_opam\lib\ocaml
set OCAML_TOPLEVEL_PATH=K:\Applications_INFO\OCaml\win10\_opam\lib\toplevel

K:\Applications_INFO\OCaml\win10\_opam\bin\utop.exe %*

Now I am off configuring Emacs


1 Like

For the record, there is a “for-teachers” channel in the OCaml discord (OCaml). You might also find some help there.