Is opam using the dune cache when building packages?

I can’t seem to figure this out. I have enabled the dune cache in ~/.cache/dune. This directory grows in size when I do dune build, so it seems to be working. However, if I nuke the cache and install some package (which builds through dune), then the cache is not populated. Does this make sense? I couldn’t find a straight answer when searching on whether opam builds should profit from the dune cache or not. I’m using opam version 2.2.0, dune version 3.16.0.

1 Like

At first I thought that maybe it doesn’t work because the dune cache is outside of the sandbox that opam uses for building but if I take a look at ~/.opam/opam-init/hooks/sandbox.sh there is specific support for the dune cache (in rw mode, so it should be able to populate it), and it is called when building so this seems all correct.

Maybe check whether this is the same for you as well?

I haven’t messed with the default settings when setting up the switch, and my sandbox script also mentions dune cache. Do you see the dune cache being used / populated when you do opam stuff? I’ll try to disable sandboxing altogether…

Hmm, if I do opam init --disable-sandboxing then the dune cache is populated when I install packages. So then it would seem that whatever exceptions are being made for the dune cache in sandbox.sh are not working on my machine. A bug in opam?

Could it be that you have enabled the cache in your dune config file but that file is not being mounted into the sandbox; thus the sandboxed dune doesn’t see that it should be enabled?

Maybe setting DUNE_CACHE=enabled would solve it? Or ro-mounting the config file into the sandbox.

1 Like

I had a second look. It still seems like the dune cache is not used even though I’ve explicitly set DUNE_CACHE=enabled. The issue is indeed sandboxing. If I make sure the sandbox script calls dune with --verbose, I see errors like:

cache store error [0c82767bf03a1f977be00fd6067a0121]: cannot link
- /home/arvid/.cache/dune/db/temp/dune_0d8e6f_artifacts/bam.cmxs between file
- systems. Use (cache-storage-mode copy) instead.

So either the sandbox must be disabled, or one can try the (slower) cache storage mode copy.

That is suggesting that the dune-cache and wherever opam is doing its thing are on different mounts. Which would indeed mean links from one to the other won’t work.