[ANN] Windows-friendly OCaml 4.12 distribution - Diskuv OCaml 0.1.0

I am pleased to announce the first preview release of the Diskuv OCaml (“DKML”) distribution. Parts of the diskuv / diskuv-ocaml README.md are reproduced below:

Diskuv OCaml is an OCaml distribution focused on a) secure, cross-platform software development and b) ease of use for language learners and professional developers.

Documentation is available at https://diskuv.gitlab.io/diskuv-ocaml/

The preview versions 0.1.x run on 64-bit Windows and:

  1. Includes an installer for the initial multi-hour Windows compilation process, including the installation of Git and Visual Studio Build Tools if needed:

    Installation Screenshot

  2. Includes a UNIX-compatible runtime environment for building OCaml applications with common tools like make, opam and dune:

     [PS Z:\source\diskuv-ocaml-starter] cd ~/DiskuvOCamlProjects/diskuv-ocaml-starter
     [PS Z:\source\diskuv-ocaml-starter] ./make build-dev
     [PS Z:\source\diskuv-ocaml-starter] _build/default/bin/main.exe
     > 1
     > 2
     > 3
     > 94.5
     > Total: 100.5
     [PS Z:\source\diskuv-ocaml-starter] ./make shell-dev
    
     [diskuv-ocaml-starter]$ echo You are now running a UNIX shell.
     > You are now running a UNIX shell.
     [diskuv-ocaml-starter]$ opam switch --short
     > C:\Users\you\AppData\Local\Programs\DiskuvOCaml\1\system
     > Z:\source\diskuv-ocaml-starter\build\dev\Debug
     > Z:\source\diskuv-ocaml-starter\build\dev\Release
     > diskuv-boot-DO-NOT-DELETE
     [diskuv-ocaml-starter]$ dune utop
     > ──────────┬─────────────────────────────────────────────────────────────┬──────────
     >           │ Welcome to utop version 2.8.0 (using OCaml version 4.12.0)! │
     >           └─────────────────────────────────────────────────────────────┘
     >
     > Type #utop_help for help about using utop.
     >
     > ─( 06:26:11 )─< command 0 >─────────────────────────────────────────{ counter: 0 }─
    
     utop #> let square x = x * x ;;
     > val square : int -> int = <fun>
     utop #> square 2 ;;
     > - : int = 4
     utop #> square (square 2) ;;
     > - : int = 16
     utop #> #quit ;;
    
  3. Works with the OCaml recommended Visual Studio Code plugin:

    Screenshot of Visual Studio Code

Please visit our documentation at https://diskuv.gitlab.io/diskuv-ocaml/
Twitter Follow

Acknowledgements

The Diskuv OCaml distribution would not be possible without many people’s efforts!

In alphabetical order some of the critical pieces were provided by:

  • Andreas Hauptmann (fdopen@) - Maintained the defacto Windows ports of OCaml for who knows how long
  • INRIA for creating and maintaining OCaml
  • Jane Street and the contributors to dune
  • OCaml Labs and the contributors for the Visual Studio Code extension for OCaml
  • OCamlPro, Jane Street and the contributors to opam
  • Yaron Minsky, Anil Madhavapeddy and Jason Hickey for the book “Real World OCaml”

For OCaml package maintainers two things in particular may be of interest:

  • Instructions for VirtualBox for how to run Windows virtual machines (legally and free!) on Linux and macOS: Windows 10 on macOS/Linux with VirtualBox
  • Using core_kernel.v0.14.2 as a prototypical example, there is a detailed walkthrough and resolution for the common problems you may experience getting your package to build on a native Windows toolchain: MSVC + MSYS2 toolchain

Feedback is appreciated! I’ll post critical bug fixes and important documentation updates in the [ANN] Windows-friendly OCaml 4.12 distribution - Diskuv OCaml 0.1.0 topic thread until the next release (0.1.1 or 0.2.0).

Thanks. Jonah; Founder, Diskuv.

21 Likes

This is amazing work. It’s exactly what I was hoping for. Now we can point to this for anyone who asks about OCaml on Windows.

Good job!
Will I be able to install without admin privileges if the MS compiler toolchain is already installed?

Thanks! Please send them over @yawaramin

No, but … I was trying to be very conservative because Visual Studio comes with hundreds of optional workload and component IDs and a few different release years. It would be very easy for an end-user to spend days trying to figure out what went wrong with a build. But I just stumbled on microsoft/vswhere so I could add a CLI option to point at your specified existing installation (if you are willing to accept the risk of a mismatch) or an option to do a requirements query for the specific components that the Diskuv OCaml distribution needs (which might not find your installation if the version numbers don’t line up exactly). Would either option work for you?

1 Like

A requirements query sounds neat!
In any case, it’s not a dealbreaker. I was just thinking about my work setup which is managed by my org. There, I have several MSVC toolchains installed already, but getting admin rights is always a bit hairy

This is fantastic!

A small plug for msvs-detect which is actually used in opam for the same purpose - it locates all valid Visual Studio installations (checking for the required tools as well)

Oh that looks much simpler, and it is a nice opportunity to harmonize. Thanks! I can send a PR if it needs any tweaking to work with MSYS2.

