Using stack to provide a consistent build environment for something that is not a cabal package?

12 views
Skip to first unread message

Brent Yorgey

unread,
Feb 11, 2018, 11:14:27 PM2/11/18
to haskell-stack
Hi all,

I have a specific goal and I'm hoping you can help me figure out the best way to accomplish it using stack (or perhaps even using other tools if they make more sense).  I am working on a LaTeX document which contains embedded Haskell code for generating diagrams (https://github.com/byorgey/series-formelles).  When the LaTeX file is compiled, a certain executable (diagrams-builder-pgf) needs to be present, which in turn uses the GHC API to compile and run the code embedded in the LaTeX document. In order for this to work, various libraries (diagrams-lib, diagrams-pgf, palette, etc...) need to be present in the GHC package database; I also need a specific version of GHC.  Getting this environment set up properly, with compatible versions of everything, can be a pain; I would like to create a script that others can run in order to reproducibly get a proper environment set up to be able to build the LaTeX document.

Stack seems like the obvious choice but I have run into a few difficulties trying to get it set up: first of all, as you can tell from my description above, I do not actually have a Haskell package.  There is no Haskell library or executable I am trying to build. But as far as I can tell, a stack project is supposed to contain one or more Haskell packages.  I could try to make a "fake" Haskell package whose dependencies describe the things I want to end up being present in the package DB but I am not sure of the best way to do this, and it seems rather kludgy.  Really what I want is just a sandbox, but I can't really use a cabal sandbox because as far as I know that will just use whatever GHC version someone has installed, and I need a particular GHC version.  Secondly, in order to install the diagrams-builder-pgf executable, I need to pass a certain flag to the diagrams-builder package when it is built, but I'm not clear on exactly how to do this using stack.

So, what do you think?  Is there a good way to do this with stack?  Or should I look at some other way to get this set up?  Thanks in advance for any ideas or advice.  I'm happy to answer questions or provide further information.

-Brent

Michael Snoyman

unread,
Feb 12, 2018, 4:42:49 AM2/12/18
to Brent Yorgey, haskell-stack
IIUC, you're looking to define a `stack.yaml` file which will set up all of the packages and settings, and then have a script you run to tell Stack to build the appropriate packages. That sounds fine; I think the pieces you're missing are:

* In order to say "I have no local packages," include the line `packages: []` in your `stack.yaml`
* You can use the `flags` section in your `stack.yaml` to override default cabal flags, see https://docs.haskellstack.org/en/stable/yaml_configuration/#flags

--
You received this message because you are subscribed to the Google Groups "haskell-stack" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-stack+unsubscribe@googlegroups.com.
To post to this group, send email to haskel...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/haskell-stack/559b2f4d-bfa4-4b4e-9750-32de4d9a4a7c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Neil Mitchell

unread,
Feb 12, 2018, 4:46:35 AM2/12/18
to Michael Snoyman, Brent Yorgey, haskell-stack
Brent, I've done this before a lot, it's a great workflow. Just stack
exec and the world works as you would hope. As an example I have
instructions for compiling GHC here,
http://neilmitchell.blogspot.co.uk/2016/03/compiling-ghc-on-windows.html
- only at the end is the fact I'm using a haskell package even
mentioned.

Thanks, Neil
>> email to haskell-stac...@googlegroups.com.
>> To post to this group, send email to haskel...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/haskell-stack/559b2f4d-bfa4-4b4e-9750-32de4d9a4a7c%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "haskell-stack" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to haskell-stac...@googlegroups.com.
> To post to this group, send email to haskel...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/haskell-stack/CAKA2Jg%2BGYmOyERo%3Dq_FqH7r_AzbfB7nMwt10xLt_e1a7kWdE6g%40mail.gmail.com.

Brent Yorgey

unread,
Feb 13, 2018, 9:52:01 AM2/13/18
to haskell-stack
Aha, thanks, this works great!  Indeed, I was missing those two pieces, and there was also one other slight misconception I had to get past: it turns out that I implicitly thought 'stack build' meant 'do whatever is in the local stack.yaml', but I guess it actually means 'build the package in the working directory (using stack.yaml to guide how that should happen)'.  So when I put 'packages: []' and tried to 'stack build' of course I got an error saying that it could not find a package.  But once I figured out that I have to say 'stack build package1 package2 ...' it works great.  Thanks again for the help --- and also thanks to Neil for the example.

-Brent
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-stac...@googlegroups.com.

Michael Snoyman

unread,
Feb 13, 2018, 10:04:09 AM2/13/18
to Brent Yorgey, haskell-stack
No problem, glad it worked. One clarification: `stack build` without any explicit targets means "all local packages." `stack build .` means "everything in the current directory and subdirectories." It's a subtle point, but does make a difference. All of these rules are covered in the build command docs page:


To unsubscribe from this group and stop receiving emails from it, send an email to haskell-stack+unsubscribe@googlegroups.com.

To post to this group, send email to haskel...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages