Skip to content

Commit c680749

Browse files
author
Spencer Gray
committed
fix(rockspec): Check for Lua 5.1 header files.
Previously, rockspec.lua checked if Lua 5.1 was installed to determine if LuaRocks could build packages for Lua 5.1. This was not sufficient since the Lua version does not matter as long as the development headers for Lua 5.1 are available. So Lua 5.1 could be installed and the LuaRocks packages could still fail to install. Note: this also checks if a suitable version of Lua is installed since the command will fail if Lua is not installed at all.
1 parent 6c3bda4 commit c680749

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

lua/lazy/pkg/rockspec.lua

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local Community = require("lazy.community")
44
local Config = require("lazy.core.config")
55
local Health = require("lazy.health")
66
local Util = require("lazy.util")
7+
local Process = require("lazy.manage.process")
78

89
---@class RockSpec
910
---@field rockspec_format string
@@ -63,6 +64,21 @@ function M.hererocks.building()
6364
return vim.tbl_get(Config.plugins.hererocks or {}, "_", "build")
6465
end
6566

67+
---@param opts? LazyHealth
68+
---@param luarocks_cmd string
69+
---@return boolean
70+
function M.check_lua51_headers(opts, luarocks_cmd)
71+
local cmd = { luarocks_cmd, "--lua-version=5.1", "config", "variables.LUA_INCDIR" }
72+
local _, exit_code = Process.exec(cmd)
73+
74+
if exit_code ~= 0 then
75+
opts.error("Lua 5.1 headers not found. Install the Lua 5.1 development package for your system.")
76+
return false
77+
end
78+
79+
return true
80+
end
81+
6682
---@param opts? LazyHealth
6783
function M.check(opts)
6884
opts = vim.tbl_extend("force", {
@@ -78,23 +94,23 @@ function M.check(opts)
7894
else
7995
ok = Health.have(M.python, opts)
8096
ok = Health.have(M.hererocks.bin("luarocks")) and ok
81-
Health.have(
82-
M.hererocks.bin("lua"),
83-
vim.tbl_extend("force", opts, {
84-
version = "-v",
85-
version_pattern = "5.1",
86-
})
87-
)
97+
if ok then
98+
local luarocks_cmd = M.hererocks.bin("luarocks")
99+
if Util.is_win then
100+
luarocks_cmd = luarocks_cmd .. ".bat"
101+
end
102+
ok = M.check_lua51_headers(opts, luarocks_cmd)
103+
end
88104
end
89105
else
90106
ok = Health.have("luarocks", opts)
91-
Health.have(
92-
{ "lua5.1", "lua", "lua-5.1" },
93-
vim.tbl_extend("force", opts, {
94-
version = "-v",
95-
version_pattern = "5.1",
96-
})
97-
)
107+
if ok then
108+
local luarocks_cmd = "luarocks"
109+
if Util.is_win then
110+
luarocks_cmd = luarocks_cmd .. ".bat"
111+
end
112+
ok = M.check_lua51_headers(opts, luarocks_cmd)
113+
end
98114
end
99115
return ok
100116
end

0 commit comments

Comments
 (0)