As mentioned in previous RFCs, we identified painpoints related to the OCaml Platform and they can be summurized as follow:
Previous RFCs have tried to propose solutions that would address all of these problems, but it has proven to be too large of a scope. In this spec, we propose a solution that focuses solely on the last item: easing the Platform installation.
We recently released a version of the VSCode extension that was intended to address the following problems:
We tried to address these by automating the installation of the Platform tools in a separate opam root.
However, user feedback showed some drawbacks in our approach, in particular, the lack of flexibility for experienced users. In this document, we propose a new solution that takes this feedback into account.
Detection mechanism when first starting:
Which version of OCaml do we initialise if one isn't selected? We need the latest version that supports lsp-server. For example 4.12 had a lag and no lsp-server.
The list of OCaml Platform tools is well detailed here, but to be specific, we are considering the following subset to be the typical tools installed in a development environment:
We are intentionnally ommitting Platform tools such as ppxlib
as they are to be installed as a library with Opam, and are less impacted by the problems we are discussing here.
From this list, we classify the tools into different categories
Can be outside of switch | Doesn't depend on project | Doesn't depend on compiler | Can install from binaries | |
---|---|---|---|---|
Opam | ✅ | ✅ | ✅ | ✅ |
Dune | ✅ | ❌ [1] | ✅ | ❌ |
Utop | ✅ | ✅ | ✅ | ❌ |
Merlin | ✅ | ✅ | ❌ | ❌ |
Odoc | ✅ | ✅ | ❌ | ❌ |
Mdx | ✅ | ✅ | ✅ | ❌ |
LSP | ✅ | ✅ | ❌ | ❌ |
OCamlformat | ✅ | ❌ | ❌ [2] | ❌ |
Dune-release | ✅ | ✅ | ✅ | ❌ |
Questions:
With this classification, we can decide how to install each specific tools:
The Platform tools are intended to be used as binaries, and users should not need their sources (with the exception of utop
possibly[3]). So we can cache the compiled binaries and re-use them. If the correct version of the binary can be found, it is copied to the user's opam switch. If not, they are compiled or downloaded and copied thereafter.
Note that the installation should be idempotent: if the current switch is already setup, we don't need to do anything.
This property is important for the tools executation (see below).
There are broadly two kinds of update:
For the former, we will hardcode the versions in the code (because we need to verify the checksums and eventually the signature of the binary). If the version in the code is not the version of the latest installed binary, we download it and copy it in the binary store.
For the later, we first update the opam-repository of the opam switch used for the Platform tools compilation.
Once synched, we detect the project's versions and compare it with the latest versions in the opam-repository. For the set of tools that have a new version in the opam repository, we run the installation flow with the latest version.
If we keep the binaries outside of the switch:
If we copy the binaries in the switch:
Solution: we run make sure the tools are installed every time we execute them.
This worflow will be used by VSCode, but let's illustrate it with some command lines:
An execution of a tool will trigger an installation confirmation if it is not installed, so this fits perfectly with VSCode's workflow.
A possible version for the future:
x-dev-tools is for tools to operate on your code:
What about bisect_ppx? Both a library and a tool.
Future feature: add support for dune workspaces into VSCode extension.
Here we list the different use cases per user.
setup-ocaml
?opam install ocamlformat
The output of the project is a library that encodes the above workflow and use cases with the following properties:
In addition, a CLI that replicates VSCode's features for integration test purposes:
ocaml-platform status
- Describe the state of the Platform tools (version, installed / outdated, etc.)ocaml-platform setup
- Install OCaml Platformocaml-platform <binary>
- Redirect the arguments to the correct binaryWe will provide a NodeJS implementation of this library for use in VSCode and a Unix implementation for use in CI/CD.
Summary of the above spec in a Question-Answer format
Where do we store the binaries?
The binaries are stored in a directory with user access where the path encode information needed for the selection of the binary.
Typically:
~/.cache/ocaml/bin/ocamlformat/ocaml-4.18.0/0.17.0/ocamlformat
We reference this path ~/.cache/ocaml/bin/
as the "Binary store".
How do we install Opam?
Opam binary is downloaded from Github and stored in the binary store as we might not have access to /usr/bin
.
If an Opam installation is already present, we still copy Opam binary in the binary store so we have total control over the environment.
How do we install the platform tools?
Each platform tools has a specific installation flow. But generally, we will:
opam install
in the user switch if the sources are requiredOnce the binaries are in the binary store, they are copied in the user project.
TODO: Write user stories for all of the user workflows we want to support:
Notes on user archetypes: https://docs.google.com/document/d/1tk3VDPja-v25aiNoIXqFSlyjBmE3db1f9k2auq3BcMo/edit?usp=sharing
Dune depends on the user's project but is backward compatible, so it can be considered project-independent if using the latest version ↩︎
OCamlformat can be compiled with the latest version of the compiler ↩︎
The user requires the sources of Utop because dune compiles it when running dune utop
. Not sure if that's something we want to support? The REPL integration in VSCode could load the libraries itself. ↩︎