Skip to content

neovim: add libstdc++.so.6 dep for tree-sitter#147658

Closed
auscyber wants to merge 1 commit intoNixOS:masterfrom
auscyber:master
Closed

neovim: add libstdc++.so.6 dep for tree-sitter#147658
auscyber wants to merge 1 commit intoNixOS:masterfrom
auscyber:master

Conversation

@auscyber
Copy link
Copy Markdown
Contributor

@auscyber auscyber commented Nov 28, 2021

Motivation for this change

neovim cannot find libstdc++.so.6 which is needed for tree-sitter

Things done

@ofborg ofborg bot requested review from Ma27, manveru and rvolosatovs November 28, 2021 05:54
@ofborg ofborg bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Nov 28, 2021
@teto
Copy link
Copy Markdown
Member

teto commented Dec 2, 2021

is that for non-nixos environments ? haven't had this issue so far on nixos but then I dont use treesitter much

@auscyber
Copy link
Copy Markdown
Contributor Author

auscyber commented Dec 3, 2021

is that for non-nixos environments ? haven't had this issue so far on nixos but then I dont use treesitter much

This is a massive problem on both nix and nixos systems as neovim cannot locate libstdc++ for tree-siiter. One problem with this pr is that it doesn't work for all parsers, but it works for most. a simple override of the gcc could make it support more parsers

@auscyber
Copy link
Copy Markdown
Contributor Author

auscyber commented Dec 3, 2021

It also maybe a problem that patchelf might not work on mac, i don't know much about mac

@teto
Copy link
Copy Markdown
Member

teto commented Dec 3, 2021

could you provide instructions (nix expressions) to generate a failure that is fixed by this PR ? evntually a test in pkgs/applications/editors/neovim/tests.nix that fails without this PR

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
patchelf --add-needed ${gcc.cc.lib}/lib/libstdc++.so.6 $out/bin/nvim
patchelf --add-needed ${stdenv.cc.cc.lib}/lib/libstdc++.so.6 $out/bin/nvim

might work for mac?

could also mark it as lib.optionalString stdenv.isLinux '' for now as well

@jonringer
Copy link
Copy Markdown
Contributor

another option would be to use NIX_LDFLAGS = [ "-lstdc++" ];. But this should probably fixed upstream if that's the case

@auscyber
Copy link
Copy Markdown
Contributor Author

auscyber commented Dec 3, 2021

another option would be to use NIX_LDFLAGS = [ "-lstdc++" ];. But this should probably fixed upstream if that's the case

this actually works. on systems other than nixos its not a problem so adding it upstream is a bit overkill

@auscyber
Copy link
Copy Markdown
Contributor Author

auscyber commented Dec 3, 2021

could you provide instructions (nix expressions) to generate a failure that is fixed by this PR ? evntually a test in pkgs/applications/editors/neovim/tests.nix that fails without this PR

I couldnt do this. as the entire feature is about allowing neovim to externally download precompiled parsers. which you cannot do inside a nix environment

Copy link
Copy Markdown
Member

@rvolosatovs rvolosatovs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not required for tree-sitter per se, it is required for imperative installation of tree-sitter grammars.
The supported way to do this in nix is doing it declaratively, e.g. like this https://github.com/rvolosatovs/infrastructure/blob/dbbc2579dddb203f780fdf8935bb449887d59ada/nixpkgs/neovim/default.nix#L13.

Is libstdc++ already linked into the resulting binary and we are merely fixing the path here or are we adding a new link?

I don't mind adding support for the imperative approach, but I do mind adding an otherwise-redundant dependency on cc for all neovim installations by default, therefore I think I'd rather see this guarded by an opt-in config, unless we're just fixing an invalid link in the binary.

@jonringer
Copy link
Copy Markdown
Contributor

another option would be to use NIX_LDFLAGS = [ "-lstdc++" ];. But this should probably fixed upstream if that's the case

this actually works. on systems other than nixos its not a problem so adding it upstream is a bit overkill

The reason why I proposed for upstream to fix it, is that there is a dependency on the c++ runtime, but it's not being explicit about it. I really do not like mandatory usage of dlopen, if it's a requirement, then you should just link explicitly to it.

@jonringer
Copy link
Copy Markdown
Contributor

Looking at upstream, there's no explicit requirement for c++ https://github.com/neovim/neovim/blob/master/CMakeLists.txt

linking against c++ should not be required.

@jonringer
Copy link
Copy Markdown
Contributor

Do you mind providing an example use case where the failure occurs?

@auscyber
Copy link
Copy Markdown
Contributor Author

auscyber commented Dec 4, 2021

This change is not required for tree-sitter per se, it is required for imperative installation of tree-sitter grammars. The supported way to do this in nix is doing it declaratively, e.g. like this https://github.com/rvolosatovs/infrastructure/blob/dbbc2579dddb203f780fdf8935bb449887d59ada/nixpkgs/neovim/default.nix#L13.

Is libstdc++ already linked into the resulting binary and we are merely fixing the path here or are we adding a new link?

I don't mind adding support for the imperative approach, but I do mind adding an otherwise-redundant dependency on cc for all neovim installations by default, therefore I think I'd rather see this guarded by an opt-in config, unless we're just fixing an invalid link in the binary.

