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.
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.
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.
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.
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.
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 %*