I'm trying to run haskell code using stack ghci, but I am having this problem where stack build, stack ghci, stack anything except init (which runs fine), hangs pretty indefinitely.
Oh and this is on windows 10, running a stack I just downloaded last week. Here's the verbose output of the command it seems to get stuck on when I run stack ghci:
2016-06-12 17:22:46.134672: [debug] Run process:
C:\...\stack\setup-exe-cache\x86_64-windows\setup-Simple-Cabal-1.22.5.0-ghc-7.10.3.exe
--builddir=.stack-work\dist\2672c1f3
configure
--with-ghc=C:\...\stack\x86_64-windows\ghc-7.10.3\bin\ghc.exe
--with-ghc-pkg=C:\...\stack\x86_64-windows\ghc-7.10.3\bin\ghc-pkg.exe
--user
--package-db=clear
--package-db=global
--package-db=C:\...\stack\snapshots\ee4b7647\pkgdb
--package-db=C:\...\mp1-haskell\.stack-work\install\5c0a1b09\pkgdb
--libdir=C:\...\mp1-haskell\.stack-work\install\5c0a1b09\lib
--bindir=C:\...\mp1-haskell\.stack-work\install\5c0a1b09\bin
--datadir=C:\...\assignments\mp1-haskell\.stack-work\install\5c0a1b09\share
--libexecdir=C:\...\mp1-haskell\.stack-work\install\5c0a1b09\libexec
--sysconfdir=C:\...\mp1-haskell\.stack-work\install\5c0a1b09\etc
--docdir=C:\...\mp1-haskell\.stack-work\install\5c0a1b09\doc\mp1-haskell-0.1.0.0
--htmldir=C:\...\mp1-haskell\.stack-work\install\5c0a1b09\doc\mp1-haskell-0.1.0.0
--haddockdir=C:\...\mp1-haskell\.stack-work\install\5c0a1b09\doc\mp1-haskell-0.1.0.0
--dependency=base=base-4.8.2.0-14035a44a8b95c6832da6dae1420f59e
--extra-include-dirs=C:\...\stack\x86_64-windows\msys2-20150512\mingw64\include
--extra-lib-dirs=C:\...\stack\x86_64-windows\msys2-20150512\mingw64\lib
--enable-tests
--enable-benchmarks #(stack_9kewhubnl5WIl89fhd1ea2:System.Process.Read src/System\Process\Read.hs:283:3)
Related
Why does
stack bench builds (and run)
and
stack build mypackage:bench tells me
Cabal-simple_mPHDZzAJ_3.4.1.0_ghc-9.0.2: No benchmarks enabled. Did
you remember to configure with '--enable-benchmarks'?
I am trying to setup my Haskero (Visual Studio Code extension that uses Intero) for my Haskell project, yet I get the following error :
app\Main.hs:3:1: error:
Failed to load interface for `Lib'
Use -v to see a list of the files searched for.
Steps to reproduce:
stack new project
cd project
stack build intero
stack exec intero
> :l app/Main.hs
app/Main.hs :
module Main where
import Lib
main :: IO ()
main = someFunc
src/Lib.hs :
module Lib
( someFunc
) where
someFunc :: IO ()
someFunc = putStrLn "someFunc"
I had similar issue occuring in Visual Studio Code.
Under the hood Haskero properly uses:
stack ghci --with-ghc intero --no-build --no-load
However Haskero assumes that the stack project is the working directory loaded to VSCode. If instead the stack project is one of the subdirectories then the same error appears in IDE, because stack command is run from that main directory. At least it's what happens currently with Haskero 1.3.1.
The solution is to always make sure that stack project is equal to working directory in VSCode.
I don't have experience with Haskero but can duplicate the problem with a plain old Intero installation on a Linux machine.
The issue is that you're invoking the Intero backend via stack exec instead of stack ghci. You would observe the same problem if you tried using stack exec ghci instead of stack ghci to invoke a usual GHC interactive session (see the documentation for stack ghci for more information).
Instead of stack exec intero, try:
stack ghci --with-ghc intero --no-build --no-load
and it should work okay.
(Note that stack exec intero actually works okay if you stack build your project first, but the interactive session is still supposed to be invoked via stack ghci.)
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...
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.
I've had quite a good experience using:
https://hackage.haskell.org/package/stack-run
Edit 2018-04-05: Relevant stack issue.
Old answer:
This is what I ended up doing for now.
#/usr/bin/env sh
stack build && stack exec `basename "$PWD"` "$#"
I've put the following into a file named stack-run under my $PATH. ~/.local/bin/stack-run in my case.
Which allows me to
$ stack-run
in any directory, and even
$ stack run
Since in almost all of my projects the executable of the project bears the same name as the folder, this works. But I hope to extend it with support for differing names as well.
Edit 2016-09-26: I've also found this, but haven't given it a try yet:
https://hackage.haskell.org/package/stack-run
I followed "Yesod quick start guide" to install Yesod in Windows 10.
But, when I issued the stack build command, it failed.
Environment
Windows 10 (64bits)
stack-0.1.5 (for Windows10 64bits)
No Haskell Platform
I executed these commands
stack new my-project yesod-sqlite && cd my-project
stack install yesod-bin cabal-install --install-ghc
stack setup
stack build <--- the error occured
In 'stack build' command, the package installations were done. But, when it build the project, the error occured.
Command Prompt
>stack build
Setting codepage to UTF-8 (65001) to ensure correct output from GHC
my-project-0.0.0: build
Preprocessing library my-project-0.0.0...
In-place registering my-project-0.0.0...
Preprocessing executable 'my-project' for my-project-0.0.0...
Linking .stack-work\dist\x86_64-windows\Cabal-1.22.4.0\build\my-project\my-project.exe ...
ghc.exe: could not execute: C:\Users\xxxxx\AppData\Local\Programs\stack\x86_64-windows\ghc-7.10.2\lib/../mingw/bin/gcc.exe
-- While building package my-project-0.0.0 using:
C:\Users\xxxxx\AppData\Roaming\local\bin\stack-0.1.5.0\setup-exe-cache\setup-Simple-Cabal-1.22.4.0-x86_64-windows-ghc-7.10.2.exe --builddir=.stack-work\dist\x86_64-windows\Cabal-1.22.4.0\ build lib:my-project exe:my-project --ghc-options -ddump-hi -ddump-to-file
Process exited with code: ExitFailure 1
This is caused by the argument length limit on Windows. Starting in GHC 7.10.3, GHC will support response files for sending linker arguments in order to bypass this limitation. In the meanwhile, a workaround is to manually make the path to your stack root shorter by setting the STACK_ROOT environment variable.
For more information, see https://www.fpcomplete.com/blog/2015/08/stack-ghc-windows
Getting following error when trying to stack build snowdrift on Windows:
Linking .stack-work\dist\i386-windows\Cabal-1.18.1.5\build\SnowdriftEmailDaemon\SnowdriftEmailDaemon.exe ...
ghc.exe: could not execute: C:\Users\Razvan\AppData\Local\Programs\stack\i386-windows\ghc-7.8.4\lib/../mingw/bin/gcc.exe
Completed all 6 actions.
-- While building package Snowdrift-0.1.4 using:
C:\\Users\\Razvan\\AppData\\Local\\Programs\\stack\\i386-windows\\ghc-7.8.4\\bin\\runhaskell.exe -package=Cabal-1.18.1.5 -clear-package-db -global-package-db -package-db=C:\Users\Razvan\AppData\Roaming\stack\snapshots\i386-windows\lts-2.13\7.8.4\pkgdb\ C:\Users\Razvan\AppData\Local\Temp\stack124196\Setup.hs --builddir=.stack-work\dist\i386-windows\Cabal-1.18.1.5\ build
Process exited with code: ExitFailure 1
My question is how to obtain more information on this error as it is quite vague. Looking under .\.stack-work\logs I can't find any snowdrift related log. It is almost like setting the stack verbosity level to debug does not affect ghc/gcc verbosity level or maybe extra error information is just not there.
More information on the issue here.