ghdl-language-server icon indicating copy to clipboard operation
ghdl-language-server copied to clipboard

ghdl-ls Traceback on Windows

Open gralco opened this issue 2 years ago • 7 comments

Description After installing ghdl using the latest commit, attempting to run ghdl-ls on Windows fails (tested on Fedora and it works fine).

Context

  • OS: Windows 10
  • Origin: Built from sources: 71287d46036e45f2bcafbc06e4b1ca1b37d48b85

Here's the traceback I get when trying to run ghdl-ls:

$ ghdl-ls
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "%LOCALAPPDATA%\Programs\Python\Python312\Scripts\ghdl-ls.exe\__main__.py", line 4, in <module>
  File "%LOCALAPPDATA%\Programs\Python\Python312\Lib\site-packages\pyGHDL\cli\lsp.py", line 58, in <module>
    from pyGHDL.lsp.vhdl_ls import VhdlLanguageServer
  File "%LOCALAPPDATA%\Programs\Python\Python312\Lib\site-packages\pyGHDL\lsp\vhdl_ls.py", line 4, in <module>
    from .workspace import Workspace
  File "%LOCALAPPDATA%\Programs\Python\Python312\Lib\site-packages\pyGHDL\lsp\workspace.py", line 12, in <module>
    import pyGHDL.libghdl.vhdl.nodes as nodes
  File "%LOCALAPPDATA%\Programs\Python\Python312\Lib\site-packages\pyGHDL\libghdl\vhdl\nodes.py", line 3662, in <module>
    @BindToLibGHDL("vhdl__nodes__get_mode_view_indication")
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "%LOCALAPPDATA%\Programs\Python\Python312\Lib\site-packages\pyGHDL\libghdl\_decorator.py", line 161, in wrapper
    functionPointer = getattr(libghdl, subprogramName)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "%LOCALAPPDATA%\Programs\Python\Python312\Lib\ctypes\__init__.py", line 392, in __getattr__
    func = self.__getitem__(name)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "%LOCALAPPDATA%\Programs\Python\Python312\Lib\ctypes\__init__.py", line 397, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: function 'vhdl__nodes__get_mode_view_indication' not found. Did you mean: 'vhdl__nodes__get_subtype_indication'?

gralco avatar Oct 25 '23 21:10 gralco

Hello,

you need to update libghdl: just re-install ghdl.

Your issue is a little bit weird: you have updated ghdl-language-server, you have update pyGHDL from ghdl, but the libghdl dll has not been updated.

tgingold avatar Oct 26 '23 05:10 tgingold

I managed to build ghdl from source, but I first had to fix this:

$HOME/ghdl/src/grt/config/win32.c:183: undefined reference to `__intrinsic_setjmpex'
collect2.exe: error: ld returned 1 exit status
gnatlink: error when calling C:\msys64\mingw64\bin\gcc.exe
gnatmake: *** link failed.
make: *** [Makefile:217: ghdl_mcode.exe] Error 4

By changing #include <setjmp.h> with #include <setjmpex.h> in ghdl/src/grt/config/win32.c (as suggested here).

gralco avatar Oct 26 '23 14:10 gralco

For reference, in order to make ghdl-ls to function within neovim I needed to add the following in my init.lua file:

if not require'lspconfig.configs'.ghdl_ls then
  require'lspconfig.configs'.ghdl_ls = {
    default_config = {
      cmd = {"ghdl-ls"};
      filetypes = {"vhdl"};
      root_dir = function(fname)
        local util = require'lspconfig'.util
        return vim.fs.dirname(vim.fs.find({'hdl-prj.json'}, {upward=true})[1]) or util.root_pattern('hdl-prj.json')(fname) or util.find_git_ancestor(fname) or vim.fn.getcwd() or util.path.dirname(fname) 
      end;
      settings = {};
    };
  }
end

require'lspconfig'.ghdl_ls.setup{}

Otherwise it the LSP will not be able to find / hook onto the root directory where the vhdl code is located. Doing single_file_mode = true is not enough to make it work.

gralco avatar Oct 26 '23 15:10 gralco

Is the dll path correct and does it exist?

If yes, the error is probably due to a dependency (libgcc or libgnat). You need to update PATH.

tgingold avatar Oct 26 '23 17:10 tgingold

Is the dll path correct and does it exist? If yes, the error is probably due to a dependency (libgcc or libgnat). You need to update PATH.

I managed to fix that by building ghdl from source.

gralco avatar Oct 27 '23 00:10 gralco

I somehow ran into this issue again. As it turns out, what I needed to do was to copy over my built libghdl-4_0_0_dev.dll into /c/msys64/mingw64/lib/libghdl-4_0_0_dev.dll, that's where it's looking for libghdl (where there was an old libghdl.dll that wasn't updated when doing make install).

gralco avatar Nov 03 '23 18:11 gralco

On Fedora 38 the libghdl-4_0_0_dev.so that's built needs to be in ~/.local/lib/.

gralco avatar Nov 07 '23 03:11 gralco