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.
This commit is contained in:
Spencer Gray 2025-07-23 09:49:01 -04:00
commit 284c7fe82b

View file

@ -4,6 +4,7 @@ local Community = require("lazy.community")
local Config = require("lazy.core.config") local Config = require("lazy.core.config")
local Health = require("lazy.health") local Health = require("lazy.health")
local Util = require("lazy.util") local Util = require("lazy.util")
local Process = require("lazy.manage.process")
---@class RockSpec ---@class RockSpec
---@field rockspec_format string ---@field rockspec_format string
@ -63,6 +64,21 @@ function M.hererocks.building()
return vim.tbl_get(Config.plugins.hererocks or {}, "_", "build") return vim.tbl_get(Config.plugins.hererocks or {}, "_", "build")
end end
---@param opts? LazyHealth
---@param luarocks_cmd string
---@return boolean
function M.check_lua51_headers(opts, luarocks_cmd)
local cmd = { luarocks_cmd, "--lua-version=5.1", "config", "variables.LUA_INCDIR" }
local _, exit_code = Process.exec(cmd)
if exit_code ~= 0 then
opts.error("Lua 5.1 headers not found. Install the Lua 5.1 development package for your system.")
return false
end
return true
end
---@param opts? LazyHealth ---@param opts? LazyHealth
function M.check(opts) function M.check(opts)
opts = vim.tbl_extend("force", { opts = vim.tbl_extend("force", {
@ -78,23 +94,23 @@ function M.check(opts)
else else
ok = Health.have(M.python, opts) ok = Health.have(M.python, opts)
ok = Health.have(M.hererocks.bin("luarocks")) and ok ok = Health.have(M.hererocks.bin("luarocks")) and ok
Health.have( if ok then
M.hererocks.bin("lua"), local luarocks_cmd = M.hererocks.bin("luarocks")
vim.tbl_extend("force", opts, { if Util.is_win then
version = "-v", luarocks_cmd = luarocks_cmd .. ".bat"
version_pattern = "5.1", end
}) ok = M.check_lua51_headers(opts, luarocks_cmd)
) end
end end
else else
ok = Health.have("luarocks", opts) ok = Health.have("luarocks", opts)
Health.have( if ok then
{ "lua5.1", "lua", "lua-5.1" }, local luarocks_cmd = "luarocks"
vim.tbl_extend("force", opts, { if Util.is_win then
version = "-v", luarocks_cmd = luarocks_cmd .. ".bat"
version_pattern = "5.1", end
}) ok = M.check_lua51_headers(opts, luarocks_cmd)
) end
end end
return ok return ok
end end