2024-09-17 20:04:28 +02:00
|
|
|
-- this is the codemp updater for nvim
|
|
|
|
--
|
|
|
|
-- it basically detects your operating system and architecture to
|
|
|
|
-- decide which native extension to download, then it downloads
|
|
|
|
-- from https://codemp.dev/release/lua/. If this doesn't work for
|
|
|
|
-- you or you don't trust periodic binary downloads, feel free to
|
|
|
|
-- remove this file (or its content). remember to place the
|
|
|
|
-- `native.(so|dll|dylib)` file in this plugin folder, next to
|
|
|
|
-- the `loader.lua` file.
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2024-10-08 17:34:34 +02:00
|
|
|
if arch == "arm64" then arch = "aarch64" end
|
|
|
|
|
2024-09-10 16:07:08 +02:00
|
|
|
local platform = string.lower(os_uname.sysname)
|
2024-10-08 17:34:34 +02:00
|
|
|
if platform == "darwin" then
|
2024-09-10 16:25:19 +02:00
|
|
|
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-10-08 17:31:29 +02:00
|
|
|
elseif os_uname.sysname == "Darwin" then ext = "dylib"
|
2024-09-10 16:21:12 +02:00
|
|
|
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
|
|
|
|
|
2024-10-09 21:29:16 +02:00
|
|
|
local new_ext = ext
|
|
|
|
if os_uname.sysname == "Darwin" then new_ext = "so" end
|
|
|
|
|
2024-10-01 21:08:28 +02:00
|
|
|
local version = "v0.7.3"
|
2024-09-21 12:53:44 +02:00
|
|
|
|
2024-10-09 21:29:16 +02:00
|
|
|
local native_path = plugin_dir..sep.."lua"..sep.."codemp"..sep.."new-native."..new_ext
|
|
|
|
local replace_native_path = plugin_dir..sep.."lua"..sep.."codemp"..sep.."native."..new_ext
|
2024-09-21 12:53:44 +02:00
|
|
|
local download_url_native = string.format("https://codemp.dev/releases/lua/codemp-lua-%s-%s-%s.%s", version, arch, platform, ext)
|
2024-09-16 20:38:17 +02:00
|
|
|
|
2024-09-10 16:23:01 +02:00
|
|
|
print("downloading codemp native lua extension from '" .. download_url_native .. "' ...")
|
2024-09-17 03:46:11 +02:00
|
|
|
if os_uname.sysname == "Windows_NT" then
|
|
|
|
local handle, pid = vim.uv.spawn("powershell.exe", {
|
|
|
|
args = { "-Command", "Invoke-WebRequest "..download_url_native.." -OutFile "..native_path }
|
|
|
|
})
|
|
|
|
|
|
|
|
print("downloading in background... library will be installed upon restart")
|
2024-09-28 01:19:05 +02:00
|
|
|
|
|
|
|
vim.api.nvim_create_autocmd(
|
|
|
|
{"ExitPre"},
|
|
|
|
{
|
|
|
|
callback = function (_ev)
|
|
|
|
local handle, pid = vim.uv.spawn("cmd.exe", {
|
2024-09-28 01:21:28 +02:00
|
|
|
args = { "/k", "move", "/Y", native_path, replace_native_path }
|
2024-09-28 01:19:05 +02:00
|
|
|
})
|
|
|
|
end
|
|
|
|
}
|
|
|
|
)
|
2024-09-17 03:46:11 +02:00
|
|
|
else
|
|
|
|
local res = vim.system({"curl", "-o", native_path, download_url_native }):wait() -- TODO can we run this asynchronously?
|
|
|
|
print(res.stdout)
|
|
|
|
print(res.stderr)
|
|
|
|
print(">> " .. res.code)
|
|
|
|
if res.code == 0 then
|
|
|
|
print("downloaded! exit nvim to reload library")
|
|
|
|
else
|
|
|
|
print("error downloading native library: " .. res.code)
|
|
|
|
print(res.stdout)
|
|
|
|
print(res.stderr)
|
|
|
|
end
|
2024-09-28 01:19:05 +02:00
|
|
|
vim.api.nvim_create_autocmd(
|
|
|
|
{"ExitPre"},
|
|
|
|
{
|
|
|
|
callback = function (_ev)
|
|
|
|
vim.system({"mv", native_path, replace_native_path}, { detach = true })
|
|
|
|
end
|
|
|
|
}
|
|
|
|
)
|
2024-09-17 03:46:11 +02:00
|
|
|
end
|
2024-09-10 16:19:05 +02:00
|
|
|
|