emacs-lsp / lsp-metals

lsp-mode :heart: metals
https://emacs-lsp.github.io/lsp-metals
GNU General Public License v3.0
58 stars 34 forks source link

using lsp-metals under guix with coursier linux binary launcher #68

Open muradm opened 2 years ago

muradm commented 2 years ago

Describe the bug Currently metals gets bootstraped with coursier binary. However precompiled binaries provided by coursier are not running under Guix due to the nature of distribution and how it deals with linux ld loader.

When (lsp-install-server t 'metals) is executed on such environemnt, *Messages* will have:

LSP :: Download metals started.
(:download :url "https://github.com/coursier/launchers/raw/master/cs-x86_64-pc-linux.gz" :store-path "/home/muradm/.local/share/emacs/var/lsp/server/metals/coursier" :decompress :gzip :set-executable? t)
LSP :: Starting to download https://github.com/coursier/launchers/raw/master/cs-x86_64-pc-linux.gz to /home/muradm/.local/share/emacs/var/lsp/server/metals/coursier.gz...
Contacting host: github.com:443
Wrote /home/muradm/.local/share/emacs/var/lsp/server/metals/coursier.gz
LSP :: Finished downloading /home/muradm/.local/share/emacs/var/lsp/server/metals/coursier.gz...
LSP :: Decompressing /home/muradm/.local/share/emacs/var/lsp/server/metals/coursier.gz...
(Shell command succeeded with no output)
LSP :: Decompressed /home/muradm/.local/share/emacs/var/lsp/server/metals/coursier...
LSP :: Server metals install process failed with the following error message: (file-missing Doing vfork No such file or directory).
Check `*lsp-install*' and `*lsp-log*' buffer.

Below sequence of commands illustrating the issue with downloaded non-working launcher and working ls command as example.

$ wget https://github.com/coursier/launchers/raw/master/cs-x86_64-pc-linux.gz
$ gunzip cs-x86_64-pc-linux.gz
$ chmod a+x cs-x86_64-pc-linux
$ file cs-x86_64-pc-linux
cs-x86_64-pc-linux: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=ba800144eff305fab792b58743c6e5b9aaa50a46, for GNU/Linux 3.2.0, with debug_info, not stripped
$ ./cs-x86_64-pc-linux
bash: ./cs-x86_64-pc-linux: No such file or directory
$ ls -la /lib64/ld-linux-x86-64.so.2
ls: cannot access '/lib64/ld-linux-x86-64.so.2': No such file or directory
$ file $(readlink $(which ls))
/gnu/store/8fpk2cja3f07xls48jfnpgrzrljpqivr-coreutils-8.32/bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /gnu/store/5h2w4qi9hk1qzzgi1w83220ydslinr4s-glibc-2.33/lib/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, stripped
$ ls -la /gnu/store/5h2w4qi9hk1qzzgi1w83220ydslinr4s-glibc-2.33/lib/ld-linux-x86-64.so.2
lrwxrwxrwx 1 root root 10 Jan  1  1970 /gnu/store/5h2w4qi9hk1qzzgi1w83220ydslinr4s-glibc-2.33/lib/ld-linux-x86-64.so.2 -> ld-2.33.so

To Reproduce Setup Guix, emacs for your liking and try (lsp-install-server t 'metals).

Expected behavior Should be possible to use lsp-metals out-of-the-box.

In order to solve this issue, it could be better to use jar version of coursier launcher. It requires only java to be present in the system, which should be available any way. It will also simplify things for multiple platforms, as it should be running on any platform having java preinstalled.

Workaround Dig lsp-metals to identify how coursier is used. Find emacs lsp server install path. Do the lsp-install-server work manually. For instance:

# for me lsp server install path is below
$ cd ~/.local/share/emacs/var/lsp/server/metals
$ wget https://github.com/coursier/launchers/raw/master/coursier.jar
$ java -jar coursier.jar bootstrap --java-opt -Xss4m --java-opt -Xms100m org.scalameta:metals_2.12:latest.release -r bintray:scalacenter/releases -r sonatype:snapshots -o metals
kurnevsky commented 2 years ago

I have the same problem on nixos. But if you have coursier installed on your system it should work fine: https://github.com/emacs-lsp/lsp-metals/blob/6980fb902c3c7b43ff0d4056a6cd7d8b4709866e/lsp-metals.el#L252-L253 Looks like coursier suggests to use native launchers by default: https://get-coursier.io/docs/cli-installation#native-launcher but I'm not sure whether it makes sence in our case - we will need jvm anyway to launch metals.