diff options
| author | ruki <[email protected]> | 2026-03-12 22:58:51 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-03-12 22:58:51 +0800 |
| commit | 9cde82e4b7778e52300352f58607d96bccbbd0ad (patch) | |
| tree | 027ec2f3681f06b18cd1dc2de89a601aa05da2d2 | |
| parent | 5d8708f4bff9c8ee444817ba09776ac120d0278a (diff) | |
| parent | c03f3c5fbb20377215ea4c1c7240b4fc3da7722f (diff) | |
Merge pull request #7391 from xmake-io/vcpkg
improve to find package with vcpkg features
| -rw-r--r-- | xmake/modules/package/manager/vcpkg/find_package.lua | 36 | ||||
| -rw-r--r-- | xmake/modules/package/manager/vcpkg/install_package.lua | 4 |
2 files changed, 39 insertions, 1 deletions
diff --git a/xmake/modules/package/manager/vcpkg/find_package.lua b/xmake/modules/package/manager/vcpkg/find_package.lua index 045adf050..563521889 100644 --- a/xmake/modules/package/manager/vcpkg/find_package.lua +++ b/xmake/modules/package/manager/vcpkg/find_package.lua @@ -131,11 +131,32 @@ function _get_package_info(name, triplet, infodirs, arch, plat, mode) return result end +-- check if the required features are installed via `vcpkg list` +-- @see https://github.com/xmake-io/xmake/issues/7388 +function _has_installed_features(vcpkg, name, triplet, required_features) + for _, feature in ipairs(required_features) do + local listinfo = try { function () + return os.iorunv(vcpkg, {"list", name .. "[" .. feature .. "]:" .. triplet}) + end} + if not listinfo or listinfo:trim() == "" then + return false + end + end + return true +end + function _find_package(vcpkg, vcpkgdir, name, opt) -- get configs local configs = opt.configs or {} + -- extract required features before stripping, e.g. curl[openssl,mbedtls] -> {"openssl", "mbedtls"} + local required_features + local features_str = name:match("%[(.-)%]") + if features_str then + required_features = features_str:split(",", {plain = true}) + end + -- fix name, e.g. ffmpeg[x264] as ffmpeg -- @see https://github.com/xmake-io/xmake/issues/925 name = name:gsub("%[.-%]", "") @@ -161,9 +182,22 @@ function _find_package(vcpkg, vcpkgdir, name, opt) return end + -- check that required features are installed + -- @see https://github.com/xmake-io/xmake/issues/7388 + if required_features and not _has_installed_features(vcpkg, name, triplet, required_features) then + return + end + -- find dependency package + -- pass features to depend-info to get the complete dependency tree + -- e.g. curl[mbedtls] needs mbedtls libraries + -- @see https://github.com/xmake-io/xmake/issues/7388 + local depend_name = name + if required_features then + depend_name = name .. "[" .. table.concat(required_features, ",") .. "]" + end local result = nil - local _, dependinfo = try { function () return os.iorunv(vcpkg, {"depend-info", name, "--sort=reverse", "--triplet=" .. triplet}) end } + local _, dependinfo = try { function () return os.iorunv(vcpkg, {"depend-info", depend_name, "--sort=reverse", "--triplet=" .. triplet}) end } if dependinfo then for _, line in ipairs(dependinfo:split("\n", {plain = true})) do if not line:startswith("vcpkg-") then diff --git a/xmake/modules/package/manager/vcpkg/install_package.lua b/xmake/modules/package/manager/vcpkg/install_package.lua index 021e30d9a..e7c0fa930 100644 --- a/xmake/modules/package/manager/vcpkg/install_package.lua +++ b/xmake/modules/package/manager/vcpkg/install_package.lua @@ -56,6 +56,10 @@ function _install_for_classic(vcpkg, name, opt) table.insert(argv, "--debug") end + -- allow rebuilding packages when features change + -- @see https://github.com/xmake-io/xmake/issues/7388 + table.insert(argv, "--recurse") + -- install package os.vrunv(vcpkg, argv) end |
