Skip to content
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

Cabal 3: in build-depends, package name gets treated as internal library name ("legacy" syntax) even when using the pkg:lib qualified syntax #6083

Closed
ekmett opened this issue Jun 17, 2019 · 7 comments
Assignees
Labels
Cabal: other re: internal library Concerning internal libraries in packages type: bug
Milestone

Comments

@ekmett
Copy link
Member

ekmett commented Jun 17, 2019

I had 3 libraries:

fontconfig -- provides fontconfig bindings
fontconfig-freetype -- provides supplementary support for freetype
freetype -- provides freetype bindings

I've consolidated the first two into one using public sublibraries. I had to rename the new sublibrary for fontconfig-freetype to fcfreetype to hack it into place.

Now I'd like to be able to use the unmangled name, so that users would incur a dependency on fontconfig:freetype or fontconfig:{freetype}, and all that really changes is a character or so in their imports, but I'd be able to maintain a single package on hackage. While users who do not want or need freetype can depend on fontconfig:core and bypass the extras.

Done right this sort of thing seems like a path to having many many little fine-grained internal dependencies, so you can incur dependencies on just the functionality you need out of a larger package.

But it seems no matter how I try to refer to the external library freetype, I'm getting a cycle detected as if the top level fontconfig library which re-exports its own sub-library freetypes contents is in a cycle with its member.

I'm guessing either I have no way to refer to the external freetype in the current naming convention, or something is one step too simple in the cycle detector? What is the correct name to use to refer to a library that isn't the one in the current package being built, but rather the name in the top level namespace?

See this associated commit to a side-branch for this issue.

The repository should compile with ghc 8.8 and cabal 3. I apologize for not distilling a smaller issue, but basically any example of library name shadowing should do.

This arises for me at least, because I also have about a dozen more of these, each of which would need distinct name mangling conventions.(e.g. harfbuzz-freetype, harfbuzz-icu) and it seems a shame to make the user use harfbuzz:hb-ft or something rather than remain as clear as the current naming.

@fgaz
Copy link
Member

fgaz commented Jun 18, 2019

That's the legacy syntax :-/

Internal library names shadow external package names.

I was planning to leave it for another .cabal version or so, but I guess we could just disable it now since conflicts like this are likely to happen

/cc @hvr

@fgaz fgaz changed the title Cabal 3: Bad cycle detection in library names Cabal 3: sublibrary name shadowing becomes a problem with public sublibraries Jun 18, 2019
@fgaz
Copy link
Member

fgaz commented Jun 18, 2019

Btw you may want to add visibility:public to those sublibrary stanzas. The Cabal shipped with ghc 8.8 alpha does not enforce it, but from rc1 onwards it will

@hvr
Copy link
Member

hvr commented Jun 18, 2019

@fgaz what do you consider "legacy" syntax?

Shouldn't build-depends: foo:bar always unambigously refer to the (sub)lib bar in the package foo?

Likewise, shouldn't build-depends: foo:foo always refer unambigously to the primary library of the package foo?

I.e. by using the fully qualified syntax we should always be able to refer to an absolute target, regardless of what intra-package sublibs happen to be in scope.

Whether build-depends: bar is subject to (consistent!) shadowing by local sublib (i.e. when a local intra-package sublib named bar exists it shall shadow an external package-name bar) shouldn't be a an actual problem -- and I'm hesitant to change these shadowing semantics as we'd still need to keep them for cabal-version:2.4 and older, unless there's a compelling reason to do so that outweights the potentially confusing switch of semantics as a function of the declared cabal-version:

@fgaz
Copy link
Member

fgaz commented Jun 18, 2019

@hvr is right, I didn't see you used the full qualified syntax (freetype:freetype), which should work. Somehow the package name gets treated as a library name anyway. This is indeed a bug

@fgaz fgaz self-assigned this Jun 18, 2019
@fgaz fgaz changed the title Cabal 3: sublibrary name shadowing becomes a problem with public sublibraries Cabal 3: in build-depends, package name gets treated as internal library name ("legacy" syntax) even when using the pkg:lib qualified syntax Jun 18, 2019
@fgaz fgaz mentioned this issue Jun 26, 2019
31 tasks
@phadej phadej added this to the 3.0.1.0 milestone Nov 28, 2019
@phadej
Copy link
Collaborator

