bbarker
bbarker

Reputation: 13108

How does one have multiple libraries using hpack?

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    

Upvotes: 7

Views: 898

Answers (1)

sclv
sclv

Reputation: 38891

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.

Upvotes: 3

Related Questions