2024-09-05 05:16:18 +02:00
|
|
|
local plugin_dir = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":p:h") -- got this from https://lazy.folke.io/developers#building
|
2024-09-05 05:27:00 +02:00
|
|
|
|
2024-09-10 16:07:08 +02:00
|
|
|
local os_uname = vim.loop.os_uname()
|
|
|
|
|
|
|
|
local arch = os_uname.machine
|
|
|
|
|
|
|
|
local platform = string.lower(os_uname.sysname)
|
2024-09-10 16:25:19 +02:00
|
|
|
if platform == "mac" then
|
|
|
|
platform = "darwin"
|
2024-09-15 00:00:03 +02:00
|
|
|
elseif platform == "windows_nt" then
|
2024-09-16 23:40:25 +02:00
|
|
|
platform = "windows-msvc"
|
2024-09-10 16:25:19 +02:00
|
|
|
else
|
|
|
|
platform = platform .. "-gnu"
|
|
|
|
end
|
2024-09-10 16:07:08 +02:00
|
|
|
|
|
|
|
local ext = os_uname.sysname
|
2024-09-15 00:01:45 +02:00
|
|
|
if os_uname.sysname == "Windows_NT" then ext = "dll"
|
2024-09-10 16:21:12 +02:00
|
|
|
elseif os_uname.sysname == "Mac" then ext = "dylib"
|
|
|
|
else ext = "so"
|
2024-09-10 16:07:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- -- TODO compare checksum before redownloading
|
2024-09-05 05:38:45 +02:00
|
|
|
-- if vim.fn.filereadable(path .. 'native' .. ext) == 1 then
|
|
|
|
-- shasum = vim.fn.system("sha256sum " .. path .. 'native' .. ext)
|
|
|
|
-- end
|
2024-09-10 16:07:08 +02:00
|
|
|
|
2024-09-16 20:38:17 +02:00
|
|
|
local sep = '/'
|
|
|
|
if os_uname.sysname == "Windows_NT" then sep = '\\' end
|
|
|
|
|
|
|
|
local native_path = plugin_dir..sep.."lua"..sep.."codemp"..sep.."new-native."..ext
|
|
|
|
local replace_native_path = plugin_dir..sep.."lua"..sep.."codemp"..sep.."native."..ext
|
2024-09-10 16:23:32 +02:00
|
|
|
local download_url_native = string.format("https://codemp.dev/releases/lua/codemp-lua-%s-%s.%s", arch, platform, ext)
|
2024-09-16 20:38:17 +02:00
|
|
|
|
|
|
|
local command = {
|
|
|
|
Windows_NT = { "Invoke-WebRequest", download_url_native, "-OutFile", native_path },
|
|
|
|
Linux = {"curl", "-o", native_path, download_url_native },
|
|
|
|
Mac = {"curl", "-o", native_path, download_url_native },
|
|
|
|
}
|
|
|
|
|
2024-09-10 16:23:01 +02:00
|
|
|
print("downloading codemp native lua extension from '" .. download_url_native .. "' ...")
|
2024-09-16 20:38:17 +02:00
|
|
|
vim.system(command[os_uname.sysname]):wait() -- TODO can we run this asynchronously?
|
2024-09-10 16:19:05 +02:00
|
|
|
print("downloaded! exit nvim to reload library")
|
|
|
|
|
|
|
|
vim.api.nvim_create_autocmd(
|
|
|
|
{"ExitPre"},
|
|
|
|
{
|
|
|
|
callback = function (_ev)
|
2024-09-10 16:21:12 +02:00
|
|
|
vim.system({"mv", native_path, replace_native_path}, { detach = true })
|
2024-09-10 16:19:05 +02:00
|
|
|
end
|
|
|
|
}
|
|
|
|
)
|