Skip to content

Commit

Permalink
fix: don't let luarocks install binary rocks for the wrong architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Aug 2, 2024
1 parent fc51c1b commit 1504fb1
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 9 deletions.
29 changes: 24 additions & 5 deletions bootstrap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,35 @@ end

assert(set_up_luarocks(temp_luarocks_path), "failed to install luarocks! Please try again :)")

vim.notify("Installing rocks.nvim...")

local sc = vim.system({
local rocks_binaries_supported_arch_map = {
Darwin = {
arm64 = "macosx-aarch64",
aarch64 = "macosx-aarch64",
x86_64 = "macosx-x86_64",
},
Linux = {
x86_64 = "linux-x86_64",
},
Windows_NT = {
x86_64 = "win32-x86_64",
},
}
local uname = vim.uv.os_uname()
local supported_arch = rocks_binaries_supported_arch_map[uname.sysname][uname.machine]

local install_cmd = {
luarocks_binary,
"--lua-version=5.1",
"--tree=" .. install_path,
"--server='https://nvim-neorocks.github.io/rocks-binaries/'",
"install",
"rocks.nvim",
}):wait()
}
if supported_arch then
table.insert(install_cmd, 4, "--server='https://nvim-neorocks.github.io/rocks-binaries/'")
end
vim.notify("Installing rocks.nvim...")

local sc = vim.system(install_cmd):wait()

if sc.code ~= 0 then
notify_output("Installing rocks.nvim failed:", sc, vim.log.levels.ERROR)
Expand Down
27 changes: 23 additions & 4 deletions installer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -369,15 +369,34 @@ local function install()
return
end

vim.notify("Installing rocks.nvim...")
local sc = vim.system({
local rocks_binaries_supported_arch_map = {
Darwin = {
arm64 = "macosx-aarch64",
aarch64 = "macosx-aarch64",
x86_64 = "macosx-x86_64",
},
Linux = {
x86_64 = "linux-x86_64",
},
Windows_NT = {
x86_64 = "win32-x86_64",
},
}
local uname = vim.uv.os_uname()
local supported_arch = rocks_binaries_supported_arch_map[uname.sysname][uname.machine]

local install_cmd = {
luarocks_binary,
"--lua-version=5.1",
"--tree=" .. install_path,
"--server='https://nvim-neorocks.github.io/rocks-binaries/'",
"install",
"rocks.nvim",
}):wait()
}
if supported_arch then
table.insert(install_cmd, 4, "--server='https://nvim-neorocks.github.io/rocks-binaries/'")
end
vim.notify("Installing rocks.nvim...")
local sc = vim.system(install_cmd):wait()

if sc.code ~= 0 then
notify_output("Installing rocks.nvim failed:", sc, vim.log.levels.ERROR)
Expand Down
15 changes: 15 additions & 0 deletions lua/rocks/config/internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,20 @@ end

---@return string
local function mk_luarocks_config()
local sysname_map = {
Linux = "linux",
Darwin = "macosx",
Windows_NT = "win32",
}
local machine_map = {
arm64 = "aarch64",
aarch64 = "aarch64",
x86_64 = "x86_64",
}
local uname = vim.uv.os_uname()
local sysname = sysname_map[uname.sysname]
local machine = machine_map[uname.machine] or uname.machine
local arch = sysname and machine and ("%s-%s"):format(sysname, machine)
local default_luarocks_config = {
lua_version = "5.1",
rocks_trees = {
Expand All @@ -163,6 +177,7 @@ local function mk_luarocks_config()
root = config.rocks_path,
},
},
arch = arch,
}
local luarocks_config = vim.tbl_deep_extend("force", default_luarocks_config, opts.luarocks_config or {})

Expand Down

0 comments on commit 1504fb1

Please sign in to comment.