Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document instructions for scripting in Haskell with Cabal 3.0 #6066

Closed
elliottslaughter opened this issue Jan 14, 2020 · 4 comments
Closed

Comments

@elliottslaughter
Copy link

Cabal 3.0 changes the default install subcommand to the new-style installation (aka v2-install in earlier versions). The new-style installation seems not to register any installed packages with the GHC package database. As a result, you can't write Pandoc scripts in Haskell and build them with ghc --make; you would have to set up a full Cabal project for each script, which is rather a drag.

Is this worth documenting somewhere? Pandoc users may want to be aware that they need to use v1- style subcommands in order to get to a working setup for scripting.


The only way I've been able to make this work is to go back to the v1-install subcommand:

$ cabal v1-install pandoc
$ ghc-pkg list pandoc
/Users/elliott/.brew/Cellar/ghc/8.8.1/lib/ghc-8.8.1/package.conf.d
    (no packages)
/Users/elliott/.ghc/x86_64-darwin-8.8.1/package.conf.d
    pandoc-2.9.1.1
$ ghc --make behead.hs 
[1 of 1] Compiling Main             ( behead.hs, behead.o )
Linking behead ...

Whereas whenever I build with any of the new-style commands, I can't build scripts afterwards.

$ cabal install --lib pandoc
$ ghc-pkg list pandoc
.../ghc/8.8.1/lib/ghc-8.8.1/package.conf.d
    (no packages)
$ ghc --make behead.hs 
Loaded package environment from /Users/elliott/.ghc/x86_64-darwin-8.8.1/environments/default
[1 of 1] Compiling Main             ( behead.hs, behead.o )

behead.hs:4:1: error:
    Ambiguous module name ‘Text.Pandoc’:
      it was found in multiple packages: pandoc-2.9.1.1 pandoc-2.9.1.1
  |
4 | import Text.Pandoc
  | ^^^^^^^^^^^^^^^^^^

And similarly with --global:

$ cabal install --global --lib pandoc
$ ghc-pkg list pandoc
.../ghc/8.8.1/lib/ghc-8.8.1/package.conf.d
    (no packages)
$ ghc --make behead.hs 
Loaded package environment from /Users/elliott/.ghc/x86_64-darwin-8.8.1/environments/default
[1 of 1] Compiling Main             ( behead.hs, behead.o )

behead.hs:4:1: error:
    Ambiguous module name ‘Text.Pandoc’:
      it was found in multiple packages: pandoc-2.9.1.1 pandoc-2.9.1.1
  |
4 | import Text.Pandoc
  | ^^^^^^^^^^^^^^^^^^

I'm not sure what exactly is wrong with the new-style subcommands. --global sounds like it should do what I want, but it doesn't seem to. Other users of cabal seem to be having similar issues, see e.g. haskell/cabal#6478.

Note: To be sure I'm getting a clean environment, I run rm -rf ~/.cabal ~/.ghc/x86_64-darwin-8.8.1 && cabal user-config update && cabal update prior to each attempt.

@elliottslaughter
Copy link
Author

Ok, thanks to some discussion on the other issue, I found a set of new-style Cabal commands that seems to work:

cabal v2-install pandoc
cabal v2-install --lib pandoc
cabal v2-install --lib pandoc-types
ghc -package-env=default --make behead.hs

You need the second line to expose Pandoc as a library, and the third because otherwise any dependencies of pandoc-the-library are marked as hidden. (And you need to repeat the third line for any other dependencies you intend to use.)

I still think it's worth some amount of documentation to guide Pandoc users in the right direction, though I guess there's some question whether that should be v1-* or v2-* commands.

@jgm
Copy link
Owner

jgm commented Jan 15, 2020

thanks a lot. I was wondering about this myself.

@jgm
Copy link
Owner

jgm commented Jan 15, 2020

See if the changes in ebf413c help.

@elliottslaughter
Copy link
Author

Yes, I those instructions look good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants