melange-re.github.io
melange-re.github.io copied to clipboard
Add a "from scratch" section to the "getting started" page
Currently, the Getting Started docs highlight the [template]( template, which is definitely the easiest way for most people to jump in, but personally I like to set up new projects by hand because I feel like it helps me get more familiar with how the ecosystem's tools fit together. Especially as someone coming from Bucklescript, I'm less familiar with how the opam and dune pieces fit together, and I'd like more hands-on experience getting a project set up with those tools.
Some specific things I'm confused about:
- opam installs dune, then I can use
dune initto create a project... which will likely have its own opam switch? Do I first need to create an opam switch with the version of dune I want to use inside the new project?
...wait, maybe that's the only thing I'm confused about. 😆 I'll keep working through this and let you know if there's anything else that confuses me.
dune init only creates a project layout with files like dune, some ml OCaml modules etc but it does not create a switch. Actually Dune will never do anything related to fetching or downloading anything related to the toolchain or dependencies (this is subject to change after this RFC is implemented). It relies on opam creating a switch previously and downloading the dependencies to have the toolchain available.
So, the first thing to do for a new project is always creating the opam switch. Once that is done you can proceed to install the dependencies for the project, and Dune is most probably the first dependency one wants to install.
Btw if you want to take a stab at the "from scratch" section I encourage you to do so, you are probably one of the best positioned to do so! 🤗
I'm more than happy to take a shot at writing a small "from scratch" section. I think I got a from-scratch setup working yesterday, but before I write things down, I'd love to get feedback on this general outline from people who actually know what they're doing. 😁
- using a global opam switch that has dune 3.8 or greater installed (is this part true?) run
dune initto create your new project - in the new project directory, create an opam switch for the project
- add and install dependencies (especially
melange, optionallyreason, probably some lsp stuff) - configure a
dunefile with somemelange.emitrules, etc, probably lots of linking to other existing docs and examples in the template when we get to this point
The first two steps in particular are the ones that could use some guidance, I think. Like, is it correct that you need a global opam + global dune first, so that you can init the project and then make the project switch?
There's no need to use the global switch, an opam local switch can be installed with opam switch create . 4.14.1 and then opam install dune to get Dune and be able to run dune init.
In other words:
in the new project directory, create an opam switch for the project
This can be the first step.