15

While building my Haskell programs with Stack, I'm trying to get the executable to be written to project/dist/ but no matter what command line arguments I use or config files I change, it always ends up in project/.stack-work/dist/x86_64-osx/Cabal-2.2.0.1/build/project/.

After spending a decent amount of time looking at the command line arguments for the stack command, as well as options in project.cabal, Setup.hs, and stack.yaml, I can't seem to find how to configure the output location of stack build.

How do you configure the executable output location for stack build?

sjakobi
  • 3,546
  • 1
  • 25
  • 43
TheEnvironmentalist
  • 2,694
  • 2
  • 19
  • 46

2 Answers2

13

You can use the --copy-bins flag (or the install command) to copy the executables to some output directory. That destination directory can be controlled with --local-bin-path, but defaults to ~/.local/bin on POSIX systems.

Michael Snoyman
  • 31,100
  • 3
  • 48
  • 77
5

stack path --local-install-root outputs path to build artifact. You just need to add /bin/name-of-my-exe to this path to get path of executable. And then you just run simple one-line bash script to copy executable to desired location.

Full command for completeness:

cp "$(stack path --local-install-root)/bin/name-of-my-exe" ~/.local/bin/name-of-my-exe
Shersh
  • 9,019
  • 3
  • 33
  • 61