How does one have multiple libraries using hpack?
Asked Answered
F

1

7

I'd like to organize my project into different libraries, since eventually I may be splitting some out to external repositories.

In a .cabal file I can have multiple libraries (one unnamed, and multiple named, I believe):

library
  import: servant-deps
  exposed-modules:
      App
  other-modules:
      Paths_cow_streamer
  hs-source-dirs:
      src
  build-depends:
      servant-server >= 0.15


library sxapi
  import: servant-deps
  exposed-modules:
      SxClient
  other-modules:
      Paths_cow_streamer
  hs-source-dirs:
      sxapi
  build-depends:
      http-client

Initially I tried like this in my hpack package.yaml:

library:
  bar:
    source-dirs:
      - src
    dependencies:
      - servant-server >= 0.14
      - wai
      - warp
  foo:
    source-dirs:
      - sxapi
    dependencies:
      - servant-server >= 0.14
      - wai
      - warp    

But in this case, none of the entries seemed to be interpreted correctly, since e.g. source-dirs weren't present in the generated cabal file.

I also tried this, but unsurprisingly, one of the library definitions was overwritten:

library:
  source-dirs:
    - src
  dependencies:
    - servant-server >= 0.14
    - wai
    - warp

library:      
  source-dirs:
    - sxapi
  dependencies:
    - servant-server >= 0.14
    - wai
    - warp    
Fireproof answered 21/12, 2018 at 21:6 Comment(3)
You can have multiple libraries in a .cabal file? Since when?Fayefayette
Now that you mention it, maybe it was a similar situation where all but the last was ignored; not sure but could check later.Fireproof
@AlexisKing Since Cabal 3.0.0.0, apparently.Shanelleshaner
P
3

As per the documentation of hpack (https://github.com/sol/hpack#top-level-fields) you use the internal-libraries header for your internal (named) libraries.

Preach answered 12/8, 2021 at 18:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.