Stack: How to depend on a package during development? - haskell

There is a portion of my application that would be better if published to Hackage. I still don't know exactly what it will look like, so I need to make many changes to it while working on my application.
It's very easy to just create a module in my project and iterate there, but I would like to put it in its own project so it can have its own dependencies.
How can I have my project depend on this separate package during development? It should allow for quick iteration. Here's what I tried so far:
# stack.yaml
packages:
- '.'
- location: ../amqp-worker
# my-application.cabal
library
build-depends:
base >= 4.7 && < 5
, amqp-worker
But I get an error when I build:
$ stack build
cra-reporting-0.1.0.0: build
-- While building package cra-reporting-0.1.0.0 using:
/Users/seanhess/.stack/setup-exe-cache/x86_64-osx/setup-Simple-Cabal-1.24.0.0-ghc-8.0.1 --builddir=.stack-work/dist/x86_64-osx/Cabal-1.24.0.0 build lib:cra-reporting exe:cra-reporting-exe --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
Logs have been written to: /Users/seanhess/projects/simple/cra-reporting/.stack-work/logs/cra-reporting-0.1.0.0.log
Preprocessing library cra-reporting-0.1.0.0...
[8 of 8] Compiling Simple.DataX.Worker ( src/Simple/DataX/Worker.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.0.0/build/Simple/DataX/Worker.o )
/Users/seanhess/projects/simple/cra-reporting/src/Simple/DataX/Worker.hs:6:1: error:
Failed to load interface for ‘Network.Worker’
Perhaps you meant
Network.Socket (needs flag -package-key network-2.6.3.1)
Network.Wreq (from wreq-0.4.1.0)
Network.Socks5 (needs flag -package-key socks-0.5.5)
Use -v to see a list of the files searched for.
The external package seems to build fine if I run stack build from within its project folder.
Both projects are targeting lts-7.3

The above example should work. I attempted this again from scratch and it works fine. The error was due to some kind of build artifact.
If it happened again I would delete .stack-work in the sub-project and rebuild.

Related

"* Missing (or bad) C library: OpenAL32" - from stack build for a haskell project

