Can you have different compilers and resolvers on Stack? - haskell

I have a Stack project that can build both GHCJS and GHC binaries. How can I specify on stack.yaml that builds should use both compilers?

I think you have to either
use two different files, say ghc.yaml and ghcjs.yaml, you can then use stack --stack-yaml ghc.yaml or stack --stack-yaml ghcjs.yaml to use those
you can set the compiler ghc or ghcjs by setting the resolver (see haskellstack.org/config#resolver)
or there is a compiler option (see haskellstack.org/config#compiler)
or directly use the commandline option --compiler

Related

global GHC from Stack?

I have happily installed Stack, and run my code with stack ghci or stack exec and whatnot.
I would like to use vscode-haskell, and that requires a ghc available in the PATH.
Is it possible to create a ghc command available globally using stack? (e.g. some suitable commans in my powershell/bash profile)
ps. Close duplicates that did not help me are
Using stack ghc as replacement of ghc but only talks about makefiles
Haskell Stack doesn't use system Ghc is about making Stack use a system GHC if it is available which is not the case for me
Haskell stack with global ghc which is close to a dupplicate of [2]

Is there a way for `stack --nix` to allow newer versions of ghc to be used?

I'm running stack --nix init for a new project (xmonad config) and getting error: attribute 'ghc863' missing, at (string):1:43; I have ghc 8.6.5 in the environment, and stack --version reports: 2.1.3.1 x86_64 hpack-0.32.0. My project is roughly following this blog post for building XMonad (with exceptions made to do things using Nix where possible), and so far only consists of cloning the three repos into .xmonad and running stack --nix init; the three repos are: xmobar, xmonad-contrib, xmonad.
Is there a way for stack --nix to allow newer versions of ghc to be used? Or are there other possible causes for the issue?
I saw stack --nix build complains about ghc version mismatch but felt this didn't really illuminate the issue, though it does suggest possibly alternatives using cabal/nix.

Passing RTS-opts to `stack test`

How can I pass RTS options to the test-suite of my project using stack?
stack exec allows for passing options to the executable, but since stack test is a synonym for stack build --test I can't see how to accomplish this.
I'm trying to generate some JSON-formatted profiler output for my test-suite using the RTS option -pj (GHC user guide).
I can see where stack places the regular executables, but not the executables for the test-suite.

Haskell Stack doesn't use system Ghc

I'm trying to use Haskell Stack to setup a project but using the stack provided ghc I am having a -fPIC error
GitHub issue
To bypass the fPIC problem I'm trying to use a package manager provided GHC using the 7.10.3 version (stack currently is using 8.0.2)
When I try to force stack to use the systm ghc it simply ignores me.
I've tried to override using /home/user/.stack/config.yaml and {project}/stack.yaml system-ghc : true option... but stack use the 8.0.2 version in the setup.
Am I missing something?
TL;DR
Stack ignore the system-ghc : true option
I'm runnig Sabayon 16
"haskell-primer" is the project name
stack list-dependencies
base 4.9.1.0
ghc-prim 0.5.0.0
haskell-primer 0.1.0.0
integer-gmp 1.0.0.1
rts 1.0
Setting system-ghc: true allows Stack to use the system GHC if it matches the resolver's constraints. It will not force Stack to use the system GHC if it does not match the constraints. If your resolver requires GHC 8 but your system has GHC 7 then Stack will not use your system GHC no matter what value you give system-ghc. Conversely, if system-ghc: false then Stack will never use the system GHC, regardless of whether its version matches.
From the Stack FAQ, emphasis mine:
If you would like stack to use your system GHC installation, use the --system-ghc flag or run stack config set system-ghc --global true to make stack check your PATH for a suitable GHC by default.
Note that stack can only use a system GHC installation if its version is compatible with the configuration of the current project, particularly the resolver setting.

How to have multiple build flavors with stack?

When developing, I want to build everything with -O0 to save time.
But when building the same package on a CI system, I want to use -O.
One option I see would be to have two different stack.yaml files differing in their ghc-options, but then I'd have to make all changes to stack.yaml in two places.
Having an alias for stack --ghc-options=-O0 doesn't work, because I want -O0 to apply only to local packages, not the snapshot, and there's no way to specify that on the command line, from what I know.
Are there any better options?
Actually, stack build --ghc-options=-O0 will apply -O0 to only the local packages, not to the snapshot packages. For more information, see:
https://github.com/commercialhaskell/stack/blob/master/GUIDE.md#ghc-options

Resources