summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-03-12 23:29:07 +0800
committerruki <[email protected]>2026-03-12 23:29:07 +0800
commit9ccfd524267021fbe5bbc8730e2c8891c62f1702 (patch)
tree8d81be6fa66712965ba85d3b7c421153f703db99
parenta3fa1adf39a11074b516d3ffa27d77a182aa070b (diff)
improve to find package with features in vcpkg
-rw-r--r--xmake/modules/package/manager/vcpkg/find_package.lua47
1 files changed, 43 insertions, 4 deletions
diff --git a/xmake/modules/package/manager/vcpkg/find_package.lua b/xmake/modules/package/manager/vcpkg/find_package.lua
index 531137b29..33ad3b755 100644
--- a/xmake/modules/package/manager/vcpkg/find_package.lua
+++ b/xmake/modules/package/manager/vcpkg/find_package.lua
@@ -131,6 +131,40 @@ function _get_package_info(name, triplet, infodirs, arch, plat, mode)
return result
end
+-- get installed features from vcpkg status file
+-- @see https://github.com/xmake-io/xmake/issues/7388
+function _get_installed_features(name, triplet, statusdirs)
+ local features = {}
+ for _, statusdir in ipairs(statusdirs) do
+ local statusfile = path.join(statusdir, "status")
+ if os.isfile(statusfile) then
+ local statusdata = io.readfile(statusfile)
+ if statusdata then
+ -- parse dpkg-like status entries, separated by blank lines
+ -- e.g.
+ -- Package: curl
+ -- Feature: openssl
+ -- Architecture: x64-windows-static-md
+ -- Status: install ok installed
+ --
+ statusdata = "\n" .. statusdata .. "\n\n"
+ for entry in statusdata:gmatch("\n\n(.-)\n\n") do
+ local pkg = entry:match("Package:%s*(%S+)")
+ local arch = entry:match("Architecture:%s*(%S+)")
+ local feature = entry:match("Feature:%s*(%S+)")
+ local status = entry:match("Status:%s*(.-)\n?$")
+ if pkg == name and arch == triplet and status and status:find("installed", 1, true) then
+ if feature then
+ table.insert(features, feature)
+ end
+ end
+ end
+ end
+ end
+ end
+ return features
+end
+
function _find_package(vcpkg, vcpkgdir, name, opt)
-- get configs
@@ -168,12 +202,17 @@ function _find_package(vcpkg, vcpkgdir, name, opt)
return
end
- -- check that required features are installed
- -- e.g. curl[mbedtls] should have curl_*_triplet_mbedtls.list in info directory
+ -- check that required features are installed via vcpkg status file
+ -- @see https://github.com/xmake-io/xmake/issues/7388
if required_features then
+ local statusdirs = {}
+ if opt.installdir then
+ table.insert(statusdirs, path.join(opt.installdir, "vcpkg_installed", "vcpkg"))
+ end
+ table.insert(statusdirs, path.join(vcpkgdir, "installed", "vcpkg"))
+ local installed_features = _get_installed_features(name, triplet, statusdirs)
for _, feature in ipairs(required_features) do
- local feature_infofile = find_file(format("%s_*_%s_%s.list", name, triplet, feature), infodirs)
- if not feature_infofile then
+ if not table.contains(installed_features, feature) then
return
end
end