[Haskell-cafe] Global Package Install
Viktor Dukhovni
ietf-dane at dukhovni.org
Sun Mar 21 10:01:23 UTC 2021
On Sun, Mar 21, 2021 at 08:14:09AM +0000, Tom Ellis wrote:
> On Thu, Feb 18, 2021 at 03:35:10PM -0500, Viktor Dukhovni wrote:
> > You can use "cabal repl -z" to run ghci with the Cabal "user" package
> > database in scope:
>
> I'm confused by this. What is 'the Cabal "user" package database'?
> The --help text says
>
> -z --ignore-project Only include explicitlyspecified packages (and 'base').
With the "-z" flag, "cabal repl" stops looking for ".cabal" files in the
current directory (sandbox if you like), and just works with whatever is
installed in the Cabal package database.
Thus, because I've previously compiled optparse-applicative and
streaming-bytestring:
$ (cd ~/.cabal/store/ghc-8.10.4; ls -d optparse-applicative* streaming-byte*)
optparse-applicative-0.16.1.0-eee378057b7539bcf75579d76e9f4ff170b047a9ccc498b6fe1ba5d2dfa9075a
streaming-bytestring-0.2.0-8e7f82f7151e104bdca4aac21a045ebe5b332e0490a839f8fba8a3901dfcd58a
I can run:
$ cabal repl -v0 -z
λ> import Data.Either
λ> :set -package bytestring
λ> import Data.ByteString
λ> :set -package streaming-bytestring
λ> import Streaming.ByteString
λ> :set -package optparse-applicative
λ> import Options.Applicative
λ> :t strOption
strOption
:: Data.String.IsString s => Mod OptionFields s -> Parser s
λ> :t unconsChunk
unconsChunk
:: Monad m =>
ByteStream m r
-> m (Either r (Data.ByteString.ByteString, ByteStream m r))
whereas the same does not generally work with just ghci, which does not
know about Cabal's package store:
$ ghci -v0
λ> :set -package bytestring
λ> :set -package streaming-bytestring
cannot satisfy -package streaming-bytestring
(use -v for more information)
λ> :set -package optparse-applicative
cannot satisfy -package optparse-applicative
(use -v for more information)
However, (perhaps dependent on one's Cabal configuration settings) when
I use "cabal install --lib some-package" I also end up with a GHC
environment file created as a side-effect of the "cabal install". Below
I request "base" which is already there, so the only effect is to create
the environment file:
$ cabal install --lib base
Resolving dependencies...
Up to date
$ cat ~/.ghc/x86_64-freebsd-8.10.4/environments/default
clear-package-db
global-package-db
package-db /home/viktor/.cabal/store/ghc-8.10.4/package.db
package-id ghc-8.10.4
package-id bytestring-0.10.12.0
package-id unix-2.7.2.2
package-id base-4.14.1.0
package-id time-1.9.3
package-id hpc-0.6.1.0
package-id filepath-1.4.2.1
package-id process-1.6.9.0
package-id array-0.5.4.0
package-id integer-gmp-1.0.3.0
package-id containers-0.6.4.1
package-id ghc-boot-8.10.4
package-id binary-0.8.8.0
package-id ghc-prim-0.6.1
package-id ghci-8.10.4
package-id rts-1.0.1
package-id terminfo-0.4.1.4
package-id transformers-0.5.6.2
package-id deepseq-1.4.4.0
package-id ghc-boot-th-8.10.4
package-id pretty-1.1.3.6
package-id template-haskell-2.16.0.0
package-id directory-1.3.6.0
package-id text-1.2.4.1
Once the environment file is in place, I can:
$ ghci -v0
λ> import Data.Either
λ> :set -package optparse-applicative
λ> import Options.Applicative
λ> :set -package streaming-bytestring
λ> import Streaming.ByteString
λ> :set -package bytestring
λ> import Data.ByteString
λ> :t strOption
strOption
:: Data.String.IsString s => Mod OptionFields s -> Parser s
λ> :t unconsChunk
unconsChunk
:: Monad m =>
ByteStream m r
-> m (Either r (Data.ByteString.ByteString, ByteStream m r))
> I can't see any evidence locally that it brings any packages into
> scope. Could you please clarify exactly what -z is doing in your
> example below?
With "-z" I can load any pre-built library from the Cabal package store,
rather than just the dependencies of the current project.
--
Viktor.
More information about the Haskell-Cafe
mailing list