OCaml with Emacs on Win10

Hello,
I’m a Windows 10 user and I want to code in OCaml with Emacs.
But I have some issues:
I have installed Ubuntu via the Microsoft Store in order to have the WSL.
I followed some tutorial and I am sure that I have the 4.08.1 OCaml build installed, but I can’t upgrade it because I get some error message each time :

I have the latest version of Emacs installed with the Tuareg mode, but I couldn’t evaluate my code.
I’ve been told I didn’t add the directory of ocaml to the path. But what directory do I have to add? I can’t manage to find an “ocaml.exe” or something like that even though I can code with OCaml on Ubuntu. I suspect the fact that I installed binary files for Linux and not for Windows, as it is written on the OCaml installation page for Windows.
I am aware that I could I use some VM shenanigans, but I really don’t want that.

WSL Questions:

  • Are you using WSL version 1? If yes, I suspect this is the main cause of the bwrap error.

Emacs Questions:

Ocaml Questions:

  • Have you run opam init? (Normally, you don’t need to run opam install ocaml, and normally you’d do something along the lines of opam switch create 4.13.1 instead)
  • Have you installed bubblewrap and m4? (Based on the opam output, I suspect that bubblewrap in already installed, but try running sudo apt install bubblewrap m4 if you haven’t).
  • For the 4.08.1 build, what was that installation method?

Try with opam init --disable-sandboxing (if I remember correctly, sandboxing is not supported under WSL).

Cheers,
Nicolas

WSL2 does support the sandbox if you can upgrade. Otherwise if you can’t, I suppose disabling the sandbox for this particular case is fine.

-Yes (checked on the PowerShell)
-Yes (unzipped something that I installed via the Ocaml website)
-No I’m not, I will look into it
-Yes (I get the same error with opam switch create 4.13.1)
-I didn’t thought so but apparently I did.
-And I have no idea, maybe it was something I installed that was needed for somethig else.

That made no difference.

It is “Required setup” for running “opam init” for the fist time.

Could you try with opam init --reinit --disable-sandboxing ? (opam init doesn’t do anything when things are already initialized, see Make opam init easier to use · Issue #4821 · ocaml/opam · GitHub for upstream issue)

Upgrading Ubuntu to WSL 2 will fix the bwrap errors if you don’t want to reinit. Not sure if it’s a supported use case, but I’ve run opam with sandboxing under WSL2. IIRC, you have to run PowerShell with administrative privileges and run wsl --set-version Ubuntu 2.

I tried but it didn’t work at first. Now that I’ve done some more work, I have WSL2.
But opam switch create 4.13.1 stille doesn’t work, as on the screen.

You likely need to install make.

Lol it worked, now I have OCaml 4.13.1

But how can I use it with Emacs now ? I installed it on ubuntu but obviously emacs & won’t open Emacs.