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

'Error during compilation' How to get more information? #1030

Closed
breuerfelix opened this issue Mar 15, 2021 · 23 comments
Closed

'Error during compilation' How to get more information? #1030

breuerfelix opened this issue Mar 15, 2021 · 23 comments
Labels
bug Something isn't working

Comments

@breuerfelix
Copy link

breuerfelix commented Mar 15, 2021

Describe the bug

Everytime i start Neovim, it tries to install one missing language parser and fails. I am not able to get any error messages to figure out which one it is or why this happens.
TSUpdate also returns errors for two parsers. How do i get more information?

To Reproduce

Steps to reproduce the behavior:

  1. Start Neovim
  2. Run :messages
[nvim-treesitter] [0/1] Downloading...
[nvim-treesitter] [0/1] Creating temporary directory
[nvim-treesitter] [0/1] Extracting...
[nvim-treesitter] [0/1] Compiling...
Error during compilation
  1. Run :TSUpdate
[nvim-treesitter] [0/2] Downloading...
[nvim-treesitter] [0/2] Downloading...
[nvim-treesitter] [0/2] Creating temporary directory
[nvim-treesitter] [0/2] Extracting...
[nvim-treesitter] [0/2] Compiling...
[nvim-treesitter] [0/2] Creating temporary directory
[nvim-treesitter] [0/2] Extracting...
[nvim-treesitter] [0/2] Compiling...
Error during compilation
Error during compilation

Expected behavior

More Error Information. Or no Error at all :)

Output of :checkhealth nvim_treesitter

health#nvim_treesitter#check
========================================================================
## Installation
  - OK: `tree-sitter` found  0.18.2(parser generator, used for :TSInstallFromGrammar)
  - OK: `git` executable found.
  - OK: `cc` executable found.

## Parser/Features H L F I
  - lua            ✓ ✓ ✓ ✓ 
  - glimmer        ✓ . . . 
  - ruby           ✓ ✓ . ✓ 
  - bash           ✓ ✓ ✓ . 
  - vue            ✓ . ✓ . 
  - jsonc          ✓ ✓ ✓ ✓ 
  - php            ✓ ✓ ✓ . 
  - java           ✓ ✓ . ✓ 
  - yaml           ✓ ✓ ✓ ✓ 
  - kotlin         ✓ . . . 
  - html           ✓ ✓ ✓ ✓ 
  - julia          ✓ ✓ . . 
  - rst            ✓ ✓ . . 
  - json           ✓ ✓ ✓ ✓ 
  - css            ✓ . ✓ ✓ 
  - erlang         . . . . 
  - regex          ✓ . . . 
  - ocaml          ✓ ✓ ✓ . 
  - fennel         ✓ ✓ . . 
  - javascript     ✓ ✓ ✓ ✓ 
  - teal           ✓ ✓ ✓ ✓ 
  - turtle         ✓ ✓ ✓ ✓ 
  - gdscript       ✓ ✓ . . 
  - ql             ✓ ✓ . . 
  - ocaml_interface✓ ✓ ✓ . 
  - nix            ✓ ✓ ✓ . 
  - verilog        ✓ ✓ ✓ . 
  - ocamllex       ✓ . . . 
  - query          ✓ ✓ ✓ ✓ 
  - clojure        ✓ ✓ . . 
  - c              ✓ ✓ ✓ ✓ 
  - jsdoc          ✓ . . . 
  - cpp            ✓ ✓ ✓ ✓ 
  - comment        ✓ . . . 
  - typescript     ✓ ✓ ✓ ✓ 
  - dart           ✓ ✓ . ✓ 
  - sparql         ✓ ✓ ✓ ✓ 
  - rust           ✓ ✓ ✓ ✓ 
  - tsx            ✓ ✓ ✓ ✓ 
  - ledger         ✓ . ✓ ✓ 
  - graphql        ✓ . . ✓ 
  - go             ✓ ✓ ✓ ✓ 
  - supercollider  ✓ ✓ ✓ ✓ 
  - python         ✓ ✓ ✓ ✓ 
  - devicetree     ✓ ✓ ✓ ✓ 
  - c_sharp        ✓ . . . 
  - toml           ✓ ✓ ✓ ✓ 
 Legend: H[ighlight], L[ocals], F[olds], I[ndents]
         *) multiple parsers found, only one will be used
         x) errors found in the query, try to run :TSUpdate {lang}

