From c13ff298bdd424d7b7401fce4f0379cda0348af8 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 19 Feb 2024 11:55:39 -0300 Subject: fix(build): don't look for Lua headers when installing pure-Lua rocks This only applies to 'builtin' as we can't know about other modes, but this should be good enough. Fixes #1275. --- src/luarocks/build.lua | 34 +++++++++++++------------- src/luarocks/build/builtin.lua | 52 +++++++++++++--------------------------- src/luarocks/cmd.lua | 2 +- src/luarocks/deps.lua | 54 +++++++++++++++++++++++++++++++++++++++--- 4 files changed, 85 insertions(+), 57 deletions(-) (limited to 'src') diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index 471de427..55242e60 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua @@ -111,18 +111,6 @@ local function process_dependencies(rockspec, opts) end end - local ok, err, errcode = deps.check_lua_incdir(rockspec.variables) - if not ok then - return nil, err, errcode - end - - if cfg.link_lua_explicitly then - local ok, err, errcode = deps.check_lua_libdir(rockspec.variables) - if not ok then - return nil, err, errcode - end - end - if opts.deps_mode == "none" then return true end @@ -165,11 +153,8 @@ local function process_dependencies(rockspec, opts) end end end - ok, err, errcode = deps.fulfill_dependencies(rockspec, "dependencies", opts.deps_mode, opts.verify) - if err then - return nil, err, errcode - end - return true + + return deps.fulfill_dependencies(rockspec, "dependencies", opts.deps_mode, opts.verify) end local function fetch_and_change_to_source_dir(rockspec, opts) @@ -241,6 +226,21 @@ local function run_build_driver(rockspec, no_install) if not pok or type(driver) ~= "table" then return nil, "Failed initializing build back-end for build type '"..btype.."': "..driver end + + if not driver.skip_lua_inc_lib_check then + local ok, err, errcode = deps.check_lua_incdir(rockspec.variables) + if not ok then + return nil, err, errcode + end + + if cfg.link_lua_explicitly then + local ok, err, errcode = deps.check_lua_libdir(rockspec.variables) + if not ok then + return nil, err, errcode + end + end + end + local ok, err = driver.run(rockspec, no_install) if not ok then return nil, "Build error: " .. err diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua index 70210bab..c55b61a0 100644 --- a/src/luarocks/build/builtin.lua +++ b/src/luarocks/build/builtin.lua @@ -2,6 +2,11 @@ --- A builtin build system: back-end to provide a portable way of building C-based Lua modules. local builtin = {} +-- This build driver checks LUA_INCDIR and LUA_LIBDIR on demand, +-- so that pure-Lua rocks don't need to have development headers +-- installed. +builtin.skip_lua_inc_lib_check = true + local unpack = unpack or table.unpack local fs = require("luarocks.fs") @@ -9,38 +14,7 @@ local path = require("luarocks.path") local util = require("luarocks.util") local cfg = require("luarocks.core.cfg") local dir = require("luarocks.dir") - -function builtin.autodetect_external_dependencies(build) - if not build or not build.modules then - return nil - end - local extdeps = {} - local any = false - for _, data in pairs(build.modules) do - if type(data) == "table" and data.libraries then - local libraries = data.libraries - if type(libraries) == "string" then - libraries = { libraries } - end - local incdirs = {} - local libdirs = {} - for _, lib in ipairs(libraries) do - local upper = lib:upper():gsub("%+", "P"):gsub("[^%w]", "_") - any = true - extdeps[upper] = { library = lib } - table.insert(incdirs, "$(" .. upper .. "_INCDIR)") - table.insert(libdirs, "$(" .. upper .. "_LIBDIR)") - end - if not data.incdirs then - data.incdirs = incdirs - end - if not data.libdirs then - data.libdirs = libdirs - end - end - end - return any and extdeps or nil -end +local deps = require("luarocks.deps") local function autoextract_libs(external_dependencies, variables) if not external_dependencies then @@ -323,10 +297,16 @@ function builtin.run(rockspec, no_install) end if type(info) == "table" then if not checked_lua_h then - local lua_incdir, lua_h = variables.LUA_INCDIR, "lua.h" - if not fs.exists(dir.path(lua_incdir, lua_h)) then - return nil, "Lua header file "..lua_h.." not found (looked in "..lua_incdir.."). \n" .. - "You need to install the Lua development package for your system." + local ok, err, errcode = deps.check_lua_incdir(rockspec.variables) + if not ok then + return nil, err, errcode + end + + if cfg.link_lua_explicitly then + local ok, err, errcode = deps.check_lua_libdir(rockspec.variables) + if not ok then + return nil, err, errcode + end end checked_lua_h = true end diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index 3cbe3852..3067f4ce 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua @@ -561,7 +561,7 @@ function cmd.run_command(description, commands, external_namespace, ...) util.warning("command module " .. module .. " does not implement command(), skipping") end else - util.warning("failed to load command module " .. module) + util.warning("failed to load command module " .. module .. ": " .. mod) end end diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index 8af28327..2680b64b 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua @@ -10,7 +10,6 @@ local fun = require("luarocks.fun") local util = require("luarocks.util") local vers = require("luarocks.core.vers") local queries = require("luarocks.queries") -local builtin = require("luarocks.build.builtin") local deplocks = require("luarocks.deplocks") --- Generate a function that matches dep queries against the manifest, @@ -570,6 +569,40 @@ local function check_external_dependency(name, ext_files, vars, mode, cache) return nil, err_dirname, err_testfile, err_files end +function deps.autodetect_external_dependencies(build) + -- only applies to the 'builtin' build type + if not build or not build.modules then + return nil + end + + local extdeps = {} + local any = false + for _, data in pairs(build.modules) do + if type(data) == "table" and data.libraries then + local libraries = data.libraries + if type(libraries) == "string" then + libraries = { libraries } + end + local incdirs = {} + local libdirs = {} + for _, lib in ipairs(libraries) do + local upper = lib:upper():gsub("%+", "P"):gsub("[^%w]", "_") + any = true + extdeps[upper] = { library = lib } + table.insert(incdirs, "$(" .. upper .. "_INCDIR)") + table.insert(libdirs, "$(" .. upper .. "_LIBDIR)") + end + if not data.incdirs then + data.incdirs = incdirs + end + if not data.libdirs then + data.libdirs = libdirs + end + end + end + return any and extdeps or nil +end + --- Set up path-related variables for external dependencies. -- For each key in the external_dependencies table in the -- rockspec file, four variables are created: _DIR, _BINDIR, @@ -587,7 +620,7 @@ function deps.check_external_deps(rockspec, mode) assert(rockspec:type() == "rockspec") if not rockspec.external_dependencies then - rockspec.external_dependencies = builtin.autodetect_external_dependencies(rockspec.build) + rockspec.external_dependencies = deps.autodetect_external_dependencies(rockspec.build) end if not rockspec.external_dependencies then return true @@ -706,16 +739,25 @@ local function find_lua_incdir(prefix, luaver, luajitver) end function deps.check_lua_incdir(vars) + if vars.LUA_INCDIR_OK == true + then return true + end + local ljv = util.get_luajit_version() if vars.LUA_INCDIR then - return lua_h_exists(vars.LUA_INCDIR, cfg.lua_version) + local ok, err = lua_h_exists(vars.LUA_INCDIR, cfg.lua_version) + if ok then + vars.LUA_INCDIR_OK = true + end + return ok, err end if vars.LUA_DIR then local d, err = find_lua_incdir(vars.LUA_DIR, cfg.lua_version, ljv) if d then vars.LUA_INCDIR = d + vars.LUA_INCDIR_OK = true return true end return nil, err @@ -725,10 +767,15 @@ function deps.check_lua_incdir(vars) end function deps.check_lua_libdir(vars) + if vars.LUA_LIBDIR_OK == true + then return true + end + local fs = require("luarocks.fs") local ljv = util.get_luajit_version() if vars.LUA_LIBDIR and vars.LUALIB and fs.exists(dir.path(vars.LUA_LIBDIR, vars.LUALIB)) then + vars.LUA_LIBDIR_OK = true return true end @@ -768,6 +815,7 @@ function deps.check_lua_libdir(vars) if ok then vars.LUALIB = vars.LUA_LIBDIR_FILE + vars.LUA_LIBDIR_OK = true return true else err = err or "Failed finding Lua library. You may need to configure LUA_LIBDIR." -- cgit v1.2.3-55-g6feb