2 Likes

The 0.2.x release is not yet available but I wanted to give an early heads-up on upcoming breaking changes.

0.2.x Upcoming Breaking Changes

1) (Major) Changed Opam root from $env:USERPROFILE/.opam to $env:LOCALAPPDATA/opam

Why? The new Opam root will be the standard in a future release of Opam. That Opam root should work even if you are on a managed Windows machine (especially corporate/enterprise installations). One of the aims of Diskuv OCaml is to be standards compliant as much as possible, which means less hassle for you if you use another Windows distribution in the future.

Consequences: During the upgrade (instructions will be given in the upcoming 0.2.x announcement) you will be prompted to accept the deletion of the old Opam root and your old Opam switches. If you have adopted the Local Project directory structure (ex. diskuv-ocaml-starter) then ./makeit prepare-dev will recreate the Opam root and your Opam switch correctly based on your .opam files. If you have been creating Opam switches manually (which is not currently recommended because the Diskuv OCaml pinned package versions will be missing) you will use opam install ./xxx.opam --deps-only --with-test to re-install the packages in your new Opam switches.

Thanks to @dra27 for extensively reviewing Opam changes for Windows MSVC+MSYS2!

2) (Minor) Changed make.cmd script to makeit.cmd

Why? If you are an OCaml package maintainer and are creating documentation for your users, it would be nice if you had the same copy-and-paste documentation for both Windows and *nix (Linux/macOS). With this rename your user instructions can be ./makeit build-dev to build your project regardless of whether your users are on Windows or *nix; that syntax works in Powershell where makeit.cmd will be invoked and it works in *nix where the shell script makeit will be invoked. There will be an example of that in diskuv-ocaml-starter in the upcoming announcement.
(An alternative could have been typing ./make but that may be confused with make)

Consequences: You’ll need to rename your make.cmd script.

1 Like

What is the win over using esy here? Esy has solved a lot of these issues on Windows and works very well in my experience.

Not trying to downplay the huge effort here, I’m genuinely curious about the tradeoffs of choosing one tool over the other.

1 Like

@ulrikstrid (Simplification alert) Esy gives access to the Javascript ecosystem. Diskuv OCaml (DKML) gives access to the C ecosystem. C and Javascript are complementary, so in my categories of thought DKML and Esy are complementary as well.

I think the support for Windows is incidental in both DKML and Esy, mostly because both currently depend on fdopen’s MinGW repository for Windows support.

Since DKML is so new, I’ll explain how DKML gives access to the C ecosystem:

  1. Generally it is a bad idea to link GCC-compiled libraries with MSVC-compiled libraries in the same executable. Most of the Windows effort in DKML is getting OCaml packages to compile with MSVC because MSVC is often the only “supported” choice for third-party C libraries on Windows.
  2. The next release of DKML will bundle vcpkg which is currently the most popular C package manager. Vcpkg has packaged 1348 well-maintained, officially supported C libraries that work equally (*) on Windows, Linux and OS/X. There is also community supported platforms like Android and some of the embedded space.
  3. I’ve been getting help from @fdopen / @nojb / @yallop to get a MSVC port of ocaml-ctypes: Library for binding to C libraries using pure OCaml integrated. The combination of vcpkg + ctypes gives an uncomplicated escape hatch for myself and other people who want to base their software on OCaml but also want to be de-risked from the current small size of the OCaml ecosystem.
  4. OCaml already has great support for the C language (ctypes is one example of this), so it is counterproductive for DKML to change standards like Dune and Opam. My last post was an example of the standards adherence you can expect in the future.

In conclusion I’d say that Esy and DKML both provide escape hatches to the bigger Javascript and C ecosystems, and both provide an on-ramp for new users familiar with Javascript and C to come into the OCaml fold. It really boils down to whether your needs revolve around Javascript+OCaml, C+OCaml or pure OCaml.

Hope that helps. Apologies for the verbosity.

(*) Eventually I’d like to see vcpkg treated as an Opam depexts package manager for Windows. Since packages from Debian, homebrew, et cetera are almost always C-based packages, those same packages can usually be found on vcpkg. The benefits should flow to Esy users as well.

5 Likes

Quick question, as Diskuv OCaml is distributed under the Fair Source License, if a teacher were to tell a bunch of students to use it for coursework, would that fall under ‘personal use’ for each of them? Or would they be considered part of an ‘organization’?

2 Likes

Definitely personal use. I’m make sure that is explicit somewhere.

3 Likes

Nice, well done. I’ve wanted that for quite some time, but never managed to look into it. Can’t wait to try it

1 Like

@yawaramin
I made it explicit on the README.md of diskuv / diskuv-ocaml. But I just realized I missed perhaps half of your question; which section do teachers and professors fall under? Those teachers and professors, most of whom are employees of a school, are clearly members of an “organization” that uses DKML and they would not have the personal grant. But it would still be free unless more than 5 teachers were teaching OCaml at the same time in the same school. I think “5” is a reasonable line for now, but your question is clarifying that supporting a single teacher with 50 students is a very different proposition than supporting a single office employee. So thanks for raising the question. And if you know of or have a situation where that line looks unreasonable, just ping me.

1 Like