the imperative way allows for easy usage on on nixos sysytems or windows, i'd hate to have a way to check if its nix and then link the parsers and somehow find a way for them to be the same.

@auscyber
Copy link
Copy Markdown
Contributor Author

auscyber commented Dec 4, 2021

Do you mind providing an example use case where the failure occurs?

Use neovim-master, and setup a parser like c or nix, and then try and use it. it fails hard on not being able to find libstdc++.so.6 on linux when it downloads the parsers and compiles them with cc

@auscyber
Copy link
Copy Markdown
Contributor Author

auscyber commented Dec 4, 2021

Looking at upstream, there's no explicit requirement for c++ https://github.com/neovim/neovim/blob/master/CMakeLists.txt

linking against c++ should not be required.

Because it uses your system cc to compile the parsers.

@rvolosatovs
Copy link
Copy Markdown
Member

This change is not required for tree-sitter per se, it is required for imperative installation of tree-sitter grammars. The supported way to do this in nix is doing it declaratively, e.g. like this https://github.com/rvolosatovs/infrastructure/blob/dbbc2579dddb203f780fdf8935bb449887d59ada/nixpkgs/neovim/default.nix#L13.

Is libstdc++ already linked into the resulting binary and we are merely fixing the path here or are we adding a new link?

I don't mind adding support for the imperative approach, but I do mind adding an otherwise-redundant dependency on cc for all neovim installations by default, therefore I think I'd rather see this guarded by an opt-in config, unless we're just fixing an invalid link in the binary.

the imperative way allows for easy usage on on nixos sysytems or windows, i'd hate to have a way to check if its nix and then link the parsers and somehow find a way for them to be the same.

I don't see why, tree-sitter grammars are already packaged in nixpkgs and neovim package supports plugin configuration including tree-sitter.

The OS is irrelevant here, because the change you're suggesting allows compilation and installation of tree-sitter grammars without relying on nix.
So you want to allow manually building something that nix can already build.

I think this is mostly the question of what we need to support in nixpkgs. We have several OS-agnostic plugin management approaches supported for neovim. I think that we should consider those ways of plugin installation "officially supported".
If you used one of the "officially supported" means of neovim plugin installation, you wouldn't have a problem, since you'd rely on tree-sitter grammars already packaged in nixpkgs.
The only supported use case for this I see is manually compiling tree-sitter grammars, which are not already packaged in nixpkgs, from within neovim. Well, the supported way to do it is to package the grammar.

In fact, I'd argue that I explicitly don't want my neovim installation to be able to silently compile grammars at runtime and rely on that state. This beats the purpose of configuring neovim via nix in the first place, since it hurts purity and I want to minimize the local state my editor depends on.

I don't see this change as necessary, but don't object if it's guarded by an opt-in configuration flag.

@rvolosatovs
Copy link
Copy Markdown
Member

Given this shell.nix file:

{ pkgs ? import <nixpkgs> { } }:
let
  neovim = pkgs.wrapNeovim pkgs.neovim-unwrapped {
    configure.packages.plugins.start = with pkgs.vimPlugins; [
      (nvim-treesitter.withPlugins (_: pkgs.tree-sitter.allGrammars))
    ];
  };
in
pkgs.mkShell {
  buildInputs = with pkgs; [
    neovim
  ];
}

this is what

nix-shell --pure --run "nvim -c 'checkhealth treesitter nvim_treesitter'"

prints:


nvim_treesitter: health#nvim_treesitter#check
========================================================================
## Installation
  - WARNING: `tree-sitter` executable not found (parser generator, only needed for :TSInstallFromGrammar, not required for :TSInstall)
  - WARNING: `node` executable not found (only needed for :TSInstallFromGrammar, not required for :TSInstall)
  - ERROR: `git` executable not found.
    - ADVICE:
      - Install it with your package manager.
      - Check that your `$PATH` is set correctly.
  - OK: `gcc` executable found. Selected from { "gcc", "cc", "gcc", "clang", "cl" }
  - OK: Neovim was compiled with tree-sitter runtime ABI version 13 (required >=13). Parsers must be compatible with runtime ABI.

## Parser/Features H L F I J
  - ERROR: fennel(highlights): ...ed-0.6.0/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: error at position 551
  - ERROR: fennel(locals): ...ed-0.6.0/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: error at position 235
  - ERROR: verilog(highlights): ...0.6.0/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /nix/store/9l3zjb7zidrzyrq165xha3sihr60j2zm-vim-pack-dir/pack/plugins/start/nvim-treesitter/parser/verilog.so: supported between 13 and 13, found 12
  - ERROR: verilog(locals): ...0.6.0/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /nix/store/9l3zjb7zidrzyrq165xha3sihr60j2zm-vim-pack-dir/pack/plugins/start/nvim-treesitter/parser/verilog.so: supported between 13 and 13, found 12
  - ERROR: verilog(folds): ...0.6.0/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /nix/store/9l3zjb7zidrzyrq165xha3sihr60j2zm-vim-pack-dir/pack/plugins/start/nvim-treesitter/parser/verilog.so: supported between 13 and 13, found 12
  - ERROR: verilog(injections): ...0.6.0/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /nix/store/9l3zjb7zidrzyrq165xha3sihr60j2zm-vim-pack-dir/pack/plugins/start/nvim-treesitter/parser/verilog.so: supported between 13 and 13, found 12
  - ERROR: cpp(highlights): ...ed-0.6.0/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 3163
  - ERROR: cpp(locals): ...ed-0.6.0/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 1799
  - ERROR: zig(highlights): ...ed-0.6.0/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 1012
  - ERROR: c_sharp(highlights): ...ed-0.6.0/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: error at position 5112