I have a stack project using Sound.ALUT. The project was building fine on both Windows and Mac before I added sound. (Sound.ALUT is a library layered over OpenAL.) Got thinks working on MacOS but those changes broke the Windows build. Still builds fine on MacOS.
The offending snippit from the "stack build" console log on Windows looks like this
GLUT > [22 of 24] Compiling Graphics.UI.GLUT.Callbacks.Global
GLUT > [23 of 24] Compiling Graphics.UI.GLUT.Callbacks
GLUT > [24 of 24] Compiling Graphics.UI.GLUT
GLUT > copy/register
GLUT > Installing library in C:\sr\snapshots\87ecdd59\lib\x86_64-windows-ghc-8.10.7\GLUT-2.7.0.16-2jeyeunHWey2D1Huuhst8j
GLUT > Registering library for GLUT-2.7.0.16..
OpenAL > configure
OpenAL > Configuring OpenAL-1.7.0.5...
OpenAL > Cabal-simple_Z6RU0evB_3.2.1.0_ghc-8.10.7.exe: Missing dependency on a foreign
OpenAL > library:
OpenAL > * Missing (or bad) C library: OpenAL32
OpenAL > This problem can usually be solved by installing the system package that
OpenAL > provides this library (you may need the "-dev" version). If the library is
OpenAL > already installed but in a non-standard location then you can use the flags
OpenAL > --extra-include-dirs= and --extra-lib-dirs= to specify where it is.If the
OpenAL > library file does exist, it may contain errors that are caught by the C
OpenAL > compiler at the preprocessing stage. In this case you can re-run configure
OpenAL > with the verbosity flag -v3 to see the error messages.
OpenAL >
Progress 10/21
Cleary it can't find OpenAL. I've tried:
installing OpenAL using the Windows installer from https://www.openal.org/downloads
cloning and building openal-soft https://github.com/kcat/openal-soft on windows
setting the --extra-include-dirs and --extra-lib-dirs inslide my stack.yaml to point to where the libraries should be.
I had similar issues getting Sound.ALUT working on the Mac build. In that case building from the sources seemed to solve the problems. I have more trouble building on Windows since the build environment is less familiar. My Windows work has mostly been centered around installing Cygwin and making it look like Unix. But this time, I'm trying to get by on what stack's mingw-w64 provides. I was pulling down things with stack exec -- pacman trying to find something that would install OpenAL as a side effect but no luck.
Some subtleties arise from the fact that stack want to install things in its own self-contained environment. It tries to keep installs localized inside the project directory and not muck around with directories elsewhere. My stack environment looks like this
C:\Users\Mark\slgjff>stack path
snapshot-doc-root: C:\sr\snapshots\aff7b821\doc
local-doc-root: C:\Users\Mark\slgjff\.stack-work\install\f5431f41\doc
local-hoogle-root: C:\Users\Mark\slgjff\.stack-work\hoogle\f5431f41
stack-root: C:\sr
project-root: C:\Users\Mark\slgjff
config-location: C:\Users\Mark\slgjff\stack.yaml
bin-path: .;C:\sr\snapshots\87ecdd59\bin;C:\sr\compiler-tools\x86_64-windows\ghc-8.10.7\bin;C:\Users\Mark\AppData\Local\Programs\stack\x86_64-windows\ghc-8.10.7\bin;C:\Users\Mark\AppData\Local\Programs\stack\x86_64-windows\ghc-8.10.7\mingw\bin;C:\Users\Mark\AppData\Local\Programs\stack\x86_64-windows\msys2-20220503\mingw64\bin;C:\Users\Mark\AppData\Local\Programs\stack\x86_64-windows\msys2-20220503\usr\bin;C:\Users\Mark\AppData\Local\Programs\stack\x86_64-windows\msys2-20220503\usr\local\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Users\Mark\AppData\Roaming\local\bin;C:\Users\Mark\AppData\Local\Microsoft\WindowsApps
programs: C:\Users\Mark\AppData\Local\Programs\stack\x86_64-windows
compiler-exe: C:\Users\Mark\AppData\Local\Programs\stack\x86_64-windows\ghc-8.10.7\bin\ghc-8.10.7.exe
compiler-bin: C:\Users\Mark\AppData\Local\Programs\stack\x86_64-windows\ghc-8.10.7\bin
compiler-tools-bin: C:\sr\compiler-tools\x86_64-windows\ghc-8.10.7\bin
local-bin: C:\Users\Mark\AppData\Roaming\local\bin
extra-include-dirs: C:\Users\Mark\AppData\Local\Programs\stack\x86_64-windows\msys2-20220503\mingw64\include
extra-library-dirs: C:\Users\Mark\AppData\Local\Programs\stack\x86_64-windows\msys2-20220503\mingw64\lib, C:\Users\Mark\AppData\Local\Programs\stack\x86_64-windows\msys2-20220503\mingw64\bin
snapshot-pkg-db: C:\sr\snapshots\87ecdd59\pkgdb
local-pkg-db: C:\Users\Mark\slgjff\.stack-work\install\363b2fd8\pkgdb
global-pkg-db: C:\Users\Mark\AppData\Local\Programs\stack\x86_64-windows\ghc-8.10.7\lib\package.conf.d
ghc-package-path: C:\Users\Mark\slgjff\.stack-work\install\363b2fd8\pkgdb;C:\sr\snapshots\87ecdd59\pkgdb;C:\Users\Mark\AppData\Local\Programs\stack\x86_64-windows\ghc-8.10.7\lib\package.conf.d
snapshot-install-root: C:\sr\snapshots\87ecdd59
local-install-root: C:\Users\Mark\slgjff\.stack-work\install\363b2fd8
dist-dir: .stack-work\dist\274b403a
local-hpc-root: C:\Users\Mark\slgjff\.stack-work\install\363b2fd8\hpc
local-bin-path: C:\Users\Mark\AppData\Roaming\local\bin
ghc-paths: C:\Users\Mark\AppData\Local\Programs\stack\x86_64-windows
I'm not sure the configure needs to be happy. I wish I could construct a checklist run through, but I don't understand enough to write that checklist. Do it need the C source for header files? Don't know. Certainly it must need the .lib and .dlls on the path somewhere. But which path exactly?
My package.yaml -- which works fine on MacOS
ghc-options:
#- -dynamic
- -static
dependencies:
- base >= 4.7 && < 5
- random
- gloss
- gloss-juicy
- ALUT
library:
source-dirs: src
executables:
slgjff-exe:
main: Main.hs
source-dirs: app
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- slgjff
tests:
slgjff-test:
main: Spec.hs
source-dirs: test
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- slgjff
And my stack.yaml -- which also works fine on MacOS
resolver:
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/18/24.yaml
packages:
- .
extra-deps:
- gloss-1.13.2.1#sha256:273d02d30e1896932d45424dab6022a16986c0ed3eef6937776b5f40854ce51c,4075
- JuicyPixels-3.3.6#sha256:03bd32c3a884ac8a32f49334f14695469a710945c84cef9a1e059a79ac416996,3911
- gloss-juicy-0.2.3
And because it may be helpful, here are the includes at top of my program.
import System.Exit ( exitSuccess, exitFailure )
import System.IO ( hPutStrLn, stderr )
import Data.List
import Graphics.Gloss
import Graphics.Gloss.Interface.Pure.Game
import Graphics.Gloss.Interface.IO.Game
import Graphics.Gloss.Data.Vector
import Graphics.Gloss.Juicy
import Control.Monad( when, unless )
import Sound.ALUT as S
I got so desperate I stuck C:/Windows/System32 on the path and almost spilled my drink when the build tried to delete files from C:/Windows/System32. So, I took that out. Running out of ideas.
My sense is that out of inexperience with ghc on Windows, I must be missing something that would be really obvious to someone with more experience. Thanks in advance for any insights.
P.S. I created a stripped down version of the project and put it up on github at https://github.com/markcornwell/alut-glitch
See the README for the project for instruction on how to reproduce the error.

