Skip to content

Commit

Permalink
Merge pull request #4523 from ImperatorS79/dev
Browse files Browse the repository at this point in the history
Fix package detection and install on msys2 for ucrt64 and clang64 platforms
  • Loading branch information
waruqi authored Dec 21, 2023
2 parents f66a1bd + cc6f823 commit 1597b1a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
33 changes: 14 additions & 19 deletions xmake/modules/package/manager/pacman/find_package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ function _find_package_from_list(list, name, pacman, opt)
-- mingw + pacman = cygpath available
local cygpath = nil
local pathtomsys = nil
local msystem = nil
if is_subhost("msys") and opt.plat == "mingw" then
cygpath = find_tool("cygpath")
if not cygpath then
return
end
pathtomsys = os.iorunv(cygpath.program, {"--windows", "/"})
pathtomsys = pathtomsys:trim()
msystem = os.getenv("MSYSTEM")
if msystem then
msystem = msystem:lower()
end
end

-- iterate over each file path inside the pacman package
Expand All @@ -48,13 +53,8 @@ function _find_package_from_list(list, name, pacman, opt)
local hpath = line
if is_subhost("msys") and opt.plat == "mingw" then
hpath = path.join(pathtomsys, line)
if opt.arch == "x86_64" then
local basehpath = path.join(pathtomsys, "mingw64/include")
table.insert(result.includedirs, basehpath)
else
local basehpath = path.join(pathtomsys, "mingw32/include")
table.insert(result.includedirs, basehpath)
end
local basehpath = path.join(pathtomsys, msystem .. "/include")
table.insert(result.includedirs, basehpath)
end
table.insert(result.includedirs, path.directory(hpath))
end
Expand Down Expand Up @@ -112,7 +112,6 @@ function main(name, opt)
end

-- for msys2/mingw? mingw-w64-[i686|x86_64]-xxx
local name_alt
if is_subhost("msys") and opt.plat == "mingw" then
-- try to get the package prefix from the environment first
-- https://www.msys2.org/docs/package-naming/
Expand All @@ -121,23 +120,18 @@ function main(name, opt)
local msystem = os.getenv("MSYSTEM")
if msystem and not msystem:startswith("MINGW") then
local i, j = msystem:find("%D+")
name_alt = prefix .. msystem:sub(i, j):lower() .. "-" .. arch .. name
name = prefix .. msystem:sub(i, j):lower() .. "-" .. arch .. name
else
name = prefix .. arch .. name
end
name = prefix .. arch .. name
end

-- get package files list
local list
for _, n in ipairs({name, name_alt}) do
list = n and try { function() return os.iorunv(pacman.program, {"-Q", "-l", n}) end }
if list then
break
end
end
list = name and try { function() return os.iorunv(pacman.program, {"-Q", "-l", name}) end }
if not list then
return
end

-- parse package files list
local linkdirs = {}
local pkgconfig_files = {}
Expand Down Expand Up @@ -185,5 +179,6 @@ function main(name, opt)
-- if there is no .pc, we parse the package content to obtain the data we want
result = _find_package_from_list(list, name, pacman, opt)
end

return result
end
14 changes: 12 additions & 2 deletions xmake/modules/package/manager/pacman/install_package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,18 @@ function main(name, opt)
end

-- for msys2/mingw? mingw-w64-[i686|x86_64]-xxx
if opt.plat == "mingw" then
name = (opt.arch == "x86_64" and "mingw-w64-x86_64-" or "mingw-w64-i686-") .. name
if is_subhost("msys") and opt.plat == "mingw" then
-- try to get the package prefix from the environment first
-- https://www.msys2.org/docs/package-naming/
local prefix = "mingw-w64-"
local arch = (opt.arch == "x86_64" and "x86_64-" or "i686-")
local msystem = os.getenv("MSYSTEM")
if msystem and not msystem:startswith("MINGW") then
local i, j = msystem:find("%D+")
name = prefix .. msystem:sub(i, j):lower() .. "-" .. arch .. name
else
name = prefix .. arch .. name
end
end

-- init argv
Expand Down

0 comments on commit 1597b1a

Please sign in to comment.