haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.65k stars 355 forks source link

Building HLS fails with "happy: 1861: unrecognised directive: %shift" #3783

Closed konnik closed 1 year ago

konnik commented 1 year ago

I have some trouble trying to build HLS from source to be able to try som some HLS plugin hacking.

Your environment

MacOS X 11.7.9 (old intel mac)

From ghcup:

What's wrong?

Following the instructions https://haskell-language-server.readthedocs.io/en/latest/contributing/contributing.html#building

<clone repo>

$ cabal update
$ cabal build
Warning: Requested index-state 2023-08-25T00:00:00Z is newer than
'hackage.haskell.org'! Falling back to older state (2023-08-24T20:52:33Z).
Resolving dependencies...
Build profile: -w ghc-9.6.2 -O1
In order, the following will be built (use -v for more details):
 - ListLike-4.7.8.1 (lib) (requires build)
 - bitvec-1.1.5.0 (lib) (requires build)
 - deferred-folds-0.9.18.3 (lib) (requires build)
 - free-5.2 (lib) (requires build)
 - ghc-lib-parser-9.6.2.20230523 (lib) (requires build)
 - hw-prim-0.6.3.2 (lib) (requires build)
 - list-t-1.0.5.6 (lib) (requires build)
 - monoid-subclasses-1.2.3 (lib) (requires build)
 - indexed-traversable-instances-0.1.1.2 (lib) (requires build)
 - invariant-0.6.2 (lib) (requires build)
 - parsers-0.12.11 (lib) (requires build)
 - pretty-simple-4.1.2.0 (lib:pretty-simple) (requires build)
 - optparse-simple-0.1.1.4 (lib) (requires build)
 - row-types-1.0.1.2 (lib) (requires build)
 - sqlite-simple-0.4.18.2 (lib) (requires build)
 - tasty-1.4.3 (lib) (requires build)
 - text-rope-0.2 (lib) (requires build)
 - process-extras-0.7.4 (lib) (requires build)
 - vector-algorithms-0.9.0.1 (lib) (requires build)
 - ghc-exactprint-1.7.0.1 (lib) (requires build)
 - adjunctions-4.4.2 (lib) (requires build)
 - ormolu-0.7.1.0 (lib) (requires build)
 - ghc-lib-parser-ex-9.6.0.1 (lib) (requires build)
 - hw-fingertree-0.1.2.1 (lib) (requires build)
 - primitive-extras-0.10.1.7 (lib) (requires build)
 - fuzzy-0.1.0.1 (lib) (requires build)
 - witherable-0.4.2 (lib) (requires build)
 - semialign-1.3 (lib) (requires build)
 - hiedb-0.4.3.0 (lib) (requires build)
 - tasty-expected-failure-0.12.3 (lib) (requires build)
 - tasty-rerun-1.1.18 (lib) (requires build)
 - tasty-hunit-0.10.0.3 (lib) (requires build)
 - tasty-golden-2.3.5 (lib) (requires build)
 - mono-traversable-1.0.15.3 (lib) (requires build)
 - retrie-1.2.2 (lib) (requires build)
 - apply-refact-0.13.0.0 (lib) (requires build)
 - kan-extensions-5.2.5 (lib) (requires build)
 - stm-hamt-1.2.0.9 (lib) (requires build)
 - aeson-2.1.2.1 (lib) (requires build)
 - conduit-1.3.5 (lib) (requires build)
 - lens-5.2.3 (lib) (requires build)
 - stm-containers-1.2.0.2 (lib) (requires build)
 - aeson-pretty-0.8.10 (lib) (requires build)
 - enummapset-0.7.1.0 (lib) (requires build)
 - deriving-aeson-0.2.9 (lib) (requires build)
 - HsYAML-aeson-0.2.0.1 (lib) (requires build)
 - libyaml-0.1.2 (lib) (requires build)
 - conduit-extra-1.3.6 (lib) (requires build)
 - conduit-parse-0.2.1.1 (lib) (requires build)
 - lens-aeson-1.2.3 (lib) (requires build)
 - hls-graph-2.2.0.0 (lib) (first run)
 - stylish-haskell-0.14.5.0 (lib) (requires build)
 - yaml-0.11.11.2 (lib) (requires build)
 - lsp-types-2.0.2.0 (lib) (requires build)
 - implicit-hie-0.1.2.7 (lib) (requires build)
 - hlint-3.6.1 (lib) (requires build)
 - hie-bios-0.12.0 (lib) (requires build)
 - fourmolu-0.13.1.0 (lib) (requires build)
 - lsp-2.2.0.0 (lib) (requires build)
 - implicit-hie-cradle-0.5.0.1 (lib) (requires build)
 - lsp-test-0.16.0.0 (lib) (requires build)
 - hls-plugin-api-2.2.0.0 (lib) (first run)
 - ghcide-2.2.0.0 (lib) (first run)
 - hls-test-utils-2.2.0.0 (lib) (first run)
 - hls-stylish-haskell-plugin-2.2.0.0 (lib) (first run)
 - hls-refactor-plugin-2.2.0.0 (lib) (first run)
 - hls-qualify-imported-names-plugin-2.2.0.0 (lib) (first run)
 - hls-pragmas-plugin-2.2.0.0 (lib) (first run)
 - hls-overloaded-record-dot-plugin-2.2.0.0 (lib) (first run)
 - hls-ormolu-plugin-2.2.0.0 (lib) (first run)
 - hls-module-name-plugin-2.2.0.0 (lib) (first run)
 - hls-hlint-plugin-2.2.0.0 (lib) (first run)
 - hls-fourmolu-plugin-2.2.0.0 (lib) (first run)
 - hls-explicit-record-fields-plugin-2.2.0.0 (lib) (first run)
 - hls-explicit-imports-plugin-2.2.0.0 (lib) (first run)
 - hls-explicit-fixity-plugin-2.2.0.0 (lib) (first run)
 - hls-eval-plugin-2.2.0.0 (lib) (first run)
 - hls-code-range-plugin-2.2.0.0 (lib) (first run)
 - hls-class-plugin-2.2.0.0 (lib) (first run)
 - hls-change-type-signature-plugin-2.2.0.0 (lib) (first run)
 - hls-call-hierarchy-plugin-2.2.0.0 (lib) (first run)
 - hls-cabal-plugin-2.2.0.0 (lib) (first run)
 - hls-cabal-fmt-plugin-2.2.0.0 (lib) (first run)
 - hls-alternate-number-format-plugin-2.2.0.0 (lib) (first run)
 - ghcide-test-utils-1.9.0.0 (lib) (first run)
 - hls-splice-plugin-2.2.0.0 (lib) (first run)
 - hls-retrie-plugin-2.2.0.0 (lib) (first run)
 - hls-rename-plugin-2.2.0.0 (lib) (first run)
 - hls-gadt-plugin-2.2.0.0 (lib) (first run)
 - haskell-language-server-2.2.0.0 (lib) (first run)
 - haskell-language-server-2.2.0.0 (exe:haskell-language-server-wrapper) (first run)
 - haskell-language-server-2.2.0.0 (exe:haskell-language-server) (first run)
 - haskell-language-server-2.2.0.0 (test:wrapper-test) (first run)
 - haskell-language-server-2.2.0.0 (test:func-test) (first run)
Starting     deferred-folds-0.9.18.3 (lib)
Starting     ListLike-4.7.8.1 (lib)
Starting     list-t-1.0.5.6 (lib)
Starting     bitvec-1.1.5.0 (lib)
Starting     monoid-subclasses-1.2.3 (lib)
Starting     hw-prim-0.6.3.2 (lib)
Starting     free-5.2 (lib)
Starting     ghc-lib-parser-9.6.2.20230523 (lib)
Building     ListLike-4.7.8.1 (lib)
Building     deferred-folds-0.9.18.3 (lib)
Building     list-t-1.0.5.6 (lib)
Building     monoid-subclasses-1.2.3 (lib)
Building     bitvec-1.1.5.0 (lib)
Building     hw-prim-0.6.3.2 (lib)
Building     free-5.2 (lib)
Building     ghc-lib-parser-9.6.2.20230523 (lib)
Starting     indexed-traversable-instances-0.1.1.2 (lib)
Building     indexed-traversable-instances-0.1.1.2 (lib)
Haddock      list-t-1.0.5.6 (lib)
Haddock      indexed-traversable-instances-0.1.1.2 (lib)
Haddock      deferred-folds-0.9.18.3 (lib)
Installing   list-t-1.0.5.6 (lib)
Completed    list-t-1.0.5.6 (lib)
Installing   indexed-traversable-instances-0.1.1.2 (lib)
Completed    indexed-traversable-instances-0.1.1.2 (lib)
Installing   deferred-folds-0.9.18.3 (lib)
Completed    deferred-folds-0.9.18.3 (lib)
Haddock      free-5.2 (lib)
Installing   free-5.2 (lib)
Completed    free-5.2 (lib)
Haddock      monoid-subclasses-1.2.3 (lib)
Installing   monoid-subclasses-1.2.3 (lib)
Completed    monoid-subclasses-1.2.3 (lib)
Haddock      ListLike-4.7.8.1 (lib)
Haddock      hw-prim-0.6.3.2 (lib)
Installing   hw-prim-0.6.3.2 (lib)
Completed    hw-prim-0.6.3.2 (lib)
Installing   ListLike-4.7.8.1 (lib)
Completed    ListLike-4.7.8.1 (lib)
Haddock      bitvec-1.1.5.0 (lib)
Installing   bitvec-1.1.5.0 (lib)
Completed    bitvec-1.1.5.0 (lib)

