refactoring: add dune_opam library for opam file parsing#13438
refactoring: add dune_opam library for opam file parsing#13438samoht wants to merge 1 commit intoocaml:mainfrom
Conversation
Create a new dune_opam library that sits between dune_lang and dune_pkg in the dependency hierarchy. Signed-off-by: Thomas Gazagnaire <thomas@gazagnaire.org>
|
Is this for the ability the ability to vendor opam packages inside inside dune workspaces? |
|
yes -- and also to separate the "locking" rules from the "building" rules. They don't have to be so closely intertwined (they are separate features). |
|
I see. Off the top of my head, I don't see how it helps since the rules can already use dune_pkg. I also expect that this feature would work independently from the scope stanza so that more users could benefit from it. Meanwhile, all of these additional libraries are slowing down builds as we're starting to realize. Let's keep this in mind while we're trying to make this feature work. I'd like to see more concrete benefits before we commit to this split. Something that will definitely need to be split for this feature to work is some of the code in pkg_rules.ml. We need a set of functions that will build an opam package without looking it up in the lock directory. |
|
Here's an outline for how to implement this feature:
|
|
In your mind, is this an incremental path to a point where opam packages that use Dune in their lock file are built with dune directly rather than via opam rules? I'm still not very fond of mixing the notions of locks and opam packages. It's perfectly fine to lock dune packages (like opam-monorepo does). And in that case, it's really odd to have pkg_rules intertwining both opam rules and lock rules. tbh, I'd really prefer if locks were just a light way to create a workspace that then uses normal dune rules (that know nothing about the lock). You could, for instance, always promote the opam-repo metadata to the package (ie, copy the opam file back in the source/build tree where the source of that package builds) so they are standalone and there is no distinction between "lock" package and normal packages stanza. |
|
At the moment, building an opam package with dune is something that we already have in pkg_rules. So I'm of course eager to reuse that code as much as possible because it already does all the hard work of integrating with the rest of the rules. Without using this module, the entire idea would be hopeless because of the massive amount of work that it would require. So it really is the path of least resistance by a wide margin. Now it's true that this module has awareness of a bunch of things that you might not care about (lock dirs, autolocking, dev tools), but that's a question of organization that I'd rather address after the feature is in a working state. I much prefer refactoring after we have a working prototype rather than before. But moreover, I would like this feature to integrate with package management even if not everybody intends to use it that way. I would for example prefer that a vendored package can be used to build a package inside the lock dir and vice versa.
I think you need to clarify what you mean here. Do you mean just copy opam packages along with their sources into some directory that dune knows how to use? |
To be clear, I really don't intend to reimplement it at all from scratch! Lots of work has already been put into that feature, so it's just about extracting/reorganising it. And I do think doing this sooner rather than later will help with testing and proper design, instead of having a very large file where everything is tightly coupled and hard to (unit) test. Anyway, I don't have strong opinions either way. I created this PR to open the discussion, I didn't intend to have it merged straight away :-) |
Somehow my mental model is this one:
|
|
Yeah, that's basically the opam-monorepo model but with dune filling in first class support for non dune packages. I don't think it works for everybody, but I don't really see the tension in the dune code base to support both workflows. I think you already have your own solver integration in opam-monorepo to select version and fetch sources. Dune just needs to take it from there. |
|
Why would this not work for everybody ? Also I don't understand the rationale for the current pkg strategy : why you are trying to wrap dune builds inside opam build inside dune builds ? This is very inefficient and you loose all the good properties of Dune). Seems more reliable to just use opam at this point :-) |
I don't want external sources polluting my workspace. I want to reuse dune's cache to store and deduplicate sources.
That is just a temporary limitation that will be lifted eventually.
But then your feature request to build opam packages in dune wouldn't have any legs to stand on :). |
So jump-to-definition will jump into the cache? :-) |
|
Yes, right in the _build directory. What's the downside? That we can't edit our dependencies? That's not really all that common. Moreover, any such patches would need to be formalized with something like pins or composition otherwise the next time the deps are updated by whatever tool re-downloads the sources they would be blown away. |
This PR creates a new
dune_opamlibrary that sits betweendune_langanddune_pkgin the dependency hierarchy.As discussed with @Alizter and @art-w, this patch extracts the
opam buildandopam installDune rules into their own libraries so they can be reused, for instance by the scope stanza.Apologies in advance for the code drop... I'll have limited availability in the following days, so please feel free to take over that PR if you think that's useful.