Up until recently, I was executing this beauty to build + run a project with stack:
stack build && .stack-work/install/x86_64-linux/lts-4.1/7.10.3/bin/<project-name>
I was told on IRC that this can be simplified to
stack build && stack exec <project-name>
Can this be simplified even more, to
stack run
or at least
stack run <project-name>
?
If I recall correctly this was possible with cabal run
.
Edit:
@haoformayor's comment is getting close:
alias b='stack build --fast --ghc-options="-Wall" && stack exec'
Although this still needs the project name, right?
I've also started to get close with
function stack-run () { stack build && stack exec `basename "$PWD"` }
Although this only works if the project name matches with the folder name. Maybe we can query cabal/stack for the first executable
entry in the .cabal file? Or Maybe we could do it with sed
...
Stack supports creating projects using templates. It also supports your own custom templates. Stack has built-in hpack support in it. It provides an alternative (IMO, a better) way of writing cabal files using yaml file which is more widely used in the industry.
In basketball, a stack is a type of inbounds play where the four offensive players on the court stand close together in a vertical line formation in front of the inbounder. The "stacked" players then simultaneously break out of the line formation by running to different locations on the court.
In its default configuration, Stack will simply ignore any system GHC installation and use a sandboxed GHC that it has installed itself. You can find these sandboxed GHC installations in the ghc-* directories in the stack path --programs directory.
Stack-built files generally go in either the Stack root directory (default: ~/. stack on Unix-like operating systems, or, %LOCALAPPDATA%\Programs\stack on Windows) or ./. stack-work directories local to each project. The Stack root directory holds packages belonging to snapshots and any Stack-installed versions of GHC.
As it's mentioned here http://docs.haskellstack.org/en/stable/README.html#quick-start-guide, you can use stack exec my-project-exe
where my-project-exe
is the name of the executable in your .cabal file.
You can use --exec
to tell stack what program should be run after a successful built:
stack build --exec <executable-name>
You can also specify arguments for the executable, e.g.
stack unpack pandoc && cd pandoc*
stack build --exec "pandoc --version"
That's probably the closest you'll get compared to cabal run
, since both stack exec
and the --exec
flag need an executable name. The cleanest variant, however, would be an additional stack-run
command, that does stack build --exec <first-executable in .cabal>
. It could be worth a feature request on the project's GitHub issue tracker.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With