Stack: Passing cabal flags?

Created on 5 Jun 2015  路  11Comments  路  Source: commercialhaskell/stack

E.g. -fdev for yesod apps. Can I do this?

need confirmation

Most helpful comment

stack build gtk --flag gtk:have-quartz-gtk

All 11 comments

I implemented this on Friday, it's the --flag option:

  --flag PACKAGE:[-]FLAG   Override flags set in stack.yaml (applies to local
                           packages and extra-deps)

great success

Can someone give an example of what PACKAGE would be? What would be the stack equivalent of this cabal command:

cabal install gtk -fhave-quartz-gtk

stack build gtk --flag gtk:have-quartz-gtk

I can't see it being passed through.

stack build gtk --flag gtk:have-quartz-gtk gives me an error:

~ $ stack build gtk --flag gtk:have-quartz-gtk
Run from outside a project, using implicit global config
Using resolver: lts-3.1 from global config file: /Users/darren/.stack/global/stack.yaml
Invalid flag specification:
- Package 'gtk' not found (specified on command line)

I'm trying to install threadscope (which requires gtk) on a mac, using stack. The error below is what happens if -fhave-quartz-gtk isn't supplied, which is why I suspect it isn't making it through.

stack build gtk --flag *:have-quartz-gtk
Run from outside a project, using implicit global config
Using resolver: lts-3.1 from global config file: /Users/darren/.stack/global/stack.yaml
gtk-0.13.9: configure
gtk-0.13.9: build

--  While building package gtk-0.13.9 using:
      /Users/darren/.stack/programs/x86_64-osx/ghc-7.10.2/bin/runhaskell -package=Cabal-1.22.4.0 -clear-package-db -global-package-db -package-db=/Users/darren/.stack/snapshots/x86_64-osx/lts-3.1/7.10.2/pkgdb/ /var/folders/w_/hxywk7kd52g2jjvqdtw6qx5w0000gn/T/stack75520/gtk-0.13.9/Setup.hs --builddir=.stack-work/dist/x86_64-osx/Cabal-1.22.4.0/ build --ghc-options -hpcdir .stack-work/dist/x86_64-osx/Cabal-1.22.4.0/hpc/.hpc/ -ddump-hi -ddump-to-file
    Process exited with code: ExitFailure 1
    Logs have been written to: /Users/darren/.stack/global/.stack-work/logs/gtk-0.13.9.log

This should probably transition to a new issue. Please include the stack version you're using.

I comment on this issue because I think it is the most appropriate one instead of creating a new one.

stack build --flag package:flag works perfectly but when you want to run a binary with a specific flag activated, stack run package-exe --flag package:flag does not work and reports that --flag is not available:

Invalid option `--flag'

Usage: stack run [-- ARGS (e.g. stack run -- file.txt)]
                 [--[no-]ghc-package-path] [--[no-]stack-exe] [--package ARG]
                 [--rts-options RTSFLAG] [--cwd DIR] [--help]
  Build and run an executable. Defaults to the first available executable if
  none is provided as the first argument.

Is this expected? how should I proceed if I want to pass a cabal flag when executing a binary and I want it to be given on the command line (this means that writing it in stack.yaml is not an option for me)?

@Jasagredo I realize it's probably not the answer you're hoping for, but how about just making this a two-step process using the current functionality?

$ stack build --flag package:flag && stack run
                                  ^^^^^^^^^^^^

@mattaudesse
That approach works. For now I can stick to that.
Though with some guidance that flag option could be added to stack run if approved.
Thanks.

@Jasagredo I realize it's probably not the answer you're hoping for, but how about just making this a two-step process using the current functionality?

$ stack build --flag package:flag && stack run
                                  ^^^^^^^^^^^^

For me stack run rebuilds the binary, so I use stack exec <binary> instead.

Was this page helpful?
0 / 5 - 0 ratings