Output of nvim --version

NVIM v0.5.0-dev
Build type: Release
LuaJIT 2.1.0-beta3
Compilation:
Compiled by nixbld

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "
/nix/store/0q0r30jpyqxbsn8lajdiwikk8b8xq6fk-neovim-nightly-master/share/nvim"

Run :checkhealth for more info

Treesitter config:

require'nvim-treesitter.configs'.setup {
  -- "all", "maintained" or a list
  ensure_installed = "maintained",
  highlight = { enable = true, },
  indent = { enable = false, },
  rainbow = { enable = true, },
}

Additional context

  • Running NixOS
  • Same config works fine on another computer
  • Sorry but the details in this issue template f** up the whole syntax :D

/edit now i got this error on all of my systems. not able to debug!

@breuerfelix breuerfelix added the bug Something isn't working label Mar 15, 2021
@breuerfelix
Copy link
Author

i resolved this issue by installing the nixOS package clangStdenv or gccStdenv. Seems like i had some issue with libstdc++ linking.
The installing said that, svelte got installed properly, so i guess it was this lib causing problems.
Yet, i do not wanna close this issue here because i still want to figure out how to get information WHICH plugin was causing the problems. A simple "Error during compilation" is not helpful at all :)

How to debug further errors ? how do i get the exact error messages instead of just "Error ... " ?

@theHamsta
Copy link
Member

theHamsta commented Mar 16, 2021

TSInstallSync yields the complete compiler output in case of failure but we should capture stdio also in async launches

@cd-a
Copy link

cd-a commented Mar 17, 2021

I got the exact same. Running latest neovim and with tree-sitter 0.19.3 PR 1000.

For me the culprit is haskell. All the others work fine.

Output from TSInstallSync haskell

Downloading...
Creating temporary directory
Extracting...
Compiling...
src/scanner.cc:77:10: error: expected expression
  return [=](A a) { return f(g(a)); };
         ^
src/scanner.cc:81:10: error: expected expression
  return [=](A a) { return f(g(a)); };
         ^
src/scanner.cc:85:10: error: expected expression
  return [=](A a) { return f(g(a)); };
         ^
src/scanner.cc:88:64: error: expected expression
template<class A, class B> function<B(A)> const_(B b) { return [=](auto _) { return b; }; }
                                                               ^
