From b83c31c46e41f101778369fe00122a169099e638 Mon Sep 17 00:00:00 2001 From: William Boman Date: Mon, 10 Oct 2022 19:34:28 +0200 Subject: feat(platform): better glibc detection (#537) --- lua/mason-core/platform.lua | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'lua/mason-core/platform.lua') 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 -- cgit v1.2.3-70-g09d2