phadej commented Nov 28, 2019

We cannot fix this in 3.0 anymore

The freetype:freetype (explicit) and freetype (ambiguous) are both parsed as

+                      condTreeConstraints = [Dependency
+                                               (PackageName "freetype")
+                                               AnyVersion
+                                               (Set.fromList [LMainLibName])],

So latter in the pipeline we cannot know which way it was originally. Reschedulling for 3.2

@phadej phadej modified the milestones: 3.0.1.0, 3.2 Nov 28, 2019
phadej added a commit that referenced this issue Nov 28, 2019
I'm adding this test, so we dont' silently change the behaviour
for `cabal-version: 3.0`
@phadej phadej modified the milestones: 3.2, 3.4 Nov 28, 2019
@phadej
Copy link
Collaborator

phadej commented Nov 28, 2019

Sorry for the spam. Actually I'm scheduling this for 3.4 directly, as the current plan is to not produce cabal-version: 3.2. We don't have time, and this would be the only change into the format.

phadej added a commit that referenced this issue Nov 28, 2019
I'm adding this test, so we dont' silently change the behaviour
for `cabal-version: 3.0`
phadej added a commit that referenced this issue Nov 28, 2019
I'm adding this test, so we dont' silently change the behaviour
for `cabal-version: 3.0`
phadej added a commit that referenced this issue Nov 29, 2019
Add test for #6083, build-depends: pkg:pkg
phadej added a commit to phadej/cabal that referenced this issue Dec 4, 2019
I'm adding this test, so we dont' silently change the behaviour
for `cabal-version: 3.0`
@phadej
Copy link
Collaborator

phadej commented Mar 22, 2020

Whether build-depends: bar is subject to (consistent!) shadowing by local sublib (i.e. when a local intra-package sublib named bar exists it shall shadow an external package-name bar) shouldn't be a an actual problem -- and I'm hesitant to change these shadowing semantics as we'd still need to keep them for cabal-version:2.4 and older, unless there's a compelling reason to do so that outweights the potentially confusing switch of semantics as a function of the declared cabal-version:

I think this might be a solution, as interpretation of names happens after the parsing. Then bar would be shorthand for bar:bar independently of context. And you'll need to write mylib:bar to point to internal dependencies.

EDIT: getInternalPackages is one function to look at. It does shadowing currently.

@phadej phadej self-assigned this May 14, 2020
@phadej phadej modified the milestones: Considered for 3.4, 3.4.0.0 May 14, 2020
phadej added a commit to phadej/cabal that referenced this issue May 14, 2020
Also add a test for current behaviour
of haskell#6083

And variant with mixin, for haskell#6281

The tests are disable for GHC older than 8.8
Should they work?
phadej added a commit to phadej/cabal that referenced this issue May 15, 2020
Also add a test for current behaviour
of haskell#6083

And variant with mixin, for haskell#6281

The tests are disable for GHC older than 8.8
Should they work?
phadej added a commit to phadej/cabal that referenced this issue May 15, 2020
Also add a test for current behaviour
of haskell#6083

And variant with mixin, for haskell#6281

The tests are disable for GHC older than 8.8
Should they work?
phadej added a commit that referenced this issue Jun 11, 2020
This is preparation to solve #6083.
As such, this shouldn't affect anything yet.
phadej added a commit to phadej/cabal that referenced this issue Jun 12, 2020
This is preparation to solve haskell#6083.
As such, this shouldn't affect anything yet.
phadej added a commit to phadej/cabal that referenced this issue Jun 16, 2020
Note: configuredPackageProblems is a mess,
and there might be bugs now.
@phadej phadej closed this as completed in 6747939 Jun 16, 2020
phadej added a commit that referenced this issue Jun 16, 2020
Fix #6083: allow depending on public sublibrary with pkg:lib qualified syntax
@fgaz fgaz added the re: internal library Concerning internal libraries in packages label Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cabal: other re: internal library Concerning internal libraries in packages type: bug
Projects
None yet
Development

No branches or pull requests

4 participants