Skip to content

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

Description

@ekmett

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.

Activity

  1. fgaz commented on Jun 18, 2019

    @fgaz
    Member

    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

  2. changed the title [-]Cabal 3: Bad cycle detection in library names[/-] [+]Cabal 3: sublibrary name shadowing becomes a problem with public sublibraries[/+] on Jun 18, 2019
  3. fgaz commented on Jun 18, 2019

    @fgaz
    Member

    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

  4. hvr commented on Jun 18, 2019

    @hvr
    Member

    @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:

  5. fgaz commented on Jun 18, 2019

    @fgaz
    Member

    @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

  6. self-assigned this
    on Jun 18, 2019
  7. 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[/+] on Jun 18, 2019
  8. added this to the 3.0.1.0 milestone on Nov 28, 2019
  9. phadej commented on Nov 28, 2019

    @phadej
    Collaborator

    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

  10. modified the milestones: 3.0.1.0, 3.2 on Nov 28, 2019
  11. 8 remaining items

  12. phadej commented on Mar 22, 2020

    @phadej
    Collaborator

    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.

  13. self-assigned this
    on May 14, 2020
  14. added 3 commits that reference this issue on May 14, 2020
  15. added 4 commits that reference this issue on Jun 11, 2020
  16. added 2 commits that reference this issue on Jun 16, 2020
    9b380e2
    b256029
  17. added
    re: internal library
    on Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Cabal: otherre: internal librarytype: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions