Skip to content

Conversation

@gridbugs
Copy link
Collaborator

No description provided.

@gridbugs gridbugs added the docs Documentation improvements label Nov 21, 2025
@Alizter
Copy link
Collaborator

Alizter commented Nov 21, 2025

Instead of setting contexts, wouldn't it be more useful to advertise (pkg disabled) for people looking to opt out of package management given a lock directory.

@Leonidas-from-XIV
Copy link
Collaborator

I would also rather advertise (pkg enabled)/(pkg disabled) over dune pkg lock. I think autolocking is probably what most people who just want a tool to install their dependencies want. dune pkg lock is more for those that want to lock their package versions, which I assume is a much smaller subset of the former.

@gridbugs gridbugs force-pushed the doc-opam-switch-and-pkg-workflow branch from 2c77694 to 2252ef8 Compare November 21, 2025 09:46
@Alizter
Copy link
Collaborator

Alizter commented Nov 21, 2025

It is however possible if a person wishes to contribute to a repo that has a checked in lock file but they may wish to continue to use opam.

@gridbugs
Copy link
Collaborator Author

Ok updated to use autolocking instead of lockdirs.


With these two files in place, by default Dune will use the specified Opam
switch to resolve your project's dependencies. However, setting the environment
variable ``DUNE_WORKSPACE=dune-workspace.pkg`` will cause Dune to use
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is also possible to do this using the --workspace cli option. But I'm not sure if its worth going into all this detail about it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a line about the CLI flag is probably good, because users of either strategy are likely to want to test or try the other in one-off commands.

@Alizter
Copy link
Collaborator

Alizter commented Nov 21, 2025

Do we have any genuine reasons other than not wanting to change for using opam? The existence of this tutorial might be confusing without the proper motivation.

@Sudha247
Copy link
Collaborator

Do we have any genuine reasons other than not wanting to change for using opam? The existence of this tutorial might be confusing without the proper motivation.

This is a good question. I think this tutorial is useful because a large chunk of users of dune pkg are coming from opam. Having an incremental path makes it easier to try out Dune package management without the doubt that something might break and go into an irrecoverable state. Furthermore, for large projects with a sizeable number of contributors, (e.g. ocaml.org as observed in ocaml/ocaml.org#3280), it might be required to still have a workflow for opam even if the project decides to use dune pkg by default. Changes tend to take time, and it makes sense to try and make it as smooth as possible for the users.

@Alizter
Copy link
Collaborator

Alizter commented Nov 21, 2025

OK what about this. We should add a paragraph stating that we are interested in knowing what can be done with opam that can't with dune pkg for local development. If there is something we are not aware of, we should definitely ask about it. Opening an issue etc.

@@ -0,0 +1,41 @@
How to Use Opam Alongside Dune Package Management
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a lovely solution!

@shonfeder
Copy link
Member

shonfeder commented Nov 21, 2025

@Alizter see quantifyearth/container-image#7 (review) and the following discussion for context.

We should add a paragraph stating that we are interested in knowing what can be done with opam that can't with dune pkg for local development

IMO, this needlessly complicates the documentation here. AFAIU, we all agree dune must continue to support non dune-pkg development workflows (at least in the near to midterm future), and so we should make it easy for people who want to manage dependencies with opam to do so. I don't think we need to situate it as a resource contention or complicate the docs on how to do that easily with nudges to use dunt pkg instead.

@gridbugs gridbugs force-pushed the doc-opam-switch-and-pkg-workflow branch 2 times, most recently from 43b5726 to d6d64ea Compare November 24, 2025 08:13
@gridbugs gridbugs force-pushed the doc-opam-switch-and-pkg-workflow branch 2 times, most recently from e907bcb to f5de90d Compare November 24, 2025 08:15
@gridbugs gridbugs enabled auto-merge (squash) November 24, 2025 08:22
@gridbugs gridbugs merged commit d63da6b into ocaml:main Nov 24, 2025
26 checks passed
@avsm
Copy link
Member

avsm commented Nov 27, 2025

This doesn't seem to actually work though...

> cat dune-project
(lang dune 3.20)
(pkg enabled)
> dune build
File "dune-project", line 2, characters 1-4:
2 | (pkg enabled)
     ^^^
Error: Unknown field "pkg"
Hint: did you mean pin?

I assume this needs lang dune 3.21 ?

@Alizter
Copy link
Collaborator

Alizter commented Nov 27, 2025

This doesn't seem to actually work though...

> cat dune-project
(lang dune 3.20)
(pkg enabled)
> dune build
File "dune-project", line 2, characters 1-4:
2 | (pkg enabled)
     ^^^
Error: Unknown field "pkg"
Hint: did you mean pin?

I assume this needs lang dune 3.21 ?

(pkg enabled) needs to be in the dune-workspace file and not the dune-project file. The reason is that it is workspace level configuration rather than project level.

Would be nice to have an informative error message here about that.

@avsm
Copy link
Member

avsm commented Nov 27, 2025

Thanks @Alizter! However, it doesn't work in the dune-workspace file either; the presence of a dune.lock seems to always activate dune package management for me.

> cat dune-workspace
(lang dune 3.20)

(pkg disabled)

(lock_dir
 (repositories upstream overlay oxcaml))

(repository
 (name oxcaml)
 (url "git+https://github.com/avsm/oxcaml-opam-repository.git#ocamlbuild.0.16"))
> dune build --verbose
Shared cache: enabled-except-user-rules
Shared cache location: /Users/avsm/.cache/dune/db
Workspace root: /Users/avsm/scratch/bushel-viewer
Auto-detected concurrency: 16
Dune context:
 { name = "default"
 ; kind = lock { default = true }
 ; profile = Dev
 ; merlin = true
 ; fdo_target_exe = None
 ; build_dir = In_build_dir "default"
 ; instrument_with = []
 }
Actual targets:
- alias @@default
Running[4]: (cd _build/.sandbox/199d1cb959c09d62ea0b0fe791cda853/_private/default/.pkg/conf-autoconf/source && /opt/homebrew/bin/autoconf -V) 2> /var/folders/sg/gylc81bj6s54lsgs0zwh3qxc0000gn/T/dune-pkg_7d8574_stderr
Running[5]: (cd _build/.sandbox/ecc939f651c744d8510fd55913c6fe44/_private/default/.pkg/conf-which/source && /usr/bin/which which) 2> /var/folders/sg/gylc81bj6s54lsgs0zwh3qxc0000gn/T/dune-pkg_e9ba03_stderr
Output[5]:
/usr/bin/which
Output[4]:
autoconf (GNU Autoconf) 2.72
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+/Autoconf: GNU GPL version 3 or later
<https://gnu.org/licenses/gpl.html>, <https://gnu.org/licenses/exceptions.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David J. MacKenzie and Akim Demaille.
Got signal INT, exiting.           ^C
> dune --version
3.20.2

@Alizter
Copy link
Collaborator

Alizter commented Nov 27, 2025

@avsm Yes, unfortunately this is a bug with 3.20. This is fixed in the soon-to-be-released 3.21.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants