Skip to content

Server fails to load while calling cabal on Apple Silicon. #2148

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

Closed
hchmr opened this issue Aug 31, 2021 · 3 comments
Closed

Server fails to load while calling cabal on Apple Silicon. #2148

hchmr opened this issue Aug 31, 2021 · 3 comments

Comments

@hchmr
Copy link

hchmr commented Aug 31, 2021

TL;DR: see "Actual behaviour" below

Your environment

  • Output of haskell-language-server --probe-tools or haskell-language-server-wrapper --probe-tools:

    haskell-language-server version: 1.3.0.0 (GHC: 8.10.5) (PATH: /Users/admin/Library/Application Support/Code/User/globalStorage/haskell.haskell/haskell-language-server-1.3.0-darwin-8.10.5) (GIT hash: e7c5e90b6df5dff2760d76169eddaea3bdd6a831)
    Tool versions found on the $PATH
    cabal:          3.4.0.0
    stack:          Not found
    ghc:            8.10.5
    
  • Which OS do you use: macOS Big Sur 11.5.2 on Apple M1.

  • lsp-client: n/a

  • Project structure:

    .
    ├── app
    │   └── Main.hs
    ├── dist-newstyle
    │   └── ...
    ├── dummy.cabal
    └── hie.yaml
    
  • Contents of hie.yaml:

    cradle:
      cabal:
        component: "exe:dummy"

Steps to reproduce

Create a new .cabal package:

$ mkdir dummy
$ cd dummy
$ cabal init

Verify that the .cabal package compiles the executable to a native Arm binary:

$ cabal build
Resolving dependencies...
Build profile: -w ghc-8.10.5 -O1
In order, the following will be built (use -v for more details):
 - dummy-0.1.0.0 (exe:dummy) (first run)
Configuring executable 'dummy' for dummy-0.1.0.0..
Preprocessing executable 'dummy' for dummy-0.1.0.0..
Building executable 'dummy' for dummy-0.1.0.0..
[1 of 1] Compiling Main             ( app/Main.hs, /Users/admin/dummy/dist-newstyle/build/aarch64-osx/ghc-8.10.5/dummy-0.1.0.0/x/dummy/build/dummy/dummy-tmp/Main.o )
Linking /Users/admin/dummy/dist-newstyle/build/aarch64-osx/ghc-8.10.5/dummy-0.1.0.0/x/dummy/build/dummy/dummy ...
$ cabal run
Up to date
Hello, Haskell!

Run language server from the terminal with no client:

$ haskell-language-server-1.3.0-darwin-8.10.5

Expected behaviour

The language should be able to load the project.

Actual behaviour

The language server runs, but is unable to load the project. It fails when calling cabal. It appears that during the configuration stage, cabal generates some intel assembly when called by HLS, but cabal does not do so when called normally from the command line, as demonstrated above. Here is the relevant output from HLS. For the full output, see the debug information below.

  Failed to parse result of calling cabal
  Build profile: -w ghc-8.10.5 -O1
  In order, the following will be built (use -v for more details):
  - dummy-0.1.0.0 (exe:dummy) (first run)
  Configuring executable 'dummy' for dummy-0.1.0.0..


  /var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:3:41: error:
  error: unexpected token in directive
  .globl _foo ## -- Begin function foo
  ^
  |
  3 | .globl _foo ## -- Begin function foo
  | ^

... 

  /var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:15:2: error:
  error: unrecognized instruction mnemonic, did you mean: eret, ret?
  retq
  ^
  |
  15 | retq
  | ^

  <no location info>: error:
  Error running clang! you need clang installed to use the LLVM backend
  (or GHC tried to execute clang incorrectly)
  `clang' failed in phase `Clang (Assembler)'. (Exit code: 1)

Include debug information

Execute in the root of your project the command haskell-language-server --debug . and paste the logs here:

Debug output:
haskell-language-server version: 1.3.0.0 (GHC: 8.10.5) (PATH: /Users/admin/Library/Application Support/Code/User/globalStorage/haskell.haskell/haskell-language-server-1.3.0-darwin-8.10.5) (GIT hash: e7c5e90b6df5dff2760d76169eddaea3bdd6a831)
 ghcide setup tester in /Users/admin/dummy.
Report bugs at https://github.com/haskell/haskell-language-server/issues

Step 1/4: Finding files to test in /Users/admin/dummy
Found 1 files

Step 2/4: Looking for hie.yaml files that control setup
Found 1 cradle
  (/Users/admin/dummy/hie.yaml)

