From 88aa5277fbfb87e359838660e381b8e65a69e9fa Mon Sep 17 00:00:00 2001 From: treatybreaker <58627896+treatybreaker@users.noreply.github.com> Date: Sun, 6 Mar 2022 20:53:09 +0000 Subject: Support libc detection (#527) --- lua/nvim-lsp-installer/installers/context.lua | 4 ++-- lua/nvim-lsp-installer/platform.lua | 10 ++++++++++ lua/nvim-lsp-installer/servers/rust_analyzer/init.lua | 12 ++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) (limited to 'lua') diff --git a/lua/nvim-lsp-installer/installers/context.lua b/lua/nvim-lsp-installer/installers/context.lua index 7f3761d6..3dda0ab2 100644 --- a/lua/nvim-lsp-installer/installers/context.lua +++ b/lua/nvim-lsp-installer/installers/context.lua @@ -84,8 +84,8 @@ function M.use_github_release_file(repo, file, opts) ) context.stdio_sink.stderr( ( - "Could not find which release file to download. Most likely, the current operating system or architecture (%s) is not supported.\n" - ):format(platform.arch) + "Could not find which release file to download. Most likely the current operating system, architecture (%s), or libc (%s) is not supported.\n" + ):format(platform.arch, platform.get_libc()) ) return nil end diff --git a/lua/nvim-lsp-installer/platform.lua b/lua/nvim-lsp-installer/platform.lua index 9ab54c6a..62c74046 100644 --- a/lua/nvim-lsp-installer/platform.lua +++ b/lua/nvim-lsp-installer/platform.lua @@ -25,6 +25,16 @@ M.is_unix = vim.fn.has "unix" == 1 M.is_mac = vim.fn.has "mac" == 1 M.is_linux = not M.is_mac and M.is_unix +-- @return string @The libc found on the system, musl or glibc (glibc if ldd is not found) +function M.get_libc() + local _, _, libc_exit_code = os.execute "ldd --version 2>&1 | grep -q musl" + if libc_exit_code == 0 then + return "musl" + else + return "glibc" + end +end + -- PATH separator M.path_sep = M.is_win and ";" or ":" diff --git a/lua/nvim-lsp-installer/servers/rust_analyzer/init.lua b/lua/nvim-lsp-installer/servers/rust_analyzer/init.lua index b2c8f7b8..5651cc7f 100644 --- a/lua/nvim-lsp-installer/servers/rust_analyzer/init.lua +++ b/lua/nvim-lsp-installer/servers/rust_analyzer/init.lua @@ -7,6 +7,8 @@ local Data = require "nvim-lsp-installer.data" local coalesce, when = Data.coalesce, Data.when +local libc = platform.get_libc() + local target = coalesce( when( platform.is_mac, @@ -18,8 +20,14 @@ local target = coalesce( when( platform.is_linux, coalesce( - when(platform.arch == "arm64", "rust-analyzer-aarch64-unknown-linux-gnu.gz"), - when(platform.arch == "x64", "rust-analyzer-x86_64-unknown-linux-gnu.gz") + when( + libc == "glibc", + coalesce( + when(platform.arch == "arm64", "rust-analyzer-aarch64-unknown-linux-gnu.gz"), + when(platform.arch == "x64", "rust-analyzer-x86_64-unknown-linux-gnu.gz") + ) + ), + when(libc == "musl", coalesce(when(platform.arch == "x64", "rust-analyzer-x86_64-unknown-linux-musl.gz"))) ) ), when( -- cgit v1.2.3-70-g09d2