vim.treesitter: require("vim.treesitter.health").check()
========================================================================
  - INFO: Runtime ABI version : 13
  - ERROR: Impossible to load parser for agda: ...0.6.0/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /nix/store/9l3zjb7zidrzyrq165xha3sihr60j2zm-vim-pack-dir/pack/plugins/start/nvim-treesitter/parser/agda.so: supported between 13 and 13, found 10
  - OK: Loaded parser for bash: ABI version 13
  - OK: Loaded parser for beancount: ABI version 13
  - OK: Loaded parser for c: ABI version 13
  - OK: Loaded parser for c_sharp: ABI version 13
  - OK: Loaded parser for clojure: ABI version 13
  - OK: Loaded parser for comment: ABI version 13
  - OK: Loaded parser for cpp: ABI version 13
  - OK: Loaded parser for css: ABI version 13
  - OK: Loaded parser for dart: ABI version 13
  - OK: Loaded parser for dot: ABI version 13
  - OK: Loaded parser for elisp: ABI version 13
  - OK: Loaded parser for embedded_template: ABI version 13
  - OK: Loaded parser for fennel: ABI version 13
  - OK: Loaded parser for fish: ABI version 13
  - ERROR: Impossible to load parser for fluent: ...0.6.0/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /nix/store/9l3zjb7zidrzyrq165xha3sihr60j2zm-vim-pack-dir/pack/plugins/start/nvim-treesitter/parser/fluent.so: supported between 13 and 13, found 8
  - OK: Loaded parser for go: ABI version 13
  - OK: Loaded parser for haskell: ABI version 13
  - OK: Loaded parser for html: ABI version 13
  - OK: Loaded parser for java: ABI version 13
  - OK: Loaded parser for javascript: ABI version 13
  - OK: Loaded parser for jsdoc: ABI version 13
  - OK: Loaded parser for json: ABI version 13
  - OK: Loaded parser for julia: ABI version 13
  - OK: Loaded parser for latex: ABI version 13
  - OK: Loaded parser for lua: ABI version 13
  - OK: Loaded parser for make: ABI version 13
  - OK: Loaded parser for markdown: ABI version 13
  - OK: Loaded parser for nix: ABI version 13
  - OK: Loaded parser for norg: ABI version 13
  - OK: Loaded parser for ocaml: ABI version 13
  - OK: Loaded parser for ocaml_interface: ABI version 13
  - OK: Loaded parser for php: ABI version 13
  - OK: Loaded parser for python: ABI version 13
  - OK: Loaded parser for ql: ABI version 13
  - OK: Loaded parser for regex: ABI version 13
  - OK: Loaded parser for rst: ABI version 13
  - OK: Loaded parser for ruby: ABI version 13
  - OK: Loaded parser for rust: ABI version 13
  - OK: Loaded parser for scala: ABI version 13
  - OK: Loaded parser for svelte: ABI version 13
  - ERROR: Impossible to load parser for swift: ...0.6.0/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /nix/store/9l3zjb7zidrzyrq165xha3sihr60j2zm-vim-pack-dir/pack/plugins/start/nvim-treesitter/parser/swift.so: supported between 13 and 13, found 10
  - OK: Loaded parser for toml: ABI version 13
  - OK: Loaded parser for tsq: ABI version 13
  - OK: Loaded parser for tsx: ABI version 13
  - OK: Loaded parser for typescript: ABI version 13
  - ERROR: Impossible to load parser for verilog: ...0.6.0/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /nix/store/9l3zjb7zidrzyrq165xha3sihr60j2zm-vim-pack-dir/pack/plugins/start/nvim-treesitter/parser/verilog.so: supported between 13 and 13, found 12
  - OK: Loaded parser for vim: ABI version 13
  - OK: Loaded parser for yaml: ABI version 13
  - OK: Loaded parser for zig: ABI version 13

By some weird reason the table of working grammars is not rendered, but that how it looks on my setup configuring the grammars in exactly the same way:

