Haskell Stack build specific executable

2020-07-13 12:00发布

问题:

How to build an specific stack executable file, ie. those specified in projectname.cabal, like:

executable executable-name
  hs-source-dirs:      tools
  main-is:             ExecutableModule.hs
  ghc-options:         -Wall -threaded -rtsopts -with-rtsopts=-N
  build-depends:       base
                     , hsass
                     , hlibsass

I would need to compile executable-name and no other. It would be something like:

stack build --executable executable-name

回答1:

Stack uses a component based lookup, e.g.

stack build packagename:component-type:component-name

So if your package is called "foo", and your executable is called "bar", you can use

stack build foo:exe:bar

However, if the component-name is unique, you can drop the package's name and the component type. So if your executable is called "exectuable-name", it's

stack build :executable-name