haskell fail to import Data.List module

|
4 | import Data.List.Split
| ^^^^^^^^^^^^^^^^^^^^^^
-- While building package myproj-0.1.0.0 using:
Process exited with code: ExitFailure 1
I got this error, how can i import the module to haskell file?
I got this error when compile in vs code or when debugging
Second error in file after compile with stack build, i already added Split in cabal build depends
Cabal file
Building all executables for `myproj' once. After a successful build of all of them, only specified executables will be rebuilt.
myproj> configure (exe)
Warning: myproj.cabal:21:10: Tabs used as indentation at 21:10
Configuring myproj-0.1.0.0...
myproj> build (exe)
Preprocessing executable 'myproj' for myproj-0.1.0.0..
Building executable 'myproj' for myproj-0.1.0.0..
<no location info>: error:
output was redirected with -o, but no output will be generated
because there is no Main module.
First you need to find out in which package the module is included.
https://hoogle.haskell.org/?hoogle=Data.List.Split
So you need the split package. Put in the build-depends of your myproj.cabal file (or package.yaml, if you use hpack or stack)
split >=0.2 && <0.3
(the version bounds are optional, but it's recommended to fix the x.y when in doubt)
Then, at next build, cabal or stack will pull in the required dependencies and thus make the module available.

Haskell there are files missing in the QuickCheck-2.11.3 package

I tried running my program which uses Haskell QuickCheck via ghc MyProgramm.hs , but received the following error:
$ ghc Ex2.hs
[1 of 1] Compiling Ex2 ( Ex2.hs, Ex2.o )
Ex2.hs:21:1: error:
Could not find module ‘Test.QuickCheck’
There are files missing in the ‘QuickCheck-2.11.3’ package,
try running 'ghc-pkg check'.
Use -v to see a list of the files searched for.
|
21 | import Test.QuickCheck (
| ^^^^^^^^^^^^^^^^^^^^^^^^...
I installed stack, ran stack update and stack install QuickCheck without issue but the error persisted. Then, I ran cabal install QuickCheck and got the following errors:
$ cabal install QuickCheck
Resolving dependencies...
Configuring QuickCheck-2.12.4...
Building QuickCheck-2.12.4...
Failed to install QuickCheck-2.12.4
Build log ( /home/username/.cabal/logs/ghc-8.4.3/QuickCheck-2.12.4-3d2YDDqfPBn4BfmTJbpJXK.log ):
cabal: Entering directory '/tmp/cabal-tmp-9133/QuickCheck-2.12.4'
Configuring QuickCheck-2.12.4...
Preprocessing library for QuickCheck-2.12.4..
Building library for QuickCheck-2.12.4..
[ 1 of 16] Compiling Test.QuickCheck.Exception ( Test/QuickCheck/Exception.hs, dist/build/Test/QuickCheck/Exception.o )
[ 2 of 16] Compiling Test.QuickCheck.Random ( Test/QuickCheck/Random.hs, dist/build/Test/QuickCheck/Random.o )
Test/QuickCheck/Random.hs:10:1: error:
Could not find module ‘System.Random’
There are files missing in the ‘random-1.1’ package,
try running 'ghc-pkg check'.
Use -v to see a list of the files searched for.
|
10 | import System.Random
| ^^^^^^^^^^^^^^^^^^^^
Test/QuickCheck/Random.hs:11:1: error:
Could not find module ‘System.Random.TF’
There are files missing in the ‘tf-random-0.5’ package,
try running 'ghc-pkg check'.
Use -v to see a list of the files searched for.
|
11 | import System.Random.TF
| ^^^^^^^^^^^^^^^^^^^^^^^
Test/QuickCheck/Random.hs:12:1: error:
Could not find module ‘System.Random.TF.Gen’
There are files missing in the ‘tf-random-0.5’ package,
try running 'ghc-pkg check'.
Use -v to see a list of the files searched for.
|
12 | import System.Random.TF.Gen(splitn)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cabal: Leaving directory '/tmp/cabal-tmp-9133/QuickCheck-2.12.4'
cabal: Error: some packages failed to install:
QuickCheck-2.12.4-3d2YDDqfPBn4BfmTJbpJXK failed during the building phase. The
exception was:
ExitFailure 1
However, I already have the arch packages haskell-random, haskell-tf-random and haskell-mwc-random installed. Does anybody know how to fix this?
Edit: I also ran cabal install random --reinstall.
Problem
On Archlinux as of 2022-09-17, pacman -S ghc cabal-install will install
system packages that provide only dynamic files (.so, .dyn_hi) in
installed packages inside /usr/lib/ghc-*; static files (.a, .hi) are (for
the most part) missing. However, the default cabal configuration enables static file
building. Unfortunately, upstream cabal-install doesn't track whether or not
static files are available inside installed packages. It just assumes they
are, and when they are gone, it fails with errors such as you have found:
[1 of 1] Compiling Main ( Main.hs, ../setup.dist/work/depender/dist/build/depender/depender-tmp/Main.o )
Main.hs:3:1: error:
Could not find module `Dynamic'
There are files missing in the `dynamic-1.0' package,
try running 'ghc-pkg check'.
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
| import qualified Dynamic (number)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Workaround
A quick workaround just to get up and running quickly is to disable static file
building, which is by default enabled. (Note that trying to pass package-local
flags to disable static file with e.g. --enable-shared --enable-executable-dynamic --disable-library-vanilla (which is how most if
not all current Archlinux Haskell packages seem to build packages, e.g. with
https://github.com/archlinux/svntogit-community/blob/master/haskell-scientific/trunk/PKGBUILD)
building using cabal-install may be ignored due to another, related bug; but
~/.cabal/config is a safe bet.) You may do so by adding 3 lines to
~/.cabal/config in the appropriate location:
library-vanilla: False
shared: True
executable-dynamic: True
(Alternatively, consider using alternative tools like stack.)
More complete solution
For a more long-term solution, one option involves 2 pieces: 1) one or more
system packages that provide all types of build artifacts, static and dynamic,
for the base, foundational packages (from GHC and cabal-install), at least as an option besides dynamic-only packages (secondary Haskell packages are optional,
since cabal-install can rebuild these with needed build artifacts (static or
dynamic)), and 2) patching cabal-install (and ghc-pkg, which can handle .conf
files recording information about installed packages) to track whether static
files are available, and to be aware of these when resolving dependencies so
that cabal-install knows when to prefer rebuild a source package with needed
build artifact configuration over an already installed package that doesn't
provid required build artifacts.
There is a merge request (I submitted) that provides such a patchset, called
fix-dynamic-deps, at https://github.com/haskell/cabal/pull/8461. For users
running into exactly the problem that you described (myself included), I also
created an AUR package that provides both pieces based on GHC 9.4.2 with Cabal
3.9.0.0 that includes my patchset (there is a mirror at
https://github.com/bairyn/ghc-cabal-arts.) It provides ghc and
cabal-install but includes both of these pieces.
Further reading
Here are a few more resources I wrote on or are related to this bug:
https://wiki.archlinux.org/index.php?title=Haskell&diff=745459&oldid=738269#Troubleshooting
https://github.com/haskell/cabal/pull/8461
https://github.com/bairyn/ghc-cabal-arts
https://github.com/bairyn/cabal/tree/fix-dynamic-builds
Even though I have a main = do and couldn't get it working that way, I was able to run my QuickCheck test as follows:
To run a quickCheck, first load your program with:
$ ghci MyProg.hs
Then to run the quickCheck, find the test you want to run, then run it with:
$ quickCheck my_quick_check

Haskell Yesod problems

someone could help me?! I'm working in a Haskell Yesod site for college on a C9 workspace, I've already installed by command Yesod and update cabal, but when I try "stack build" command, this miserable error message appears:
$ stack build
aulahaskell-0.0.0: build (lib + exe)
Preprocessing library aulahaskell-0.0.0...
[ 7 of 13] Compiling Handler.Cliente ( src/Handler/Cliente.hs, .stack-work/dist/x86_64-linux/Cabal-1.24.2.0/build/Handler/Cliente.o )
/home/ubuntu/workspace/web2017/src/Handler/Cliente.hs:10:1: error:
Failed to load interface for ‘Network.HTTP.Types.Status’
It is a member of the hidden package ‘http-types-0.9.1’.
Perhaps you need to add ‘http-types’ to the build-depends in your .cabal file.
Use -v to see a list of the files searched for.
-- While building package aulahaskell-0.0.0 using:
/home/ubuntu/.stack/setup-exe-cache/x86_64-linux/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-linux/Cabal-1.24.2.0 build lib:aulahaskell exe:aulahaskell --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
Seriously, I tried a bunch of things to fix it, but nothing is working =S
Just read the error message carefully:
Failed to load interface for ‘Network.HTTP.Types.Status’
It is a member of the hidden package ‘http-types-0.9.1’.
Perhaps you need to add ‘http-types’ to the build-depends in your .cabal file.
Use -v to see a list of the files searched for.
The line Perhaps you need to add ‘http-types’ to the build-depends in your .cabal file tells you what to do: You must add http-types to the build-depends: section of the library aulahaskell in your cabal file.
If this does not help, please post your cabal file.
How did you start the yesod project? It's recommended to do:
stack new my-yesod-project yesod-(your database here)
cd my-yesod-project
stack build
Thank you, guys! It was a problem on how I was starting the project, some files weren't installed on my workspace, so I delete the files, reinstall Yesod and cabal, create another new version after following this steps: https://www.yesodweb.com/page/quickstart

Error installing the shuffle library with stack

Using stack 1.2.0 and LTS 7.0 I'm getting the following error installing the shuffle library:
$ cabal get shuffle
$ cd shuffle-0.1.3.3
$ stack build
...
/tmp/shuffle-0.1.3.3/Setup.hs:2:1: error:
Failed to load interface for ‘Distribution.Simple.UUAGC’
Perhaps you meant
Distribution.Simple.UHC (from Cabal-1.24.0.0)
Distribution.Simple.GHC (from Cabal-1.24.0.0)
Distribution.Simple.JHC (from Cabal-1.24.0.0)
Use -v to see a list of the files searched for.
/tmp/shuffle-0.1.3.3/Setup.hs:3:1: error:
Failed to load interface for ‘UU.UUAGC’
Use -v to see a list of the files searched for.
-- While building package shuffle-0.1.3.3 using:
/usr/local/bin/ghc --make -odir /tmp/shuffle-0.1.3.3/.stack-work/dist/x86_64-linux/Cabal-1.24.0.0/setup -hidir /tmp/shuffle-0.1.3.3/.stack-work/dist/x86_64-linux/Cabal-1.24.0.0/setup -i -i. -package=Cabal-1.24.0.0 -clear-package-db -global-package-db -package-db=/home/asr/.stack/snapshots/x86_64-linux/lts-7.0/8.0.1/pkgdb /tmp/shuffle-0.1.3.3/Setup.hs -o /tmp/shuffle-0.1.3.3/.stack-work/dist/x86_64-linux/Cabal-1.24.0.0/setup/setup
Process exited with code: ExitFailure 1
I'm using the following stack.yaml file:
resolver: lts-7.0
# Local packages, usually specified by relative directory name
packages:
- '.'
extra-deps:
- logict-state-0.1.0.2
- pqueue-1.3.1.1
- uhc-util-0.1.6.6
- uuagc-0.9.52.1
- uuagc-cabal-1.0.6.0
- uulib-0.9.22
Do I need to add/change something in the library or in stack.yaml? (I had no problems using cabal-install).
I was able to get this to work by adding the following to stack.yaml:
explicit-setup-deps:
shuffle: true
For more information, see: https://docs.haskellstack.org/en/stable/yaml_configuration/#explicit-setup-deps
It appears that this package requires you to have installed uuagc-cabal to build it. Starting after Cabal-1.23 these kinds of package dependencies for Setup.hs files can be captured in the custom-setup section of a cabal file.
There are tickets about this functionality for stack that seem to be interlinked from here:
Setup.hs cannot use local snapshot dependencies WAS stack failing to resolve local dependencies of multiple package project #897

Resources