## Parser/Features H L F I J
  - svelte         x . ✓ ✓ ✓ 
  - ruby           ✓ ✓ ✓ ✓ ✓ 
  - cpp            x x ✓ ✓ ✓ 
  - bash           ✓ ✓ ✓ . ✓ 
  - latex          ✓ . ✓ . ✓ 
  - fish           ✓ ✓ ✓ ✓ ✓ 
  - php            ✓ ✓ ✓ ✓ ✓ 
  - java           ✓ ✓ . ✓ ✓ 
  - html           ✓ ✓ ✓ ✓ ✓ 
  - css            ✓ . ✓ ✓ ✓ 
  - ocaml          ✓ ✓ ✓ . ✓ 
  - c              ✓ ✓ ✓ ✓ ✓ 
  - go             ✓ ✓ ✓ ✓ ✓ 
  - ocaml_interface✓ ✓ ✓ . ✓ 
  - c_sharp        ✓ ✓ ✓ . ✓ 
  - typescript     ✓ ✓ ✓ ✓ ✓ 
  - tsx            ✓ ✓ ✓ ✓ ✓ 
  - haskell        ✓ . . . ✓ 
  - scala          ✓ . ✓ . ✓ 
  - dart           ✓ ✓ . ✓ ✓ 
  - toml           ✓ ✓ ✓ ✓ ✓ 
  - rst            ✓ ✓ . . ✓ 
  - fennel         x x . . ✓ 
  - javascript     ✓ ✓ ✓ ✓ ✓ 
  - vim            ✓ ✓ . . ✓ 
  - regex          ✓ . . . . 
  - zig            x . ✓ ✓ ✓ 
  - julia          ✓ ✓ ✓ ✓ ✓ 
  - clojure        ✓ ✓ ✓ . ✓ 
  - comment        ✓ . . . . 
  - yaml           ✓ ✓ ✓ ✓ ✓ 
  - jsdoc          ✓ . . . . 
  - nix            ✓ ✓ ✓ . ✓ 
  - verilog        x x x . x 
  - json           ✓ ✓ ✓ ✓ . 
  - lua            ✓ ✓ ✓ ✓ ✓ 
  - rust           ✓ ✓ ✓ ✓ ✓ 
  - dot            ✓ . . . ✓ 
  - ql             ✓ ✓ . ✓ ✓ 
  - python         ✓ ✓ ✓ ✓ ✓ 

 Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
         +) multiple parsers found, only one will be used
         x) errors found in the query, try to run :TSUpdate {lang}

@github-actions github-actions bot added the 6.topic: vim Advanced text editor label Dec 4, 2021
@auscyber
Copy link
Copy Markdown
Contributor Author

auscyber commented Dec 4, 2021

Given this shell.nix file:

{ pkgs ? import <nixpkgs> { } }:
let
  neovim = pkgs.wrapNeovim pkgs.neovim-unwrapped {
    configure.packages.plugins.start = with pkgs.vimPlugins; [
      (nvim-treesitter.withPlugins (_: pkgs.tree-sitter.allGrammars))
    ];
  };
in
pkgs.mkShell {
  buildInputs = with pkgs; [
    neovim
  ];
}

this is what

nix-shell --pure --run "nvim -c 'checkhealth treesitter nvim_treesitter'"

prints:


nvim_treesitter: health#nvim_treesitter#check
========================================================================
## Installation
  - WARNING: `tree-sitter` executable not found (parser generator, only needed for :TSInstallFromGrammar, not required for :TSInstall)
  - WARNING: `node` executable not found (only needed for :TSInstallFromGrammar, not required for :TSInstall)
  - ERROR: `git` executable not found.
    - ADVICE:
      - Install it with your package manager.
      - Check that your `$PATH` is set correctly.
  - OK: `gcc` executable found. Selected from { "gcc", "cc", "gcc", "clang", "cl" }
  - OK: Neovim was compiled with tree-sitter runtime ABI version 13 (required >=13). Parsers must be compatible with runtime ABI.

## Parser/Features H L F I J
  - ERROR: fennel(highlights): ...ed-0.6.0/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: error at position 551
  - ERROR: fennel(locals): ...ed-0.6.0/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: error at position 235
  - ERROR: verilog(highlights): ...0.6.0/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /nix/store/9l3zjb7zidrzyrq165xha3sihr60j2zm-vim-pack-dir/pack/plugins/start/nvim-treesitter/parser/verilog.so: supported between 13 and 13, found 12
  - ERROR: verilog(locals): ...0.6.0/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /nix/store/9l3zjb7zidrzyrq165xha3sihr60j2zm-vim-pack-dir/pack/plugins/start/nvim-treesitter/parser/verilog.so: supported between 13 and 13, found 12
  - ERROR: verilog(folds): ...0.6.0/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /nix/store/9l3zjb7zidrzyrq165xha3sihr60j2zm-vim-pack-dir/pack/plugins/start/nvim-treesitter/parser/verilog.so: supported between 13 and 13, found 12
  - ERROR: verilog(injections): ...0.6.0/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /nix/store/9l3zjb7zidrzyrq165xha3sihr60j2zm-vim-pack-dir/pack/plugins/start/nvim-treesitter/parser/verilog.so: supported between 13 and 13, found 12
  - ERROR: cpp(highlights): ...ed-0.6.0/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 3163
  - ERROR: cpp(locals): ...ed-0.6.0/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 1799
  - ERROR: zig(highlights): ...ed-0.6.0/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 1012
  - ERROR: c_sharp(highlights): ...ed-0.6.0/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: error at position 5112

