-
Notifications
You must be signed in to change notification settings - Fork 696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scoped packages (i.e. multiple libraries in a Cabal package) #2716
Comments
I'll quote myself from Reddit Please, please don't do this. Our tooling is barely holding together as is. Throwing yet another curve ball is yet another failure case we all get to worry about and experience. |
(Updated description with some motivations.) Reddit conversation: https://www.reddit.com/r/haskell/comments/3cu5nu/feedback_requested_for_supporting_multiple/ |
Can you elaborate on why Backpack can't just use one cabal file per package?
Are there some concrete examples of this? It would make more sense to me to have backpack sit as a layer on top of cabal, rather than inside of it. |
I've read the description (and updates) and the explanations on Reddit. I'm still not sure I understand the current version of the proposal. I'll take a stab at it to at least start a conversation:
Presumably, cabal-install/stack will need quite a bit of smarts added to understand these new "phantom" packages in the GHC package database, but the impact will be limited to those tools, the Cabal library, and (I guess obviously) whatever changes GHC itself requires to make all of this work. Am I on the right track with this? |
@ezyang as you know, in principle I'm supportive of the backpack effort, though as you also know I sometimes struggle with the details :-) I should point out that related to this is the idea of convenience libraries #269, which also involves the idea of multiple libraries in a single cabal package. The key thing with convenience libs however is that they're completely private to that package, are only used by other components within the package and don't contribute to the global package namespace. So totally agree on the zero / one oddity. Convenience libs would allow zero / one "public" libs and zero or more "private" libs. The big issue here with backpack is indeed the package naming issue. Having one unit of distribution provide multiple names that can be depended on by other distribution units is a significant thing. The idea of hierarchy is interesting. Are you sure backpack could really work with that? We don't ever need to refer to backpack unit p where that could come from cabal package A or B? It's always going to be possible to say that it's A.p or B.p? |
@ezyang in your revised description, I'd like to clarify what you mean/want with private libraries. The old idea of "convenience libraries" was like these private libraries except that they would not be registered into the main package db. The idea was we could get away without (and thus without namespace issues). As far as I can see, for the private lib use case there's still no need to actually register them, though I can see that for the backpack case there is. Have I missed something or is the thing about registering them solely for the backpack use case? |
@dcoutts I just read over the convenience libraries proposal. It seems that:
Convenience libraries seems to be all about local use, so I don't think registering globally is useful except for Backpack. But Backpack cares about it a lot.
I retract any earlier comments about this: Backpack will continue the Cabal model of only exporting a single package. Let's defer any conversation about subpackages of a Cabal file for much later. You are on track.
I think that the recommended strategy for cabal-install/stack is to simply ignore these packages (pretend they don't exist). They're not useful for purposes of dependency resolution. We'll need GHC changes to support this but we need GHC changes for Backpack anyway, so it's not an onerous restriction.
That was the first design, but this means that Backpack cannot be used independently of Cabal, which is a steep price to pay. |
Closing this for now. |
Currently, Cabal's internal notion of a package only supports zero or one libraries. This sticks out as a bit of a sore thumb compared to other components in a Cabal file: Cabal currently supports compiling many components per Cabal file (libraries, test suites, executables, benchmarks), but only one of these components can be a library. I propose to remove this restriction, thus making libraries treated uniformly with other components in Cabal. We can then refactor PackageDescription to have a list of components.
Use-cases:
This would then directly allow us to support private packages (these would be an extra library that would be installed to the installed package database, making it visible to GHC).
For internal packages (which may be depended upon by public packages but cannot be referenced directly), the above proposal suffices. However, you might want to export more than one package from a Cabal file. The big use-case is when you have a package which has been split into a constellation of packages in order to make it easier for users to install useful subsets of functionality without pulling in the rest of the dependencies they don't want. However, maintaining N different Cabal files can be a bit of a pain for tightly coupled packages. With scoped packages, all of these packages could be placed in one Cabal file. (We have to make sure components get depsolved separately, but @edsko has put us most of the way there.)
The big problem with this is that it breaks the invariant that there is a one-to-one mapping between exported libraries and Cabal packages. If a Cabal file can define multiple libraries (which live in the same namespace a package names), then both
foo.cabal
andbar.cabal
could define thehelper
package (collision). Furthermore, fromcabal-install
's perspective, if we need thehelper
package, it is not obvious where to look if there is nohelper.cabal
. There was considerable pushback here, so it may end up being the case that this is never going to be implemented.However, if we did want to solve this, one way would be to introduce a hierarchy of scoping to package names. For the rest of this bug, I'll assume we delimit scopes with
-
. (If we don't care about compatibility with older versions of GHC, we could use something less ambiguous). The invariant is that a package namedp
can only define librariesp
andp-anysubname
. (We might even further imagine publishing a package namedp-anysubname
, thus allowing multiple libraries to be split up from a Cabal file). Ifcabal-install
encounters a dependency onp-subpackage
, it looks atp.cabal
for a description of how to build it (or forp-subpackage.cabal
). There is some ambiguity since package names today can use hyphens, but the potential massive conflicts are reduced, andcabal-install
only has to query a few Cabal packages to see where a package is defined, as opposed to the ENTIRE package database.The text was updated successfully, but these errors were encountered: