Skip to content

Commit e907bcb

Browse files
committed
Doc page about using opam by default with dune pkg
Signed-off-by: Stephen Sherratt <[email protected]>
1 parent d8b90bb commit e907bcb

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

doc/howto/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ These guides will help you use Dune's features in your project.
2424
rule-generation
2525
override-default-entrypoint
2626
release-binaries-with-github-action
27+
use-opam-alongside-dune-package-management
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 or passing an extra
11+
argument to commands like ``dune build`` you'll be able to toggle between an
12+
Opam-based workflow and a purely Dune-based workflow.
13+
14+
Create a file named ``dune-workspace`` at the root of your project, with the following
15+
contents:
16+
17+
.. code:: scheme
18+
19+
(lang dune 3.20)
20+
21+
(pkg disabled)
22+
23+
Since ``dune-workspace`` is the default workspace file, this tells Dune that by
24+
default, don't use its internal package management mechanism to resolve the
25+
project's dependencies, even in the presence of a lockdir.
26+
27+
Now create a second file in the project root named ``dune-workspace.pkg``. The
28+
name of this file isn't important, but conventionally alternative workspace
29+
files begin with the ``dune-workspace.`` prefix. Add the following to this new
30+
file:
31+
32+
.. code:: scheme
33+
34+
(lang dune 3.20)
35+
36+
(pkg enabled)
37+
38+
With these two files in place, by default Dune will use the specified Opam
39+
switch to resolve your project's dependencies. However, setting the environment
40+
variable ``DUNE_WORKSPACE=dune-workspace.pkg`` will cause Dune to use
41+
its internal package management mechanism to resolve dependencies instead. Unset
42+
the ``DUNE_WORKSPACE`` environment variable to return to an Opam-based workflow.
43+
44+
Alternatively to setting the ``DUNE_WORKSPACE`` environment variable, invoking
45+
commands like ``dune build``, ``dune exec``, and ``dune pkg lock`` with the
46+
argument ``--workspace=dune-workspace.pkg`` also has the effect of changing
47+
which workspace file Dune will use to the one which enables package management.

0 commit comments

Comments
 (0)