src/scanner.cc:153:16: error: non-aggregate type 'vector<std::__1::string>' (aka 'vector<basic_string<char, char_traits<char>, allocator<char> > >') cannot be initialized with an initializer list
vector<string> names = {
               ^       ~
src/scanner.cc:181:69: error: expected expression
bool all(const bool *syms) { return std::all_of(syms, syms + empty, [](bool a) { return a; }); }
                                                                    ^
src/scanner.cc:238:8: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
  for (auto i : state.indents) {
       ^
src/scanner.cc:238:15: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
  for (auto i : state.indents) {
              ^
src/scanner.cc:283:10: error: expected expression
  return [=](State & state) {
         ^
src/scanner.cc:306:57: error: expected expression
Peek operator&(const Peek & l, const Peek & r) { return [=](uint32_t c) { return l(c) && r(c); }; }
                                                        ^
src/scanner.cc:307:57: error: expected expression
Peek operator|(const Peek & l, const Peek & r) { return [=](uint32_t c) { return l(c) || r(c); }; }
                                                        ^
src/scanner.cc:308:30: error: expected expression
Peek not_(Peek con) { return [=](uint32_t c) { return !con(c); }; }
                             ^
src/scanner.cc:319:72: error: expected expression
Condition operator&(const Condition & l, const Condition & r) { return [=](auto s) { return l(s) && r(s); }; }
                                                                       ^
src/scanner.cc:320:72: error: expected expression
Condition operator|(const Condition & l, const Condition & r) { return [=](auto s) { return l(s) || r(s); }; }
                                                                       ^
src/scanner.cc:321:46: error: expected expression
Condition not_(const Condition & c) { return [=](State & state) { return !c(state); }; }
                                             ^
src/scanner.cc:338:35: error: expected expression
Peek eq(uint32_t target) { return [=](uint32_t c) { return target == static_cast<uint32_t>(c); }; }
                                  ^
src/scanner.cc:349:10: error: expected expression
  return [=](State & state) {
         ^
src/scanner.cc:369:10: error: expected expression
  return [=](State & state) {
         ^
src/scanner.cc:391:10: error: expected expression
  return [=](State & state) { return all_of(s.begin(), s.end(), [&](auto a) { return consume(a)(state); }); };
         ^
src/scanner.cc:395:10: error: expected expression
  return [=](State & state) {
         ^
src/scanner.cc:409:30: error: expected expression
  if (target.empty()) return [=](auto) {};
                             ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
2 warnings and 20 errors generated.
Error during compilation
Failed to execute the following command:
{
  cmd = "cc",
  err = "Error during compilation",
  info = "Compiling...",
  opts = {
    args = { "-o", "parser.so", "-I./src", "src/parser.c", "src/scanner.cc", "-shared", "-Os", "-lstdc++", "-fPIC" },
    cwd = "/Users/cda/.local/share/nvim/tree-sitter-haskell"
  }
}

@theHamsta
Copy link
Member

theHamsta commented Mar 17, 2021

Yes, haskell uses C++11. You should try to use a more recent version of gcc or clang that use C++11 as a default. You can controll that with CC enviroment variable.

This is why I updated our CI to Ubuntu 20.04 because it uses a more recent GCC.

@cd-a
Copy link

cd-a commented Mar 17, 2021

Thanks @theHamsta
I'm on macOS, got the latest gcc from homebrew, but looks like gcc command is linked to the xcode version

@theHamsta
Copy link
Member

@dahmc The problem why we can't add --std=c++11 is because we do the compilation of the C file and the C++ file in one command. If you want to set standards you would have to do it in separate compiler invokations

@cd-a
Copy link

cd-a commented Mar 17, 2021

@theHamsta I see. I just manually compiled the file and copied it over.

I don't even use haskell, just want to be able to use the 'all' setting, so that fixes it for me :)

@jensfors
Copy link

I get the same error as @dahmc with treesitter complaining about haskell when I open nvim. I don't exactly understand how dahmc fixed it. If anyone will help enlighten me it would really be appreciated 🙏

@theHamsta
Copy link
Member

theHamsta commented Mar 24, 2021

@Jens-Andersen a very recent compiler will automatically use C++1X and the haskell parser will compile. The haskell parser is the only parser causing that problem and it fails to compile with some compilers that don't assume C++11: #1080 we eventually need to find a solution for this. A recent GCC and clang seems to do fine (but I had to upgrade the CI to Ubuntu 20.04). Apple clang and the compilers on Windows seem to have problems.

@cd-a
Copy link

cd-a commented Mar 25, 2021

@Jens-Andersen This is the very hacky solution I did to make the error go away, if I recall correctly:

cd ~/.local/share/nvim/tree-sitter-haskell
/usr/local/opt/gcc/bin/gcc-10 -o parser.so -I./src src/parser.c src/scanner.cc -shared -Os -lstdc++ -fPIC
cp parser.so ~/.vim/plugged/nvim-treesitter/parser/haskell.so

@theHamsta
Copy link
Member

You can also set CC environment variable to gcc-10 to use gcc-10

@ziulev
Copy link

ziulev commented Mar 25, 2021

@Jens-Andersen This is the very hacky solution I did to make the error go away, if I recall correctly:

cd ~/.local/share/nvim/tree-sitter-haskell
/usr/local/opt/gcc/bin/gcc-10 -o parser.so -I./src src/parser.c src/scanner.cc -shared -Os -lstdc++ -fPIC
cp parser.so ~/.vim/plugged/nvim-treesitter/parser/haskell.so

If use packer.nvim

cd ~/.local/share/nvim/tree-sitter-haskell
/usr/local/opt/gcc/bin/gcc-10 -o parser.so -I./src src/parser.c src/scanner.cc -shared -Os -lstdc++ -fPIC
cp parser.so ~/.local/share/nvim/site/pack/packer/start/nvim-treesitter/parser/haskell.so

@omar25h
Copy link

omar25h commented Mar 25, 2021

@Jens-Andersen If using Apple's Clang, you would need to invoke the compiler twice, for src/scanner.cc and then for src/parser.c

cd ~/.local/share/nvim/tree-sitter-haskell
clang -o scanner.so -I./src src/scanner.cc -std=c++14 -shared -Os -fPIC -lstdc++
clang -o parser.so scanner.so -I./src src/parser.c -shared -Os -fPIC -lstdc++
# if using vim-plug
cp parser.so ~/.vim/plugged/nvim-treesitter/parser/haskell.so
# if using packer.nvim
cp parser.so ~/.local/share/nvim/site/pack/packer/start/nvim-treesitter/parser/haskell.so

It would also be a good idea to add ~/.vim/plugged/nvim-treesitter/parser-info/haskell.revision or ~/.local/share/nvim/site/pack/packer/nvim-treesitter/parser-info/haskell.revision file with latest commit hash from https://github.com/tree-sitter/tree-sitter-haskell/commits in order to avoid updating the parser when executing :TSUpdate (1b00b9fbf93a2c8a22db3a5be748527d1d428922 at the time of this comment)

@jensfors
Copy link

jensfors commented Mar 25, 2021

@theHamsta could you give an example of how I would set my CC env variable? I get a lot of different results some with setting it in a make file others in my .*rc file. And fantastic that you are already on top of the problem, I will keep the linked issue bookmarked to follow the progress.

@ziulev thanks for the walk-through that was exactly what I was hoping for. And I use packer so I really appreciate the example with that since im still very new in this ecosystem.

@omar25h I presume I use Apple's Clang but not quite sure. And thanks for the extended answer it would be quite annoying if :TSUpdate would mess it up so appreciate the solution in advance!

@theHamsta
Copy link
Member

theHamsta commented Mar 25, 2021

@Jens-Andersen CC should just lead to your prefered C compiler (name or full path). You can also set the compiler explicitly via Lua https://github.com/theHamsta/nvim-treesitter/blob/rust-closures/lua/nvim-treesitter/install.
lua

Maybe we should allow multiple compiler invocations but this can quickly lead to a complexity where we should have use an actual build system. In the past, we only had this problem with really old compilers and just said we require a recently modern C++ standard. If it's only the Haskell parser then maybe we should special-case it?

You can also treat tree-sitter-haskel as a plugin with the corrsponding compile commands as install commands. Just remember to move the resulting haskell.so to a parser subfolder (this is how I did it before nvim-treesitter existed)

@jensfors
Copy link

Thanks for the help everyone you guys are life savers!

@theHamsta In my case it was only the haskell parser there were an issue with, the rest seems to have worked out of the box or according to the installation guides

@gbaranski
Copy link

@Jens-Andersen CC should just lead to your prefered C compiler (name or full path). You can also set the compiler explicitly via Lua https://github.com/theHamsta/nvim-treesitter/blob/rust-closures/lua/nvim-treesitter/install.
lua

Maybe we should allow multiple compiler invocations but this can quickly lead to a complexity where we should have use an actual build system. In the past, we only had this problem with really old compilers and just said we require a recently modern C++ standard. If it's only the Haskell parser then maybe we should special-case it?

You can also treat tree-sitter-haskel as a plugin with the corrsponding compile commands as install commands. Just remember to move the resulting haskell.so to a parser subfolder (this is how I did it before nvim-treesitter existed)

Could you fix link please? I've got the same issue also on NixOS

@theHamsta
Copy link
Member

theHamsta commented Apr 24, 2021

require'nvim-treesitter.install'.compilers = {"path/to/compiler"}

Is the problem the haskell compiler?

@gbaranski
Copy link

I've solved the issue by removing clang from packages

@theHamsta
Copy link
Member

Yes, on MacOS there seems to be a problem with Apple Clang not defaulting to C++14. There is only one spot in the Haskell compiler that requires C++14. Maybe I can create a PR to lower the requirement to C++11

@gbaranski
Copy link

Yes, on MacOS there seems to be a problem with Apple Clang not defaulting to C++14. There is only one spot in the Haskell compiler that requires C++14. Maybe I can create a PR to lower the requirement to C++11

Hmm, but I'm not using MacOS, I've got NixOS Linux.

@theHamsta
Copy link
Member

But with Haskell. I can happen when your compiler defaults to C++11.

I hope this change can lower the required standard to C++11 theHamsta/tree-sitter-haskell@9931c25

@bscp7
Copy link

bscp7 commented Dec 24, 2021

Thanks @breuerfelix for the fix. I installed clangStdenv and it fixed the issue.

❯ nix-env -iA nixpkgs.clangStdenv
installing 'stdenv-darwin'
building '/nix/store/cs9bs384hljk66s0y3zxx5zjvjp99zwj-user-environment.drv'...

Opened lunarvim and ran :PackerCompile and got packer.compile: Complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants