aboutsummaryrefslogtreecommitdiffstats
path: root/lua/mason-core/platform.lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-10-10 19:34:28 +0200
committerGitHub <noreply@github.com>2022-10-10 19:34:28 +0200
commitb83c31c46e41f101778369fe00122a169099e638 (patch)
tree9247bd3ab54d2b96bbbeaeac65b885bf6492bd07 /lua/mason-core/platform.lua
parentfix(visualforce-language-server): remove custom release resolution code (#534) (diff)
downloadmason-b83c31c46e41f101778369fe00122a169099e638.tar
mason-b83c31c46e41f101778369fe00122a169099e638.tar.gz
mason-b83c31c46e41f101778369fe00122a169099e638.tar.bz2
mason-b83c31c46e41f101778369fe00122a169099e638.tar.lz
mason-b83c31c46e41f101778369fe00122a169099e638.tar.xz
mason-b83c31c46e41f101778369fe00122a169099e638.tar.zst
mason-b83c31c46e41f101778369fe00122a169099e638.zip
feat(platform): better glibc detection (#537)
Diffstat (limited to 'lua/mason-core/platform.lua')
-rw-r--r--lua/mason-core/platform.lua27
1 files changed, 22 insertions, 5 deletions
diff --git a/lua/mason-core/platform.lua b/lua/mason-core/platform.lua
index f6c3a4b5..fef9de00 100644
--- a/lua/mason-core/platform.lua
+++ b/lua/mason-core/platform.lua
@@ -25,14 +25,31 @@ M.sysname = uname.sysname
M.is_headless = #vim.api.nvim_list_uis() == 0
--- @return string @The libc found on the system, musl or glibc (glibc if ldd is not found)
+local function system(args)
+ if vim.fn.executable(args[1]) == 1 then
+ local ok, output = pcall(vim.fn.system, args)
+ if ok and vim.v.shell_error == 0 then
+ return true, output
+ end
+ return false, output
+ end
+ return false, args[1] .. " is not executable"
+end
+
+---@type fun(): ('"glibc"' | '"musl"')?
local get_libc = _.lazy(function()
- local _, _, libc_exit_code = os.execute "ldd --version 2>&1 | grep -q musl"
- if libc_exit_code == 0 then
- return "musl"
- else
+ local getconf_ok, getconf_output = system { "getconf", "GNU_LIBC_VERSION" }
+ if getconf_ok and getconf_output:find "glibc" then
return "glibc"
end
+ local ldd_ok, ldd_output = system { "ldd", "--version" }
+ if ldd_ok then
+ if ldd_output:find "musl" then
+ return "musl"
+ elseif ldd_output:find "GLIBC" or ldd_output:find "glibc" or ldd_output:find "GNU" then
+ return "glibc"
+ end
+ end
end)
-- Most of the code that calls into these functions executes outside of the main event loop, where API/fn functions are