Failed to build ghc-lib-parser-9.6.2.20230523.
Build log (
/Users/niklas/.cabal/logs/ghc-9.6.2/ghc-lb-prsr-9.6.2.20230523-61409e95.log ):
Configuring library for ghc-lib-parser-9.6.2.20230523..
Preprocessing library for ghc-lib-parser-9.6.2.20230523..
happy: 1861: unrecognised directive: %shift

Error: cabal: Failed to build ghc-lib-parser-9.6.2.20230523 (which is required
by test:wrapper-test from haskell-language-server-2.2.0.0 and test:func-test
from haskell-language-server-2.2.0.0). See the build log above for details.

Any suggestions how to fix this error? Thanks in advance.

fendor commented 1 year ago

I have never seen that error and our CI succeeds for almost this arch/platform/ghc/cabal combination.

Perhaps you have an old happy version lying around somewhere? Do you have anything in ~/.cabal/bin or installed something via stack install or brew some time ago?

konnik commented 1 year ago

Can't remember I have installed happy before (btw, I have no clue what happy is... :-) ) and I can't find happy in my path:

$  which happy

Tried to build with latest stack (using ghcup for managing cabal and ghc) and that worked out ok so it seems to be an issue with cabal?

One thing I found searching for similar issues is this: https://github.com/haskell/cabal/issues/8489 I'm too much of a newbie to make any sense of the discussion there though :-)

michaelpj commented 1 year ago

Let's take a look:

So ghc-lib-parser has a too-lax lower bound on happy.

However, normally cabal picks the latest versions of packages. I would try building with --constraint 'happy >= 1.20 and see if it tells you why it thinks it can't pick that.

konnik commented 1 year ago

I did manage to build HLS with cabal 3.8.1.0. After that I switched to cabal 3.10.1.0 and now cabal build worked. But I suspect that that was because of ghc-lib-parser was already built and reused?

I then tried to build with the --constraint 'happy >= 1.20' parameter but that did not force a rebuild of ghc-lib-parser. Is there a way of cleaning an already built dependency?

michaelpj commented 1 year ago

Okay, I don't understand why that isn't changing things. Maybe happy is special somehow, but I would still expect cabal to give a solver error, I can't see how it's happy with both. Still, if you got it to work, I suspect this isn't worth more investigation unless you feel like it.

konnik commented 1 year ago

I can try to do some investigation on my own to see if I can narrow down the root of the problem further. But perfectly it's fine to close this issue because I don't think it's HLS's "fault". Thanks for the help.

konnik commented 1 year ago

Just for the record I have now found the cause of this issue. See: https://github.com/digital-asset/ghc-lib/issues/484