ghcide fails when including servant-server as dep. with cannot statisfy ...

Created on 28 Jan 2020  路  13Comments  路  Source: haskell/ghcide

When including servant-server as a dependeny, ghcide will print the following error:

ghcide version: 0.0.6 (GHC: 8.6.5) (PATH: /home/rsoeldner/.cabal/store/ghc-8.6.5/ghcide-0.0.6-4aa57fa4249b5929e468d2f1efb68a574c18cca14176427ab91eb114ea8962a2/bin/ghcide)
Ghcide setup tester in /home/rsoeldner/work/example.
Report bugs at https://github.com/digital-asset/ghcide/issues

Step 1/6: Finding files to test in /home/rsoeldner/work/example
Found 2 files

Step 2/6: Looking for hie.yaml files that control setup
Found 1 cradle

Step 3/6, Cradle 1/1: Implicit cradle for /home/rsoeldner/work/example
Cradle {cradleRootDir = "/home/rsoeldner/work/example", cradleOptsProg = CradleAction: default}

Step 4/6, Cradle 1/1: Loading GHC Session
Loaded package environment from /home/rsoeldner/work/example/.ghc.environment.x86_64-linux-8.6.5
ghcide: <command line>: cannot satisfy -package-id servant-server-0.16.2-60a275bf83d1527b502d21b0db5b200a68977694dd0fe8bab84edc3a5e354fb3: 
    servant-server-0.16.2-60a275bf83d1527b502d21b0db5b200a68977694dd0fe8bab84edc3a5e354fb3 is unusable due to missing dependencies:
      wai-app-static-3.1.7.1-fecbcfd54e54b19aae9409125afc0169209de51d3fc050d8e9632dc6af452750
    (use -v for more information)

I'm using the following workflow (running NixOs):

  1. entering nix-shell
  2. installing ghcide (cabal v2-install ghcide)
  3. create new project (cabal init) and added servant and servant-server as dep
  4. running cabal v2-configure --write-ghc-environment-files always for creating .ghc.env file
  5. run ghcide

I have uploaded this minimal, running version to Github https://github.com/rsoeldner/ghcide-example-issue

Maybe I do somethign fundamentally wrong ?

nixos bug setup

Most helpful comment

We solved the problem in hie by selecting the used ghc version based on the cradle type and then calling ghc --print-libdir and stack ghc -- --print-libdir respectively. I agree that it makes sense to add this to a cradle definition in hie-bios.
Responsible code:
https://github.com/haskell/haskell-ide-engine/blob/master/hie-plugin-api/Haskell/Ide/Engine/Cradle.hs#L91

Usage:
https://github.com/haskell/haskell-ide-engine/blob/master/hie-plugin-api/Haskell/Ide/Engine/Cradle.hs#L147

We encountered some problems with calling cabal exec -- ghc --print-libdir because this only works after the project has been at least configured.
I think we can upstream a lot of this code into the cradle definition.

All 13 comments

CC @mpickering as this sounds like hie-bios issue.

Does cabal v2-repl work for you? Can you try creating an explicit hie.yaml?

@ndmitchell cabal v2-repl works without any issues.

Adding the following hie.yaml does not change the reported behavior:

cradle: {cabal: {component: "exe:example"}}

Running ghcide produces the following output:

ghcide version: 0.0.6 (GHC: 8.6.5) (PATH: /home/rsoeldner/.cabal/store/ghc-8.6.5/ghcide-0.0.6-4aa57fa4249b5929e468d2f1efb68a574c18cca14176427ab91eb114ea8962a2/bin/ghcide)
Ghcide setup tester in /home/rsoeldner/work/example.
Report bugs at https://github.com/digital-asset/ghcide/issues

Step 1/6: Finding files to test in /home/rsoeldner/work/example
Found 2 files

Step 2/6: Looking for hie.yaml files that control setup
Found 1 cradle

Step 3/6, Cradle 1/1: Loading ./hie.yaml

Step 4/6, Cradle 1/1: Loading GHC Session
ghcide: <command line>: cannot satisfy -package-id servant-server-0.16.2-60a275bf83d1527b502d21b0db5b200a68977694dd0fe8bab84edc3a5e354fb3: 
    servant-server-0.16.2-60a275bf83d1527b502d21b0db5b200a68977694dd0fe8bab84edc3a5e354fb3 is unusable due to missing dependencies:
      wai-app-static-3.1.7.1-fecbcfd54e54b19aae9409125afc0169209de51d3fc050d8e9632dc6af452750
    (use -v for more information)

Is there a way to get ghcide to show the flags it's trying to use to start a session?

@mpickering as far as I know, no. maybe @ndmitchell or @cocreature can help here ?

Hi @mpickering ,

I just modified the the cradleToSession function inside exe/Main.hs to:

cradleToSession :: Cradle -> IO HscEnvEq
cradleToSession cradle = do
    cradleRes <- getCompilerOptions "" cradle
    opts <- case cradleRes of
        CradleSuccess r -> pure r
        CradleFail err -> throwIO err
        -- TODO Rather than failing here, we should ignore any files that use this cradle.
        -- That will require some more changes.
        CradleNone -> fail "'none' cradle is not yet supported"
    libdir <- getLibdir
    putStrLn $ "## Libdir: " ++ libdir
    putStrLn $ "## OPTS:" ++ (show opts)
    env <- runGhc (Just libdir) $ do
        _targets <- initSession opts
        getSession
    initDynLinker env
    newHscEnvEq env

to print our the libdir and opts parameter, see below of the output:

ghcide version: 0.0.6 (GHC: 8.6.5) (PATH: /home/rsoeldner/work/ghcide-0.0.6/dist-newstyle/build/x86_64-linux/ghc-8.6.5/ghcide-0.0.6/x/ghcide/build/ghcide/ghcide)
Ghcide setup tester in /home/rsoeldner/work/ghcide-0.0.6.
Report bugs at https://github.com/digital-asset/ghcide/issues

Step 1/6: Finding files to test in /home/rsoeldner/work/ghcide-0.0.6
Found 2 files

Step 2/6: Looking for hie.yaml files that control setup
Found 1 cradle

Step 3/6, Cradle 1/1: Loading /home/rsoeldner/work/example/hie.yaml

Step 4/6, Cradle 1/1: Loading GHC Session
Cradle {cradleRootDir = "/home/rsoeldner/work/example", cradleOptsProg = CradleAction: cabal}
## Libdir: /nix/store/npw9cl22d89yach0lk18m93jiipx42rz-ghc-8.6.5/lib/ghc-8.6.5

## OPTS:ComponentOptions {componentOptions = ["-fbuilding-cabal-package","-O0","-outputdir","/home/rsoeldner/work/example/dist-newstyle/build/x86_64-linux/ghc-8.6.5/example-0.1.0.0/x/example/build/example/example-tmp","-odir","/home/rsoeldner/work/example/dist-newstyle/build/x86_64-linux/ghc-8.6.5/example-0.1.0.0/x/example/build/example/example-tmp","-hidir","/home/rsoeldner/work/example/dist-newstyle/build/x86_64-linux/ghc-8.6.5/example-0.1.0.0/x/example/build/example/example-tmp","-stubdir","/home/rsoeldner/work/example/dist-newstyle/build/x86_64-linux/ghc-8.6.5/example-0.1.0.0/x/example/build/example/example-tmp","-i","-i/home/rsoeldner/work/example/dist-newstyle/build/x86_64-linux/ghc-8.6.5/example-0.1.0.0/x/example/build/example/example-tmp","-i/home/rsoeldner/work/example/.","-i/home/rsoeldner/work/example/dist-newstyle/build/x86_64-linux/ghc-8.6.5/example-0.1.0.0/x/example/build/example/autogen","-i/home/rsoeldner/work/example/dist-newstyle/build/x86_64-linux/ghc-8.6.5/example-0.1.0.0/x/example/build/global-autogen","-I/home/rsoeldner/work/example/dist-newstyle/build/x86_64-linux/ghc-8.6.5/example-0.1.0.0/x/example/build/example/autogen","-I/home/rsoeldner/work/example/dist-newstyle/build/x86_64-linux/ghc-8.6.5/example-0.1.0.0/x/example/build/global-autogen","-I/home/rsoeldner/work/example/dist-newstyle/build/x86_64-linux/ghc-8.6.5/example-0.1.0.0/x/example/build/example/example-tmp","-optP-include","-optP/home/rsoeldner/work/example/dist-newstyle/build/x86_64-linux/ghc-8.6.5/example-0.1.0.0/x/example/build/example/autogen/cabal_macros.h","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/home/rsoeldner/.cabal/store/ghc-8.6.5/package.db","-package-db","/home/rsoeldner/work/example/dist-newstyle/packagedb/ghc-8.6.5","-package-db","/home/rsoeldner/work/example/dist-newstyle/build/x86_64-linux/ghc-8.6.5/example-0.1.0.0/x/example/package.conf.inplace","-package-id","base-4.12.0.0","-package-id","servant-0.16.2-ec01031ffd8f923d66f9d2f492dddcb2951f8eceee29c58dffc326f82eab3dcd","-package-id","servant-server-0.16.2-60a275bf83d1527b502d21b0db5b200a68977694dd0fe8bab84edc3a5e354fb3","-XHaskell2010","./Main.hs","-hide-all-packages"], componentDependencies = ["example.cabal","cabal.project"]}


ghcide: <command line>: cannot satisfy -package-id servant-server-0.16.2-60a275bf83d1527b502d21b0db5b200a68977694dd0fe8bab84edc3a5e354fb3: 
    servant-server-0.16.2-60a275bf83d1527b502d21b0db5b200a68977694dd0fe8bab84edc3a5e354fb3 is unusable due to missing dependencies:
      wai-app-static-3.1.7.1-fecbcfd54e54b19aae9409125afc0169209de51d3fc050d8e9632dc6af452750
    (use -v for more information)

And what is in /nix/store/npw9cl22d89yach0lk18m93jiipx42rz-ghc-8.6.5/lib/ghc-8.6.5?

My guess is that not servant-server because ghcide is setting the wrong libdir.

correct, the path contains basic haskell libs (mtl, stm, time, text,) but nothing related to servant nor servant-server.

Shouldn't the libdir be set to the path where cabal v2-build fetched the dependencies?

Currently we use the libdir from the ghc-paths library, unless you are in Nix, in which case we use the Nix variable - see https://github.com/digital-asset/ghcide/blob/master/exe/Main.hs#L58. You are in Nix but not using the Nix ghc which confuses our heuristic. My guess is we should have hie-bios tell us the right libdir itself, and hie-bios should do that by calling ghc --print-libdir to ask for it and putting it in the Cradle. That accounts for the fact that Nix changes the libdir by altering the ghc on the $PATH, which means our environment variable trick can die (which is what goes wrong here).

We solved the problem in hie by selecting the used ghc version based on the cradle type and then calling ghc --print-libdir and stack ghc -- --print-libdir respectively. I agree that it makes sense to add this to a cradle definition in hie-bios.
Responsible code:
https://github.com/haskell/haskell-ide-engine/blob/master/hie-plugin-api/Haskell/Ide/Engine/Cradle.hs#L91

Usage:
https://github.com/haskell/haskell-ide-engine/blob/master/hie-plugin-api/Haskell/Ide/Engine/Cradle.hs#L147

We encountered some problems with calling cabal exec -- ghc --print-libdir because this only works after the project has been at least configured.
I think we can upstream a lot of this code into the cradle definition.

@ndmitchell thank you for investigating this. Setting the env inside my nix-shell with export NIX_GHC_LIBDIR=$(ghc --print-libdir) fixed most issues. One missing is related to https://github.com/haskell/haskell-ide-engine/issues/1093 which I can ignore.

I think there were some changes to make nix work after this issue: @rsoeldner could you check if it is resolved with lastest ghcide version?

@jneira havent encountered this issue again, thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

googleson78 picture googleson78  路  9Comments

decapo01 picture decapo01  路  4Comments

emilypi picture emilypi  路  8Comments

zeta-00 picture zeta-00  路  6Comments

pepeiborra picture pepeiborra  路  9Comments