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

Suggest --lib in cabal v2-install error message #6237

Closed
blamario opened this issue Sep 12, 2019 · 16 comments
Closed

Suggest --lib in cabal v2-install error message #6237

blamario opened this issue Sep 12, 2019 · 16 comments

Comments

@blamario
Copy link
Contributor

As a newby user trying to experiment through ghci with, say, the lens library, the first step would be to install lens:

$ cabal install lens
Resolving dependencies...
cabal: Cannot build the executables in the package lens because it does not
contain any executables. Check the .cabal file for the package and make sure
that it properly declares the components that you expect.

After this failure, the next step would be to look at cabal help install, and then probably to give up. The error message should prominently suggest --lib as the workaround.

@fgaz
Copy link
Member

fgaz commented Sep 12, 2019

It DID do that, I implemented it myself… I wonder why it isn't showing.

Also pinging @typedrat, who might have changed some of the logic

@typedrat
Copy link
Collaborator

I don’t recall making any changes that would effect it. Do you know what commit added the message?

@fgaz
Copy link
Member

fgaz commented Sep 19, 2019

f6aaeee (what a nice hash)

@fgaz
Copy link
Member

fgaz commented Sep 19, 2019

That code is currently in the warnIfNoExes function, which gets called in installExes. Maybe it filters targets the wrong way now? I don't have much time to test it atm

@selinger
Copy link
Contributor

Please fix this as soon as possible, as the --lib option does not even appear in the cabal 3.0.0.0 (and later) documentation, e.g. here: https://www.haskell.org/cabal/users-guide/installing-packages.html#building-and-installing-packages

Is there some documentation that is actually up-to-date, and if yes, where? Thanks!

@rasmussehlin
Copy link

I second fixing this. Had to find #6246 to know that "--lib" needed to be added.

@fgaz
Copy link
Member

fgaz commented Feb 29, 2020

If someone here has the time, a bisect would probably be helpful

@sgraf812
Copy link
Contributor

sgraf812 commented May 11, 2020

The warning from f6aaeee doesn't appear in 3.0.0.0 because it landed after 3.0.0.0 was cut, which is the cabal-install that came with GHC 8.10.1 for me.

Edit: Oh, it appears I was wrong and also confused commit dates when I double-checked.

This is the code that landed in 3.0.0.0:

warnIfNoExes :: Verbosity -> ProjectBuildContext -> IO ()
warnIfNoExes verbosity buildCtx =
when noExes $
warn verbosity $ "You asked to install executables, "
<> "but there are no executables in "
<> plural (listPlural selectors) "target" "targets" <> ": "
<> intercalate ", " (showTargetSelector <$> selectors) <> ". "
<> "Perhaps you want to use --lib "
<> "to install libraries instead."
where
targets = concat $ Map.elems $ targetsMap buildCtx
components = fst <$> targets
selectors = concatMap snd targets
noExes = null $ catMaybes $ exeMaybe <$> components
exeMaybe (ComponentTarget (CExeName exe) _) = Just exe
exeMaybe _ = Nothing
It appears the difference is in how components are handled. A trace ("exeMaybe:" ++ show exe) (Just exe) is probably enough to identify which component is reponsible for this and finding a fix.

@TakodaS
Copy link

TakodaS commented Aug 28, 2021

As a haskell newbie, I got a step further. Running cabal install --lib packagename gets me the following error:

Resolving dependencies...
cabal.exe: Could not resolve dependencies:
[__0] trying: ghc-8.10.4/installed-8.10.4 (user goal)
[__1] next goal: process (user goal)
[__1] rejecting: process-1.6.13.2, process-1.6.13.1, process-1.6.12.0
(constraint from user target requires ==1.6.11.0)
[__1] rejecting: process-1.6.11.0 (conflict: ghc =>
process==1.6.9.0/installed-1.6.9.0)
[__1] rejecting: process-1.6.10.0, process-1.6.9.0/installed-1.6.9.0,
process-1.6.9.0, process-1.6.8.2, process-1.6.8.1, process-1.6.8.0,
process-1.6.7.0, process-1.6.6.0, process-1.6.5.1, process-1.6.5.0,
process-1.6.4.0, process-1.6.3.0, process-1.6.2.0, process-1.6.1.0,
process-1.6.0.0, process-1.5.0.0, process-1.4.3.0, process-1.4.2.0,
process-1.4.1.0, process-1.4.0.0, process-1.3.0.0, process-1.2.3.0,
process-1.2.2.0, process-1.2.1.0, process-1.2.0.0, process-1.1.0.2,
process-1.1.0.1, process-1.1.0.0, process-1.0.1.5, process-1.0.1.4,
process-1.0.1.3, process-1.0.1.2, process-1.0.1.1, process-1.0.0.0,
process-1.6.13.0 (constraint from user target requires ==1.6.11.0)
[__1] fail (backjumping, conflict set: ghc, process)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: process, ghc

And then I gave up :)

@fgaz
Copy link
Member

fgaz commented Aug 28, 2021

@TakodaS what were you originally trying to do? install --lib is rarely what you want, especially in beginner situations.

For reference, here's the (code that generates the) new warning that only suggests --lib as the least likely of two options:

"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
"@ WARNING: Installation might not be completed as desired! @\n" <>
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
"The command \"cabal install [TARGETS]\" doesn't expose libraries.\n" <>
"* You might have wanted to add them as dependencies to your package." <>
" In this case add \"" <>
intercalate ", " (showTargetSelector <$> selectors) <>
"\" to the build-depends field(s) of your package's .cabal file.\n" <>
"* You might have wanted to add them to a GHC environment. In this case" <>
" use \"cabal install --lib " <>
unwords (showTargetSelector <$> selectors) <> "\". " <>
" The \"--lib\" flag is provisional: see" <>
" https://github.com/haskell/cabal/issues/6481 for more information."

@Mikolaj
Copy link
Member

Mikolaj commented Aug 28, 2021

@TakodaS: did you, perchance, run your command while in a directory with a cabal.project file? And what was the package you tried to install?

Regarding the use case from ticket description, there are various alternatives described in #6481 and cabal install --lib seems to be the worst of them (at least in current form). Until we figure out an alternative acceptable to all users, we don't know what alternative to suggest in help messages. Also, quite possibly we won't be overloading cabal install for both exe and lib installation (and both from local packages and from Hackage).

@Mikolaj
Copy link
Member

Mikolaj commented Aug 28, 2021

I was just advised, for the original problem in the ticket description, the following incantation is the best: cabal repl --build-depends foo. Given that this is now described at https://cabal.readthedocs.io/en/latest/cabal-commands.html#cabal-v2-repl, could we close this issue? Does it work for everybody? Anything else we could fix? Any objections?

@fgaz
Copy link
Member

fgaz commented Aug 29, 2021

could we close this issue?

The suggestion still does not appear, does it? that's a regression, and it seems a lot of people are stumbling into it (30 +1s on #6246)

@fgaz
Copy link
Member

fgaz commented Aug 29, 2021

Nevermind, it does!

> cabal install random
Resolving dependencies...
Up to date
Warning:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: Installation might not be completed as desired! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The command "cabal install [TARGETS]" doesn't expose libraries.
* You might have wanted to add them as dependencies to your package. In this
case add "random" to the build-depends field(s) of your package's .cabal file.
* You might have wanted to add them to a GHC environment. In this case use
"cabal install --lib random". The "--lib" flag is provisional: see
https://github.com/haskell/cabal/issues/6481 for more information.

Maybe OP was using an older cabal? I'll close optimistically. If anyone (with recent cabal) still isn't getting that message please leave a comment

@sfogarty
Copy link

This issue still emerges when installing a package with no executables.

$ cabal install ansi-terminal
Wrote tarball sdist to
/users/sfogarty/functional-testing/weights-and-gates/dist-newstyle/sdist/weights-and-gates-0.1.0.0.tar.gz
Resolving dependencies...
cabal: Cannot build the executables in the package ansi-terminal because none
of the components are available to build: the executable
'ansi-terminal-example' is marked as 'buildable: False'

$ cabal --version
cabal-install version 3.6.2.0
compiled using version 3.6.2.0 of the Cabal library 

It does not suggest to use cabal install --lib ansi-terminal, which does work to install the package.

@gbaz
Copy link
Collaborator

gbaz commented Apr 27, 2023

You are using cabal-install 3.6.2.0. The current version of cabal-install is 3.10.1.0

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

No branches or pull requests