|
| 1 | +How to Use Opam Alongside Dune Package Management |
| 2 | +================================================== |
| 3 | + |
| 4 | +This guide will show you a workflow for gradually adopting Dune Package |
| 5 | +Management, while retaining the use of an Opam switch as the default way of |
| 6 | +resolving dependencies of a project. It assumes you have a project with |
| 7 | +dependencies, and are managing those dependencies with an Opam switch. |
| 8 | +By the end of this guide you'll have enabled Dune Package Management for your |
| 9 | +project, however by default Dune will still use an Opam switch to resolve your |
| 10 | +project's dependencies. By setting an environment variable you'll be able to |
| 11 | +toggle between an Opam-based workflow and a purely Dune-based workflow. |
| 12 | + |
| 13 | +Create a file named ``dune-workspace`` at the root of your project, with the following |
| 14 | +contents: |
| 15 | + |
| 16 | +.. code:: scheme |
| 17 | +
|
| 18 | + (lang dune 3.20) |
| 19 | +
|
| 20 | + (pkg disabled) |
| 21 | +
|
| 22 | +Since ``dune-workspace`` is the default workspace file, this tells Dune that by |
| 23 | +default, don't use its internal package management mechanism to resolve the |
| 24 | +project's dependencies, even in the presence of a lockdir. |
| 25 | + |
| 26 | +Now create a second file in the project root named ``dune-workspace.pkg``. The |
| 27 | +name of this file isn't important, but conventionally alternative workspace |
| 28 | +files begin with the ``dune-workspace.`` prefix. Add the following to this new |
| 29 | +file: |
| 30 | + |
| 31 | +.. code:: scheme |
| 32 | +
|
| 33 | + (lang dune 3.20) |
| 34 | +
|
| 35 | + (pkg enabled) |
| 36 | +
|
| 37 | +With these two files in place, by default Dune will use the specified Opam |
| 38 | +switch to resolve your project's dependencies. However, setting the environment |
| 39 | +variable ``DUNE_WORKSPACE=dune-workspace.pkg`` will cause Dune to use |
| 40 | +its internal package management mechanism to resolve dependencies instead. Unset |
| 41 | +the ``DUNE_WORKSPACE`` environment variable to return to an Opam-based workflow. |
0 commit comments