vim.treesitter: require("vim.treesitter.health").check()
========================================================================
  - INFO: Runtime ABI version : 13
  - ERROR: Impossible to load parser for agda: ...0.6.0/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /nix/store/9l3zjb7zidrzyrq165xha3sihr60j2zm-vim-pack-dir/pack/plugins/start/nvim-treesitter/parser/agda.so: supported between 13 and 13, found 10
  - OK: Loaded parser for bash: ABI version 13
  - OK: Loaded parser for beancount: ABI version 13
  - OK: Loaded parser for c: ABI version 13
  - OK: Loaded parser for c_sharp: ABI version 13
  - OK: Loaded parser for clojure: ABI version 13
  - OK: Loaded parser for comment: ABI version 13
  - OK: Loaded parser for cpp: ABI version 13
  - OK: Loaded parser for css: ABI version 13
  - OK: Loaded parser for dart: ABI version 13
  - OK: Loaded parser for dot: ABI version 13
  - OK: Loaded parser for elisp: ABI version 13
  - OK: Loaded parser for embedded_template: ABI version 13
  - OK: Loaded parser for fennel: ABI version 13
  - OK: Loaded parser for fish: ABI version 13
  - ERROR: Impossible to load parser for fluent: ...0.6.0/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /nix/store/9l3zjb7zidrzyrq165xha3sihr60j2zm-vim-pack-dir/pack/plugins/start/nvim-treesitter/parser/fluent.so: supported between 13 and 13, found 8
  - OK: Loaded parser for go: ABI version 13
  - OK: Loaded parser for haskell: ABI version 13
  - OK: Loaded parser for html: ABI version 13
  - OK: Loaded parser for java: ABI version 13
  - OK: Loaded parser for javascript: ABI version 13
  - OK: Loaded parser for jsdoc: ABI version 13
  - OK: Loaded parser for json: ABI version 13
  - OK: Loaded parser for julia: ABI version 13
  - OK: Loaded parser for latex: ABI version 13
  - OK: Loaded parser for lua: ABI version 13
  - OK: Loaded parser for make: ABI version 13
  - OK: Loaded parser for markdown: ABI version 13
  - OK: Loaded parser for nix: ABI version 13
  - OK: Loaded parser for norg: ABI version 13
  - OK: Loaded parser for ocaml: ABI version 13
  - OK: Loaded parser for ocaml_interface: ABI version 13
  - OK: Loaded parser for php: ABI version 13
  - OK: Loaded parser for python: ABI version 13
  - OK: Loaded parser for ql: ABI version 13
  - OK: Loaded parser for regex: ABI version 13
  - OK: Loaded parser for rst: ABI version 13
  - OK: Loaded parser for ruby: ABI version 13
  - OK: Loaded parser for rust: ABI version 13
  - OK: Loaded parser for scala: ABI version 13
  - OK: Loaded parser for svelte: ABI version 13
  - ERROR: Impossible to load parser for swift: ...0.6.0/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /nix/store/9l3zjb7zidrzyrq165xha3sihr60j2zm-vim-pack-dir/pack/plugins/start/nvim-treesitter/parser/swift.so: supported between 13 and 13, found 10
  - OK: Loaded parser for toml: ABI version 13
  - OK: Loaded parser for tsq: ABI version 13
  - OK: Loaded parser for tsx: ABI version 13
  - OK: Loaded parser for typescript: ABI version 13
  - ERROR: Impossible to load parser for verilog: ...0.6.0/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /nix/store/9l3zjb7zidrzyrq165xha3sihr60j2zm-vim-pack-dir/pack/plugins/start/nvim-treesitter/parser/verilog.so: supported between 13 and 13, found 12
  - OK: Loaded parser for vim: ABI version 13
  - OK: Loaded parser for yaml: ABI version 13
  - OK: Loaded parser for zig: ABI version 13

By some weird reason the table of working grammars is not rendered, but that how it looks on my setup configuring the grammars in exactly the same way:

## Parser/Features H L F I J
  - svelte         x . ✓ ✓ ✓ 
  - ruby           ✓ ✓ ✓ ✓ ✓ 
  - cpp            x x ✓ ✓ ✓ 
  - bash           ✓ ✓ ✓ . ✓ 
  - latex          ✓ . ✓ . ✓ 
  - fish           ✓ ✓ ✓ ✓ ✓ 
  - php            ✓ ✓ ✓ ✓ ✓ 
  - java           ✓ ✓ . ✓ ✓ 
  - html           ✓ ✓ ✓ ✓ ✓ 
  - css            ✓ . ✓ ✓ ✓ 
  - ocaml          ✓ ✓ ✓ . ✓ 
  - c              ✓ ✓ ✓ ✓ ✓ 
  - go             ✓ ✓ ✓ ✓ ✓ 
  - ocaml_interface✓ ✓ ✓ . ✓ 
  - c_sharp        ✓ ✓ ✓ . ✓ 
  - typescript     ✓ ✓ ✓ ✓ ✓ 
  - tsx            ✓ ✓ ✓ ✓ ✓ 
  - haskell        ✓ . . . ✓ 
  - scala          ✓ . ✓ . ✓ 
  - dart           ✓ ✓ . ✓ ✓ 
  - toml           ✓ ✓ ✓ ✓ ✓ 
  - rst            ✓ ✓ . . ✓ 
  - fennel         x x . . ✓ 
  - javascript     ✓ ✓ ✓ ✓ ✓ 
  - vim            ✓ ✓ . . ✓ 
  - regex          ✓ . . . . 
  - zig            x . ✓ ✓ ✓ 
  - julia          ✓ ✓ ✓ ✓ ✓ 
  - clojure        ✓ ✓ ✓ . ✓ 
  - comment        ✓ . . . . 
  - yaml           ✓ ✓ ✓ ✓ ✓ 
  - jsdoc          ✓ . . . . 
  - nix            ✓ ✓ ✓ . ✓ 
  - verilog        x x x . x 
  - json           ✓ ✓ ✓ ✓ . 
  - lua            ✓ ✓ ✓ ✓ ✓ 
  - rust           ✓ ✓ ✓ ✓ ✓ 
  - dot            ✓ . . . ✓ 
  - ql             ✓ ✓ . ✓ ✓ 
  - python         ✓ ✓ ✓ ✓ ✓ 

 Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
         +) multiple parsers found, only one will be used
         x) errors found in the query, try to run :TSUpdate {lang}

you are including the grammars, the problem occurs when you compile the grammars yourself

@auscyber auscyber force-pushed the master branch 3 times, most recently from 1cfd246 to 8247d23 Compare December 4, 2021 12:02
@rvolosatovs
Copy link
Copy Markdown
Member

you are including the grammars, the problem occurs when you compile the grammars yourself

Right, so you are working on some custom unofficial grammar, which is not listed at https://github.com/tree-sitter/tree-sitter/blob/master/docs/index.md and you want to be able to compile it directly from neovim during development?

The "nix way" of including your grammar in neovim would be packaging it in this subtree https://github.com/NixOS/nixpkgs/tree/master/pkgs/development/tools/parsing/tree-sitter, is that not feasible?

@auscyber
Copy link
Copy Markdown
Contributor Author

auscyber commented Dec 4, 2021

I've adjusted it to be an option, link-lstdcpp defaulting

you are including the grammars, the problem occurs when you compile the grammars yourself

Right, so you are working on some custom unofficial grammar, which is not listed at https://github.com/tree-sitter/tree-sitter/blob/master/docs/index.md and you want to be able to compile it directly from neovim during development?

The "nix way" of including your grammar in neovim would be packaging it in this subtree https://github.com/NixOS/nixpkgs/tree/master/pkgs/development/tools/parsing/tree-sitter, is that not feasible?

Even if it is the nix way there still should be an option to be able to not have an entirely nix-only neovim config.

@rvolosatovs
Copy link
Copy Markdown
Member

rvolosatovs commented Dec 4, 2021

Even if it is the nix way there still should be an option to be able to not have an entirely nix-only neovim config.

I completely agree and that's exactly why I'm saying it should be guarded by an opt-in flag and considered an unsupported way of doing this (i.e. it can break in the future, but we'll do our best to ensure it doesn't).

@ofborg ofborg bot requested a review from rvolosatovs December 4, 2021 12:14
Copy link
Copy Markdown
Member

@rvolosatovs rvolosatovs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with adding the opt-in parameter, but don't know if NIX_LD_FLAGS is the right approach, looking at the docs it seems like it should be.

@auscyber
Copy link
Copy Markdown
Contributor Author

auscyber commented Dec 6, 2021

It should be perfectly good now

@pinpox
Copy link
Copy Markdown
Member

pinpox commented Dec 9, 2021

Can confirm this issue on nixos. I get the following error when opening a lua file with treesitter enabled:

Error detected while processing FileType Autocommands for "*":
E5108: Error executing lua Failed to load parser: uv_dlopen: libstdc++.so.6: cannot open shared object file: No such
 file or directory
stack traceback:
        [C]: in function '_ts_add_language'
        ...aster/share/nvim/runtime/lua/vim/treesitter/language.lua:33: in function 'require_language'
        ...wrapped-master/share/nvim/runtime/lua/vim/treesitter.lua:38: in function '_create_parser'
        ...wrapped-master/share/nvim/runtime/lua/vim/treesitter.lua:93: in function 'get_parser'
        .../start/nvim-treesitter/lua/nvim-treesitter/highlight.lua:107: in function 'attach'
        ...er/start/nvim-treesitter/lua/nvim-treesitter/configs.lua:459: in function 'attach_module'
        ...er/start/nvim-treesitter/lua/nvim-treesitter/configs.lua:482: in function 'reattach_module'
        [string ":lua"]:1: in main chunk
Press ENTER or type command to continue

@thornycrackers
Copy link
Copy Markdown
Contributor

Can this be merged? I still get this error with treesitter and would love to have this merged.

Copy link
Copy Markdown
Contributor

@jonringer jonringer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stdenv.cc.cc.lib is already in the runtime closure. I say we just forcefully add it as a flag, and call it a day.


# now defaults to false because some tests can be flaky (clipboard etc)
, doCheck ? false
, doCheck ? false, link-lstdcpp ? false
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
, doCheck ? false, link-lstdcpp ? false
, doCheck ? false

substituteInPlace src/nvim/CMakeLists.txt --replace " util" ""
'';

NIX_LDFLAGS = optional link-lstdcpp [ "-lstdc++"];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just add a comment, as to why this is necessary

Suggested change
NIX_LDFLAGS = optional link-lstdcpp [ "-lstdc++"];
# For treesitter plugins, libstdc++.so.6 will be needed
NIX_LDFLAGS = [ "-lstdc++"];

@jonringer
Copy link
Copy Markdown
Contributor

changes applied in #155688

@teto
Copy link
Copy Markdown
Member

teto commented Mar 19, 2022

this breaks the neovim development flake. neovim and treesitter are C libraries, why do we need this ? maybe it's those treesitter libraries that are wrongly packaged out of nixpkgs and need fixing instead of adding hacks on a fine setup.

❯ nix develop github:neovim/neovim?dir=contrib
zsh: no matches found: github:neovim/neovim?dir=contrib
~ via 🌙 
❯ nix develop 'github:neovim/neovim?dir=contrib'
~ via 🌙 v2.1.0-beta3 via ❄️  IMPURE (neovim-unwrapped-master) 
(ins)➜ cd /tmp
/tmp via ❄️  IMPURE (neovim-unwrapped-master) took 6s 
(ins)➜ genericBuild 
unpacking sources
unpacking source archive /nix/store/3xighsn2nfnfw25parnd185pjqzl0rfv-6cjpi4i3rzq7m6wk1d2pygsj5yvhgmz0-source
source root is 6cjpi4i3rzq7m6wk1d2pygsj5yvhgmz0-source
patching sources
applying patch /nix/store/jnp9n2x9cdvl47da3656illrd3p2qvb5-system_rplugin_manifest.patch
patching file runtime/autoload/remote/host.vim
patching file runtime/plugin/rplugin.vim
configuring
cmake flags: -DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF -DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_SKIP_BUILD_RPATH=ON -DCMAKE_INSTALL_LOCALEDIR=/home/teto/outputs/out/share/locale -DCMAKE_INSTALL_LIBEXECDIR=/home/teto/outputs/out/libexec -DCMAKE_INSTALL_LIBDIR=/home/teto/outputs/out/lib -DCMAKE_INSTALL_DOCDIR=/home/teto/outputs/out/share/doc/nvim -DCMAKE_INSTALL_INFODIR=/home/teto/outputs/out/share/info -DCMAKE_INSTALL_MANDIR=/home/teto/outputs/out/share/man -DCMAKE_INSTALL_OLDINCLUDEDIR=/home/teto/outputs/out/include -DCMAKE_INSTALL_INCLUDEDIR=/home/teto/outputs/out/include -DCMAKE_INSTALL_SBINDIR=/home/teto/outputs/out/sbin -DCMAKE_INSTALL_BINDIR=/home/teto/outputs/out/bin -DCMAKE_INSTALL_NAME_DIR=/home/teto/outputs/out/lib -DCMAKE_POLICY_DEFAULT_CMP0025=NEW -DCMAKE_OSX_SYSROOT= -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_STRIP=/nix/store/0sk7aa616ihk43r8fmc770s5vr9nqwij-clang-wrapper-13.0.0/bin/strip -DCMAKE_RANLIB=/nix/store/sga0l55gm9nlwglk79lmihwb2bpv597j-binutils-2.35.2/bin/ranlib -DCMAKE_AR=/nix/store/sga0l55gm9nlwglk79lmihwb2bpv597j-binutils-2.35.2/bin/ar -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_INSTALL_PREFIX=/home/teto/outputs/out -DGPERF_PRG=/nix/store/rga8zbmp395bivj1grldyf34ldkz1h7n-gperf-3.1/bin/gperf -DLUA_PRG=/nix/store/5c944aj1mx7hd45grcjaav7c336y1gag-luajit-2.1.0-2021-10-27-env/bin/lua -DLIBLUV_LIBRARY=/nix/store/cpabffwymllgblxps2ba1zwv6c8jjkq6-luajit-2.1.0-2021-10-27-luv-1.42.0-0/lib/lua/5.1/luv.so -DUSE_BUNDLED=OFF -DBUSTED_PRG=/nix/store/5c944aj1mx7hd45grcjaav7c336y1gag-luajit-2.1.0-2021-10-27-env/bin/busted -DMIN_LOG_LEVEL=0 -DLUACHECK_PRG=/nix/store/agvrjjqj3x378w45diaf2i7rf66j0z4c-lua5.2-luacheck-0.25.0-1/bin/luacheck -DMIN_LOG_LEVEL=0 -DENABLE_LTO=OFF -DCLANG_ASAN_UBSAN=ON 
-- The C compiler identification is Clang 13.0.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /nix/store/0sk7aa616ihk43r8fmc770s5vr9nqwij-clang-wrapper-13.0.0/bin/clang
-- Check for working C compiler: /nix/store/0sk7aa616ihk43r8fmc770s5vr9nqwij-clang-wrapper-13.0.0/bin/clang - broken
CMake Error at /nix/store/sgsvy949kd2sr2vsxcffz5jkv855rmib-cmake-3.22.2/share/cmake-3.22/Modules/CMakeTestCCompiler.cmake:69 (message):
  The C compiler

    "/nix/store/0sk7aa616ihk43r8fmc770s5vr9nqwij-clang-wrapper-13.0.0/bin/clang"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /tmp/6cjpi4i3rzq7m6wk1d2pygsj5yvhgmz0-source/build/CMakeFiles/CMakeTmp
    
    Run Build Command(s):/nix/store/is8wg3j77z9ndpsvkm85sfbrlvvqd66l-gnumake-4.3/bin/make -f Makefile cmTC_f2c62/fast && /nix/store/is8wg3j77z9ndpsvkm85sfbrlvvqd66l-gnumake-4.3/bin/make  -f CMakeFiles/cmTC_f2c62.dir/build.make CMakeFiles/cmTC_f2c62.dir/build
    make[1]: Entering directory '/tmp/6cjpi4i3rzq7m6wk1d2pygsj5yvhgmz0-source/build/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_f2c62.dir/testCCompiler.c.o
    /nix/store/0sk7aa616ihk43r8fmc770s5vr9nqwij-clang-wrapper-13.0.0/bin/clang    -MD -MT CMakeFiles/cmTC_f2c62.dir/testCCompiler.c.o -MF CMakeFiles/cmTC_f2c62.dir/testCCompiler.c.o.d -o CMakeFiles/cmTC_f2c62.dir/testCCompiler.c.o -c /tmp/6cjpi4i3rzq7m6wk1d2pygsj5yvhgmz0-source/build/CMakeFiles/CMakeTmp/testCCompiler.c
    Linking C executable cmTC_f2c62
    /nix/store/sgsvy949kd2sr2vsxcffz5jkv855rmib-cmake-3.22.2/bin/cmake -E cmake_link_script CMakeFiles/cmTC_f2c62.dir/link.txt --verbose=1
    /nix/store/0sk7aa616ihk43r8fmc770s5vr9nqwij-clang-wrapper-13.0.0/bin/clang CMakeFiles/cmTC_f2c62.dir/testCCompiler.c.o -o cmTC_f2c62 
    /nix/store/sga0l55gm9nlwglk79lmihwb2bpv597j-binutils-2.35.2/bin/ld: cannot find -lc++
    clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
    make[1]: *** [CMakeFiles/cmTC_f2c62.dir/build.make:100: cmTC_f2c62] Error 1
    make[1]: Leaving directory '/tmp/6cjpi4i3rzq7m6wk1d2pygsj5yvhgmz0-source/build/CMakeFiles/CMakeTmp'
    make: *** [Makefile:127: cmTC_f2c62/fast] Error 2
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:7 (project)


-- Configuring incomplete, errors occurred!
See also "/tmp/6cjpi4i3rzq7m6wk1d2pygsj5yvhgmz0-source/build/CMakeFiles/CMakeOutput.log".
See also "/tmp/6cjpi4i3rzq7m6wk1d2pygsj5yvhgmz0-source/build/CMakeFiles/CMakeError.log".
cmake: enabled parallel building
building

@jonringer
Copy link
Copy Markdown
Contributor

maybe it's those treesitter libraries that are wrongly packaged out of nixpkgs and need fixing instead of adding hacks on a fine setup.

I think a lot of them are written in c++. But I also don't use treesitter plugins. And using the nixpkgs version was never an issue.

Distributing binary packages without a holistic control over the system is why we are here.

@teto
Copy link
Copy Markdown
Member

teto commented Mar 21, 2022

I am tempted to revert this. @AusCyberman is that an XY problem ? like if we improve the doc on how to install tree sitter grammars from nix or make it easier to configure, does that solve the issue ?

@rvolosatovs
Copy link
Copy Markdown
Member

rvolosatovs commented Mar 21, 2022

Above I suggested to have this as opt-in, and it was so before #147658 (review), why not revert the change to that state instead, so those who want to have this can just set the parameter?

I agree with @teto and also don't think this should be the default (see the discussion above)

@teto
Copy link
Copy Markdown
Member

teto commented Mar 21, 2022

I still dont get the real reason why it's needed. Can we have an example of a treesitter grammar that fails build ? Have you tried taking this to https://github.com/nvim-treesitter/nvim-treesitter/ since I suppose that's what you rely on ?

@jonringer
Copy link
Copy Markdown
Contributor

I still dont get the real reason why it's needed. Can we have an example of a treesitter grammar that fails build ? Have you tried taking this to https://github.com/nvim-treesitter/nvim-treesitter/ since I suppose that's what you rely on ?

AFAICT, it will try to load the plugins by doing a dlopen. If the downloaded binaries need something like the c++ runtime, then it needs to come from somewhere

@teto
Copy link
Copy Markdown
Member

teto commented Mar 21, 2022

indeed, so let's find such a library and see if this is justified or just badly packaged

@teto
Copy link
Copy Markdown
Member

teto commented Mar 29, 2022

I grepped nvim-treesitter code and the stdc++ flag appears here lua/nvim-treesitter/shell_command_selectors.lua , could you try replacing it with libc ? Otherwise I've opened this #130152 that removes the LD hack. IMO it doesn't make sense to hide it behind a flag either. If you have to override neovim anyway, it's best to have the hack in the overlay rather than in nixpkgs (unless the hack is not one and we can understand why it's needed).

teto pushed a commit to teto/nixpkgs that referenced this pull request Mar 29, 2022
some linker flags have been added to support declarative treesitter grammars but the justification is fuzzy and it breaks several stuff on nix see NixOS#147658
@Janik-Haag Janik-Haag added the 12.first-time contribution This PR is the author's first one; please be gentle! label Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: vim Advanced text editor 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.first-time contribution This PR is the author's first one; please be gentle!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants