I created the recommended build.sh file from the "Running" section of the Shake manual:
#!/bin/sh
mkdir -p _shake
ghc --make Shakefile.hs -v -rtsopts -threaded -with-rtsopts=-I0 -outputdir=_shake -o _shake/build && _shake/build "$#"
but running that script gives the following error:
[1 of 1] Compiling Main ( Shakefile.hs, _shake/Main.o )
Shakefile.hs:1:1: error:
Could not find module ‘Development.Shake’
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
1 | import Development.Shake
| ^^^^^^^^^^^^^^^^^^^^^^^^
Shakefile.hs:2:1: error:
Could not find module ‘Development.Shake.Command’
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
2 | import Development.Shake.Command
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Shakefile.hs:3:1: error:
Could not find module ‘Development.Shake.FilePath’
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
3 | import Development.Shake.FilePath
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Shakefile.hs:4:1: error:
Could not find module ‘Development.Shake.Util’
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
4 | import Development.Shake.Util
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I did cabal v2-install shake --installpath=bin, but still get the same error afterwards. I also tried bin/shake but get the same error.
I tried adding -package shake to the ghc command in the build.sh, but get this error:
<command line>: cannot satisfy -package shake
(use -v for more information)
Adding -v as suggested gives this error:
Glasgow Haskell Compiler, Version 8.8.4, stage 2 booted by GHC version 8.8.3
Using binary package database: /Users/avh4/.ghcup/ghc/8.8.4/lib/ghc-8.8.4/package.conf.d/package.cache
package flags [-package shake{package shake True ([])}]
loading package database /Users/avh4/.ghcup/ghc/8.8.4/lib/ghc-8.8.4/package.conf.d
<command line>: cannot satisfy -package shake
(use -v for more information)
What is the correct way to use Shake without Haskell stack (preferably using only ghc 8.8 installed with ghcup and/or with cabal-install v2 commands)?
I figured out I need to use the --lib flag with cabal new-install otherwise only the shake binary gets installed.
After running cabal new-install --lib shake, the original build.sh script with the addition of -package shake to the ghc arguments now works! And runhaskell -package shake Shakefile.hs also works now.
Related
I'm too beginner in Haskell and I wrote a simple program that imports Data.List.Ordered, when I run the program this error appears:
test.hs:3:1: error:
Could not find module `Data.List.Ordered'
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
3 | import Data.List.Ordered ( isSorted, nub )
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Then I tired to download the package using the following command:
cabal install --lib --package-env . ordered
but It didn't work as well
C:\WINDOWS\system32>cabal install --lib --package-env . ordered
Resolving dependencies...
Build profile: -w ghc-8.10.7 -O1
In order, the following will be built (use -v for more details):
- ordered-0.1 (lib:ordered) (requires build)
Starting ordered-0.1 (all, legacy fallback)
Building ordered-0.1 (all, legacy fallback)
Failed to build ordered-0.1.
Build log (
C:\Users\reema\Desktop\Haskell\cabal\logs\ghc-8.10.7\ordered-0.1-e612131c8de88f5b62dca269575aa8273bdac512.log
):
Preprocessing library for ordered-0.1..
Building library for ordered-0.1..
[1 of 3] Compiling Data.Poset.Internal ( Data\Poset\Internal.hs, dist\build\Data\Poset\Internal.o )
Data\Poset\Internal.hs:32:10: error:
* No instance for (Semigroup PosetOrd)
arising from the superclasses of an instance declaration
* In the instance declaration for `Monoid PosetOrd'
|
32 | instance Monoid PosetOrd where
| ^^^^^^^^^^^^^^^
cabal-3.6.2.0.exe: Failed to build ordered-0.1. See the build log above for details.
These versions I'm using:
GHCi, version 8.10.7
Cabal, version3.6.2.0
vector module has been installed by "cabal install vector"
bash-3.2$ ghc-pkg list -f $HOME/.cabal/store/ghc-9.2.1/package.db
/Users/gcolpitts/.cabal/store/ghc-9.2.1/package.db
primitive-0.7.3.0
vector-0.12.3.1
but the compiler can't find it:
$ ghc prob214ff.hs
[1 of 1] Compiling Main ( prob214ff.hs, prob214ff.o )
prob214ff.hs:14:1: error:
Could not find module ‘Data.Vector’
Perhaps you meant Data.Functor (from base-4.16.0.0)
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
14 | import Data.Vector
Thx #n. 1.8e9-where's-my-share !
ghc -package-db $HOME/.cabal/store/ghc-9.2.1/package.db prob214ff.hs
solves my problem although it is a regression from previous versions of ghc which didn't require the use of the -package-db option.
I'd love to use GHC_PACKAGE_PATH but I can't see how to make that work. Sec 5.9.5 of the ghc users guide is confusing. It states "A package database is where the details about installed packages are stored. It is a directory, usually called package.conf.d." i.e. not the package.db file that I gave with -package-db on the command line. But where is the package.conf.db directory with info on the vector package that I installed with cabal?
"ghc-pkg list" references /usr/local/lib/ghc-9.2.1/lib/package.conf.d but the output of the command doesn't list the vector package I installed.
"ghc-pkg list -f $HOME/.cabal/store/ghc-9.2.1/package.db" does list the vector package in it's output but doesn't tell me a package.conf.d directory that knows about the vector package.
This is a bit fiddly with cabal version 2. Installing packages no longer really makes sense (despite the cabal install still existing...). Instead you will probably find it easiest to create a cabal package instead, for example:
$ mkdir my-package
$ cd my-package
$ cabal init
<Edit my-package.cabal and add vector to the build-depends line>
<Put the contents of prob214ff.hs in app/Main.hs instead>
$ cabal run
This will be fixed in 9.2.2, see https://gitlab.haskell.org/ghc/ghc/-/issues/20660#note_391573
With the release of cabal-3, the packages from Hackage are installed in a new location that the compiler ghc and ghc-pkg know nothing about.
In other words, packages are installed but not registered for ghc. Ghci, ghc, ghc-pkg cannot work.
For example,
cabal install safe --lib
Create file t1.hs
import Safe
t1 = tailMay [1,2,3]
Let's try:
> ghci t1.hs
GHCi, version 8.10.2: https://www.haskell.org/ghc/:? for help
[1 of 1] Compiling Main (t1.hs, interpreted)
t1.hs: 1: 1: error:
Could not find module `Safe '
Use -v (or `: set -v` in ghci) to see a list of the files searched for.
|
1 | import Safe
| ^^^^^^^^^^^
Failed, no modules loaded.
This bug is described here
https://github.com/haskell/cabal/issues/6262
and here
https://gitlab.haskell.org/ghc/ghc/-/issues/17341
I use as a temporary solution setting a system variable
GHC_PACKAGE_PATH=C:\Users\me\AppData\Roaming\cabal\store\ghc-8.10.2\package.db;
(Windwos 10, haskell-dev by chocolatey)
via
On Windows, packages installed with cabal seem to be unavailable in ghc/ghci
but with updates I will have to manually change this system variable.
Are there any more elegant solutions to this problem?
P.S. Unfortunately, this solution (via GHC's environment variable GHC_PACKAGE_PATH) is incompatible with Cabal :(
https://github.com/haskell/cabal/issues/1944
One way to achieve this is to use the --env flag to make the libraries available to GHC whenever you are in the current directory:
~ $ mkdir /tmp/foo
~ $ cd /tmp/foo
/tmp/foo $ cabal install safe --lib --env .
Resolving dependencies...
Build profile: -w ghc-8.8.3 -O1
In order, the following will be built (use -v for more details):
- safe-0.3.19 (lib) (requires build)
Configuring library for safe-0.3.19..
Preprocessing library for safe-0.3.19..
Building library for safe-0.3.19..
…
> Installing library in /home/jojo/.cabal/store/ghc-8.8.3/incoming/new-4056/home/jojo/.cabal/store/ghc-8.8.3/safe-0.3.19-92fbaef88124b4508ce447f6245bc793f7a1748247ae68d10e449150df1069af/lib
t1.hs
/tmp/foo $ cat > t1.hs
import Safe
t1 = tailMay [1,2,3]
/tmp/foo $ ls -a
. .. .ghc.environment.x86_64-linux-8.8.3 t1.hs
/tmp/foo $ ghci t1.hs
GHCi, version 8.8.3: https://www.haskell.org/ghc/ :? for help
Loaded package environment from /tmp/foo/.ghc.environment.x86_64-linux-8.8.3
[1 of 1] Compiling Main ( t1.hs, interpreted )
Ok, one module loaded.
*Main>
Note that you probably shouldn’t do this in a directory where you actually have a foo.cabal file. See the documentation of cabal v2-install for details.
Working with GHC_ENVIRONMENT is better:
setx GHC_ENVIRONMENT C:\Users\me\.ghc\x86_64-mingw32-8.10.2\environments\default
it helps for ghc and ghci.
After, in C:\Users\me\AppData\Roaming\cabal\config we should add
package-db: C:\Users\me\AppData\Roaming\cabal\store\ghc-8.10.2\package.db
it helps for cabal.
Unfortunately, ghc-pkg still has problem and works with such flag:
ghc-pkg list --user-package-db="C:\Users\me\AppData\Roaming\cabal\store\ghc-8.10.2\package.db"
For Linux the steps are similar.
I tried to create a Nix-style local build (v2-build) project on Cabal 3.0.
But several development tools (flycheck-haskell and doctest) don't work.
They worked on new-build project on Cabal 2.4.
Error message says they cannot find dependencies, as far as I read.
$ cabal v2-clean
$ cabal v2-build
$ cabal v2-test
Build profile: -w ghc-8.8.1 -O1
In order, the following will be built (use -v for more details):
- hstest9-0.1.0.0 (test:doctestd) (first run)
Configuring test suite 'doctestd' for hstest9-0.1.0.0..
Preprocessing test suite 'doctestd' for hstest9-0.1.0.0..
Building test suite 'doctestd' for hstest9-0.1.0.0..
[1 of 1] Compiling Main ( test/doctest-driver.hs, /Users/user/work/hstest9/dist-newstyle/build/x86_64-osx/ghc-8.8.1/hstest9-0.1.0.0/t/doctestd/build/doctestd/doctestd-tmp/Main.o )
Linking /Users/user/work/hstest9/dist-newstyle/build/x86_64-osx/ghc-8.8.1/hstest9-0.1.0.0/t/doctestd/build/doctestd/doctestd ...
Running 1 test suites...
Test suite doctestd: RUNNING...
/Users/user/work/hstest9/src/MyLib.hs:3:1: error:
Could not find module ‘Control.Effect’
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
3 | import Control.Effect
| ^^^^^^^^^^^^^^^^^^^^^
Test suite doctestd: FAIL
Test suite logged to:
/Users/user/work/hstest9/dist-newstyle/build/x86_64-osx/ghc-8.8.1/hstest9-0.1.0.0/t/doctestd/test/hstest9-0.1.0.0-doctestd.log
0 of 1 test suites (0 of 1 test cases) passed.
cabal: Tests failed for test:doctestd from hstest9-0.1.0.0.
Your doctest doesn't find proper GHC_ENVIRONEMNT.
Since Cabal 3.0, cabal v2-build doesn't generate environment files by default.
Since Cabal 3.0, defaults to never. Before that, defaulted to creating them only when compiling with GHC 8.4.4 and older (GHC 8.4.4 is the first version that supports the -package-env - option that allows ignoring the package environment files).
https://www.haskell.org/cabal/users-guide/nix-local-build.html#cfg-field-write-ghc-environment-files
So you should set this option on v2-build.
$ cabal v2-build --write-ghc-environment-files=ghc8.4.4+
Or you can write this in $HOME/.cabal/config for default cabal behavior.
write-ghc-environment-files: ghc8.4.4+
In official tutorial Haskell in 5 steps, an example imports a library:
import Control.Parallel
Then I use ghc to compile:
ghc parallel.hs -o parallel -O2 --make -threaded -rtsopts
just as the tutorial tells me to do. (My filename is parallel.hs) But I got:
parallel.hs:1:1: error:
Could not find module ‘Control.Parallel’
Use -v to see a list of the files searched for.
|
1 | import Control.Parallel
| ^^^^^^^^^^^^^^^^^^^^^^^
Then I stackoverflowed it and find this question. So I:
cabal new-install parallel --lib
And get:
Resolving dependencies...
Up to date
Then I compiled it again, but got the same error.
How to solve this? Did I miss any command line arguments?
Well, after cabal install parallel, the library is imported, the program is compiled successfully, and runs as expected.
I'll refer to documentations of cabal about the difference between install and new-install
As #Lorenzo noted, cabal install works fine. With cabal new-install you should have seen a warning that you forgot --lib since parallel does not include an executable and libraries must be explicitly installed via --lib. The full set of functional commands are:
cd $(mktemp -d)
cabal update && cabal new-install --lib parallel
cat <<EOF > parallel.hs
module P where
import Control.Parallel
EOF
ghc -c parallel.hs
ls parallel.o parallel.hi
Yielding:
% cd $(mktemp -d)
% cabal update && cabal new-install --lib parallel
... snipped output ...
% cat <<EOF > parallel.hs
module P where
import Control.Parallel
EOF
% ghc -c parallel.hs
Loaded package environment from /home/tommd/.ghc/x86_64-linux-8.6.4/environments/default
% ls parallel.o parallel.hi
parallel.hi parallel.o