commercialhaskell / stack

The Haskell Tool Stack
http://haskellstack.org
BSD 3-Clause "New" or "Revised" License
3.95k stars 842 forks source link

Stack script fails to use Pandoc library #6616

Open tonicebrian opened 5 days ago

tonicebrian commented 5 days ago

General summary/comments (optional)

Stack used as a script fails to find pandoc library although it has been downloaded and compiled.

Steps to reproduce

Just run this script:

#!/usr/bin/env stack
{- stack script --resolver lts-21.25 --package pandoc -}

import Prelude
import Text.Pandoc

main :: IO ()
main = putStrLn "Pandoc detected"

Expected

I would expect the "Pandoc detected" printed in screen

Actual

The script fails to compile with:

/home/cebrian/borralodedentro/example.hs:5:1: error:
    Could not load module ‘Text.Pandoc’
    It is a member of the hidden package ‘pandoc-3.0.1’.
    You can run ‘:set -package pandoc’ to expose it.
    (Note: this unloads all the modules in the current scope.)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
5 | import Text.Pandoc
  | ^^^^^^^^^^^^^^^^^^

Stack version

❯ stack --version
Version 2.15.7, Git revision 75bb479f04755c1daf91ec8f445e17e2ba2ab7a3 x86_64 hpack-0.36.0

Method of installation

Platform

Linux Ubuntu 22.04

philderbeast commented 5 days ago

This doesn't happen with the latest resolver.

   #!/usr/bin/env stack
-  {- stack script --resolver lts-21.25 --package pandoc -}
+  {- stack script --resolver nightly-2024-06-22 --package pandoc -}

   import Prelude
   import Text.Pandoc

   main :: IO ()
   main = putStrLn "Pandoc detected"
$ ./example.hs
Pandoc detected
tonicebrian commented 5 days ago

For me it doesn't work neither with lts-21.25 nor lts-22.26. I cannot go for nightly because that would involve changing the GHC compiler. Should I file an issue in LTS?

mpilgrem commented 5 days ago

@tonicebrian, thanks for reporting. I'm looking into this.

mpilgrem commented 3 days ago

Related discussion: https://discourse.haskell.org/t/stack-script-fails-to-find-pandoc/9817/9

@tonicebrian, I think this is - at least, in part - an issue with GHC's runghc, and I have opened: https://gitlab.haskell.org/ghc/ghc/-/issues/25035.

My reasoning is that (on Windows):

❯ stack --snapshot lts-21.21 exec -- runghc -hide-all-packages -package=base -package=pandoc example1.hs

example1.hs:6:1: error:
    Could not load module ‘Text.Pandoc’
    It is a member of the hidden package ‘pandoc-3.0.1’.
    You can run ‘:set -package pandoc’ to expose it.
    (Note: this unloads all the modules in the current scope.)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
6 | import Text.Pandoc
  | ^^^^^^^^^^^^^^^^^^

shoud not be a possible output of runghc. The very purpose of -package=pandoc is to expose pandoc.

(This is not Linux-specific but, oddly, GHC 9.4.7 works on Linux, fails on Windows and GHC 9.4.8 fails on Linux, works on Windows - all with pandoc-3.0.1.)