Step 3/4: Initializing the IDE
2021-08-31 12:56:11.575264 [ThreadId 7] DEBUG hls:      Initializing exports map from hiedb
2021-08-31 12:56:11.745005 [ThreadId 7] DEBUG hls:      Done initializing exports map from hiedb (0)

Step 4/4: Type checking the files
2021-08-31 12:56:11.747364 [ThreadId 42] DEBUG hls:     hlint:getIdeas:file:NormalizedFilePath "/Users/admin/dummy/app/Main.hs"
2021-08-31 12:56:11.747698 [ThreadId 44] INFO hls:      Consulting the cradle for "app/Main.hs"
Output from setting up the cradle Cradle {cradleRootDir = "/Users/admin/dummy", cradleOptsProg = CradleAction: Cabal}
> Build profile: -w ghc-8.10.5 -O1
> In order, the following will be built (use -v for more details):
>  - dummy-0.1.0.0 (exe:dummy) (first run)
> Configuring executable 'dummy' for dummy-0.1.0.0..
> 
> /var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:3:41: error:
>      error: unexpected token in directive
>             .globl  _foo                            ## -- Begin function foo
>                                                     ^
>   |
> 3 |         .globl  _foo                            ## -- Begin function foo
>   |                                         ^
> 
> /var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:8:8: error:
>      error: unknown token in expression
>             pushq   %rbp
>                     ^
>   |
> 8 |         pushq   %rbp
>   |        ^
> 
> /var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:8:8: error:
>      error: invalid operand
>             pushq   %rbp
>                     ^
>   |
> 8 |         pushq   %rbp
>   |        ^
> 
> /var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:11:7: error:
>      error: unknown token in expression
>             movq    %rsp, %rbp
>                     ^
>    |
> 11 |         movq    %rsp, %rbp
>    |       ^
> 
> /var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:11:7: error:
>      error: invalid operand
>             movq    %rsp, %rbp
>                     ^
>    |
> 11 |         movq    %rsp, %rbp
>    |       ^
> 
> /var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:13:7: error:
>      error: unknown token in expression
>             xorl    %eax, %eax
>                     ^
>    |
> 13 |         xorl    %eax, %eax
>    |       ^
> 
> /var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:13:7: error:
>      error: invalid operand
>             xorl    %eax, %eax
>                     ^
>    |
> 13 |         xorl    %eax, %eax
>    |       ^
> 
> /var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:14:7: error:
>      error: unknown token in expression
>             popq    %rbp
>                     ^
>    |
> 14 |         popq    %rbp
>    |       ^
> 
> /var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:14:7: error:
>      error: invalid operand
>             popq    %rbp
>                     ^
>    |
> 14 |         popq    %rbp
>    |       ^
> 
> /var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:15:2: error:
>      error: unrecognized instruction mnemonic, did you mean: eret, ret?
>             retq
>             ^
>    |
> 15 |         retq
>    |  ^
> 
> <no location info>: error:
>     Error running clang! you need clang installed to use the LLVM backend
>     (or GHC tried to execute clang incorrectly)
> `clang' failed in phase `Clang (Assembler)'. (Exit code: 1)
2021-08-31 12:56:12.632039 [ThreadId 44] DEBUG hls:     Session loading result: Left [CradleError {cradleErrorDependencies = ["dummy.cabal","cabal.project","cabal.project.local"], cradleErrorExitCode = ExitFailure 1, cradleErrorStderr = ["Failed to parse result of calling cabal","Build profile: -w ghc-8.10.5 -O1\nIn order, the following will be built (use -v for more details):\n - dummy-0.1.0.0 (exe:dummy) (first run)\nConfiguring executable 'dummy' for dummy-0.1.0.0..\n","\n/var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:3:41: error:\n     error: unexpected token in directive\n            .globl  _foo                            ## -- Begin function foo\n                                                    ^\n  |\n3 |         .globl  _foo                            ## -- Begin function foo\n  |                                         ^\n\n/var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:8:8: error:\n     error: unknown token in expression\n            pushq   %rbp\n                    ^\n  |\n8 |         pushq   %rbp\n  |        ^\n\n/var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:8:8: error:\n     error: invalid operand\n            pushq   %rbp\n                    ^\n  |\n8 |         pushq   %rbp\n  |        ^\n\n/var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:11:7: error:\n     error: unknown token in expression\n            movq    %rsp, %rbp\n                    ^\n   |\n11 |         movq    %rsp, %rbp\n   |       ^\n\n/var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:11:7: error:\n     error: invalid operand\n            movq    %rsp, %rbp\n                    ^\n   |\n11 |         movq    %rsp, %rbp\n   |       ^\n\n/var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:13:7: error:\n     error: unknown token in expression\n            xorl    %eax, %eax\n                    ^\n   |\n13 |         xorl    %eax, %eax\n   |       ^\n\n/var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:13:7: error:\n     error: invalid operand\n            xorl    %eax, %eax\n                    ^\n   |\n13 |         xorl    %eax, %eax\n   |       ^\n\n/var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:14:7: error:\n     error: unknown token in expression\n            popq    %rbp\n                    ^\n   |\n14 |         popq    %rbp\n   |       ^\n\n/var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:14:7: error:\n     error: invalid operand\n            popq    %rbp\n                    ^\n   |\n14 |         popq    %rbp\n   |       ^\n\n/var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:15:2: error:\n     error: unrecognized instruction mnemonic, did you mean: eret, ret?\n            retq\n            ^\n   |\n15 |         retq\n   |  ^\n\n<no location info>: error:\n    Error running clang! you need clang installed to use the LLVM backend\n    (or GHC tried to execute clang incorrectly)\n`clang' failed in phase `Clang (Assembler)'. (Exit code: 1)\n",""]}]
2021-08-31 12:56:12.633701 [ThreadId 72] INFO hls:      File:     /Users/admin/dummy/app/Main.hs
Hidden:   no
Range:    1:1-2:1
Source:   cradle
Severity: DsError
Message: 
  Failed to parse result of calling cabal
  Build profile: -w ghc-8.10.5 -O1
  In order, the following will be built (use -v for more details):
  - dummy-0.1.0.0 (exe:dummy) (first run)
  Configuring executable 'dummy' for dummy-0.1.0.0..


  /var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:3:41: error:
  error: unexpected token in directive
  .globl _foo ## -- Begin function foo
  ^
  |
  3 | .globl _foo ## -- Begin function foo
  | ^

  /var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:8:8: error:
  error: unknown token in expression
  pushq %rbp
  ^
  |
  8 | pushq %rbp
  | ^

  /var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:8:8: error:
  error: invalid operand
  pushq %rbp
  ^
  |
  8 | pushq %rbp
  | ^

  /var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:11:7: error:
  error: unknown token in expression
  movq %rsp, %rbp
  ^
  |
  11 | movq %rsp, %rbp
  | ^

  /var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:11:7: error:
  error: invalid operand
  movq %rsp, %rbp
  ^
  |
  11 | movq %rsp, %rbp
  | ^

  /var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:13:7: error:
  error: unknown token in expression
  xorl %eax, %eax
  ^
  |
  13 | xorl %eax, %eax
  | ^

  /var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:13:7: error:
  error: invalid operand
  xorl %eax, %eax
  ^
  |
  13 | xorl %eax, %eax
  | ^

  /var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:14:7: error:
  error: unknown token in expression
  popq %rbp
  ^
  |
  14 | popq %rbp
  | ^

  /var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:14:7: error:
  error: invalid operand
  popq %rbp
  ^
  |
  14 | popq %rbp
  | ^

  /var/folders/m3/g5plyvv54rb28ndnnqx6wt7w0000gn/T/ghc23311_0/ghc_1.s:15:2: error:
  error: unrecognized instruction mnemonic, did you mean: eret, ret?
  retq
  ^
  |
  15 | retq
  | ^

  <no location info>: error:
  Error running clang! you need clang installed to use the LLVM backend
  (or GHC tried to execute clang incorrectly)
  `clang' failed in phase `Clang (Assembler)'. (Exit code: 1)

  
2021-08-31 12:56:12.635524 [ThreadId 80] INFO hls:      finish: User TypeCheck (took 0.89s)
2021-08-31 12:56:12.635692 [ThreadId 83] INFO hls:      finish: GetHie (took 0.00s)
Files that failed:
2021-08-31 12:56:12.6359 [ThreadId 85] INFO hls:        finish: GenerateCore (took 0.00s)
 * /Users/admin/dummy/app/Main.hs

Completed (0 files worked, 1 file failed)
@pepeiborra
Copy link
Collaborator

Is your HLS binary an Intel assembly? And your Cabal binary? Mixing Apple and Intel binaries doesn't work

@hchmr
Copy link
Author

hchmr commented Aug 31, 2021

Thank you! That appears to be the issue here. The HLS binary was downloaded by vscode-haskell and it is indeed an Intel binary. I've now built HLS from source and manually configured the VS Code extension to use it. It seems to be working fine now.

@jneira
Copy link
Member

jneira commented Aug 31, 2021

thanks for opening the issue an confirm that build from source is a valid workaround
the main issue about would be #2008

@jneira jneira closed this as completed Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants