Skip to content

fix: ‌attempt to add dependency handling for vcpkg#7299

Merged
waruqi merged 10 commits intoxmake-io:devfrom
138436724:vcpkgdepend
Feb 10, 2026
Merged

fix: ‌attempt to add dependency handling for vcpkg#7299
waruqi merged 10 commits intoxmake-io:devfrom
138436724:vcpkgdepend

Conversation

@138436724
Copy link
Contributor

@138436724 138436724 commented Feb 6, 2026

Attempt to add dependency handling for vcpkg
#7297

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @138436724, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves Xmake's integration with Vcpkg by introducing robust dependency handling. Previously, Xmake might only process the primary requested package; now, it intelligently queries Vcpkg for all associated dependencies and incorporates their respective build information (like include paths and libraries) into the project configuration. This change streamlines the use of complex Vcpkg packages, ensuring that all necessary components are correctly linked and available during the build process.

Highlights

  • Dependency Discovery: The _find_package function now queries vcpkg depend-info to identify all direct and transitive dependencies of a requested package.
  • Iterative Package Information Extraction: The logic for extracting include directories, link directories, and library files has been refactored to iterate through each discovered dependency, ensuring all necessary components are collected.
  • Vcpkg Executable Management: The main function now explicitly locates the vcpkg executable and passes its path to _find_package, with error handling if the tool is not found.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • xmake/modules/package/manager/vcpkg/find_package.lua
    • The _find_package function signature was updated to accept the vcpkg executable path.
    • New logic was added to execute vcpkg depend-info and parse its output to identify package dependencies.
    • The process of finding package info files and extracting build-related paths (includes, libs, pkgconfig) was moved into a loop that iterates over all discovered dependencies.
    • The main function now includes a find_tool("vcpkg") call to locate the vcpkg executable and passes it to _find_package.
Activity
  • No specific activity (comments, reviews, etc.) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request attempts to add dependency handling for vcpkg, which is a valuable improvement. However, the current implementation introduces several critical logical flaws. There's a lack of error handling when calling os.iorunv, which could lead to a crash. Additionally, the logic for aggregating results from dependencies is incorrect, causing information from previously processed dependencies to be overwritten. I've left specific comments with suggestions on how to address these issues.

if #pkgconfig_files > 0 then
local pkgconfig_result = _find_package_from_pkgconfig(pkgconfig_files, {installdir = installdir, linkdirs = result and result.linkdirs})
if pkgconfig_result then
result = pkgconfig_result
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Inside the loop over dependencies, result = pkgconfig_result completely overwrites the result table. This means that for each dependency that has a .pc file, all previously collected dependency information (like includedirs, linkdirs from other dependencies) is discarded. You should merge pkgconfig_result into the existing result table instead of replacing it.

if not result.version then
result.version = infoname:match(prefix .. "_(%d+%.?%d*%.-)_" .. arch)
-- save version
if result then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The version of the package is being overwritten in each iteration of the dependency loop. This will result in result.version holding the version of the last processed dependency, which is likely not what's intended. The version should probably be set only for the main package being sought (name).

        if result and dependencyname == name then

@waruqi waruqi modified the milestone: v3.0.7 Feb 8, 2026
@waruqi
Copy link
Member

waruqi commented Feb 9, 2026

试了下,感觉不太对,这些依赖库的链接顺序都没处理,完全反的。。

现在是完全按照 depend-info 输出的遍历顺序提取的 key 作为的链接顺序

而正确的顺序应该是 add_links("openimageio", ... "lzma")

另外,不应该仅仅解析 key: value 中的 key ,而忽略 depend-info 最关键的 values 依赖部分数据。

你参考下这里的实现

https://github.com/xmake-io/xmake-repo/blob/6a5288368074c1d5f2d762d40e5dd3b9126c9a5c/packages/a/abseil/xmake.lua#L84-L107

要根据实际每个子库的依赖关系,openimageio -> fmt, libjpeg-turbo, libpng, opencolorio ...

去构建 DAG 图,然后生成最终的依赖顺序。

根据这个依赖顺序,去查找每个子库的 links ,来追加 links 。

vcpkg-cmake:
vcpkg-cmake-config:
bzip2[tool]: vcpkg-cmake
liblzma: vcpkg-cmake, vcpkg-cmake-config
zlib: vcpkg-cmake
zstd: vcpkg-cmake, vcpkg-cmake-config
expat: vcpkg-cmake, vcpkg-cmake-config
imath: vcpkg-cmake, vcpkg-cmake-config
libdeflate[gzip, compression, zlib, decompression]: vcpkg-cmake, vcpkg-cmake-config
libjpeg-turbo: vcpkg-cmake, vcpkg-cmake-config
minizip-ng[zstd, bzip2, lzma, pkcrypt, wzaes, zlib]: bzip2, liblzma, vcpkg-cmake, vcpkg-cmake-config, zlib, zstd
pystring: vcpkg-cmake, vcpkg-cmake-config
yaml-cpp: vcpkg-cmake, vcpkg-cmake-config
openjph: vcpkg-cmake, vcpkg-cmake-config
fmt: vcpkg-cmake, vcpkg-cmake-config
libpng: vcpkg-cmake, vcpkg-cmake-config, zlib
opencolorio: expat, imath, minizip-ng, pystring, vcpkg-cmake, vcpkg-cmake-config, yaml-cpp
openexr: imath, libdeflate, openjph, vcpkg-cmake, vcpkg-cmake-config
robin-map: vcpkg-cmake, vcpkg-cmake-config
tiff[jpeg, lzma, zip]: libjpeg-turbo, liblzma, vcpkg-cmake, vcpkg-cmake-config, zlib
openimageio: fmt, libjpeg-turbo, libpng, opencolorio, openexr, robin-map, tiff, vcpkg-cmake, vcpkg-cmake-config, zlib

  links = {
    "bz2",
    "lzma",
    "zlib",
    "zstd",
    "libexpat",
    "imath-3_2",
    "deflate",
    "jpeg",
    "turbojpeg",
    "minizip-ng",
    "pystring",
    "yaml-cpp",
    "openjph.0.26",
    "fmt",
    "libpng16",
    "opencolorio",
    "iex-3_4",
    "ilmthread-3_4",
    "openexr-3_4",
    "openexrcore-3_4",
    "openexrutil-3_4",
    "tiff",
    "openimageio",
    "openimageio_util"
  },

@waruqi
Copy link
Member

waruqi commented Feb 9, 2026

目前生成的链接顺序是不对的,尽管在 windows 上没问题,但是在 linux/macos ,肯定会出问题。

[ 47%]: linking.release test.exe
"C:\Program Files\Microsoft Visual Studio\18\Insiders\VC\Tools\MSVC\14.50.35503\bin\HostX64\x64\link.exe" -nologo -dynamicbase -nxcompat -machine:x64 -libpath:D:\projects\personal\vcpkg\installed\x64-windows\bin -libpath:D:\projects\personal\vcpkg\installed\x64-windows\lib -libpath:D:\projects\personal\vcpkg\installed\x64-windows-static-md\lib /opt:ref /opt:icf bz2.lib lzma.lib zlib.lib zstd.lib libexpat.lib imath-3_2.lib deflate.lib jpeg.lib turbojpeg.lib minizip-ng.lib pystring.lib yaml-cpp.lib openjph.0.26.lib fmt.lib libpng16.lib opencolorio.lib iex-3_4.lib ilmthread-3_4.lib openexr-3_4.lib openexrcore-3_4.lib openexrutil-3_4.lib tiff.lib openimageio.lib openimageio_util.lib boost_atomic-vc145-mt-x64-1_90.lib boost_filesystem-vc145-mt-x64-1_90.lib -out:build\windows\x64\release\test.exe build.objs\test\windows\x64\release\src\main.cpp.obj /implib:build\windows\x64\release\test.lib

@waruqi waruqi modified the milestones: v3.0.7, v3.0.8 Feb 9, 2026
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


I tried it, but it didn't feel right. The link order of these dependent libraries was not processed, it was completely the opposite. .

Now the key is extracted exactly according to the traversal order output by depend-info as the link order.

The correct order should be add_links("openimageio", ... "lzma")

In addition, you should not only parse the key in key: value but ignore the most critical values dependency part of depend-info.

Please refer to the implementation here

https://github.com/xmake-io/xmake-repo/blob/6a5288368074c1d5f2d762d40e5dd3b9126c9a5c/packages/a/abseil/xmake.lua#L84-L107

According to the actual dependencies of each sub-library, openimageio -> fmt, libjpeg-turbo, libpng, opencolorio...

To build a DAG graph and then generate the final dependency order.

According to this dependency order, search the links of each sub-library to append links.

vcpkg-cmake:
vcpkg-cmake-config:
bzip2[tool]: vcpkg-cmake
liblzma: vcpkg-cmake, vcpkg-cmake-config
zlib: vcpkg-cmake
zstd: vcpkg-cmake, vcpkg-cmake-config
expat: vcpkg-cmake, vcpkg-cmake-config
imath: vcpkg-cmake, vcpkg-cmake-config
libdeflate[gzip, compression, zlib, decompression]: vcpkg-cmake, vcpkg-cmake-config
libjpeg-turbo: vcpkg-cmake, vcpkg-cmake-config
minizip-ng[zstd, bzip2, lzma, pkcrypt, wzaes, zlib]: bzip2, liblzma, vcpkg-cmake, vcpkg-cmake-config, zlib, zstd
pystring: vcpkg-cmake, vcpkg-cmake-config
yaml-cpp: vcpkg-cmake, vcpkg-cmake-config
openjph: vcpkg-cmake, vcpkg-cmake-config
fmt: vcpkg-cmake, vcpkg-cmake-config
libpng: vcpkg-cmake, vcpkg-cmake-config, zlib
opencolorio: expat, imath, minizip-ng, pystring, vcpkg-cmake, vcpkg-cmake-config, yaml-cpp
openexr: imath, libdeflate, openjph, vcpkg-cmake, vcpkg-cmake-config
robin-map: vcpkg-cmake, vcpkg-cmake-config
tiff[jpeg, lzma, zip]: libjpeg-turbo, liblzma, vcpkg-cmake, vcpkg-cmake-config, zlib
openimageio: fmt, libjpeg-turbo, libpng, opencolorio, openexr, robin-map, tiff, vcpkg-cmake, vcpkg-cmake-config, zlib

  links = {
    "bz2",
    "lzma",
    "zlib",
    "zstd",
    "libexpat",
    "imath-3_2",
    "deflate",
    "jpeg",
    "turbojpeg",
    "minizip-ng",
    "pystring",
    "yaml-cpp",
    "openjph.0.26",
    "fmt",
    "libpng16",
    "opencolorio",
    "iex-3_4",
    "ilmthread-3_4",
    "openexr-3_4",
    "openexrcore-3_4",
    "openexrutil-3_4",
    "tiff",
    "openimageio",
    "openimageio_util"
  },

@138436724
Copy link
Contributor Author

vcpkg的depend-info本身是有顺序的,那个顺序从上到下应该就是依赖需要的顺序。如果需要反过来,是否可以将解析到的links循环插入到result.links头部来解决。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


The depend-info of vcpkg itself is in order, and the order from top to bottom should be the order required for dependencies. If the reverse is needed, can the parsed links loop be inserted into the result.links header to solve the problem?

@waruqi
Copy link
Member

waruqi commented Feb 9, 2026

vcpkg的depend-info本身是有顺序的,那个顺序从上到下应该就是依赖需要的顺序。如果需要反过来,是否可以将解析到的links循环插入到result.links头部来解决。

看着像是有序的,可以明确指定下顺序,topologicalreverse 反向拓扑。

你可以改成 --sort=reverse

  --sort=...             Chooses sort order for the `list` format, one of `lexicographical`,
                         `topological` (default), `reverse`

@138436724
Copy link
Contributor Author

已添加--sort=reverse,但是不确定os.iorunv这么写是否合理。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Added --sort=reverse, but not sure if it makes sense to write os.iorunv like this.

@waruqi
Copy link
Member

waruqi commented Feb 9, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces dependency handling for vcpkg by leveraging vcpkg depend-info, which is a significant improvement. The implementation is well-structured, including a refactoring of the package finding logic and the addition of a new test case to validate the changes. I have identified one potential high-severity issue regarding the use of table.unwrap that could lead to unexpected behavior, and a minor typo in a test file comment. Overall, this is a valuable contribution.

@138436724
Copy link
Contributor Author

我发现了一个问题,vcpkg还可以加入--triplet=参数

  --triplet=...          Target triplet. See 'vcpkg help triplet' (default: %VCPKG_DEFAULT_TRIPLET%)

如果是不同的类型的包写在一起或许还得加入一下这个参数来进行查询。

我认为try/catch是没必要的,因为如果没有这个包,上面infofile就会直接return,而有的包vcpkg一定能查询到。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


I found a problem, vcpkg can also add the --triplet= parameter

  --triplet=... Target triplet. See 'vcpkg help triplet' (default: %VCPKG_DEFAULT_TRIPLET%)

If different types of packages are written together, you may need to add this parameter for query.

I think try/catch is unnecessary, because if there is no such package, the above infofile will return directly, and some packages vcpkg can definitely be queried.

@waruqi
Copy link
Member

waruqi commented Feb 10, 2026

我认为try/catch是没必要的,因为如果没有这个包,上面infofile就会直接return,而有的包vcpkg一定能查询到。

凡事都要兜底,没有 100% 一定成功的情况,比如: vcpkg 后续升级更新导致 depend-info 参数改动给 break 了,比如 infofile 路径格式变动,导致后续判断失效,比如用户使用了很低的 vcpkg 版本,还没有 depend-info 支持。。各种情况都要考虑,不可能完全 100% 。

凡事皆有可能,像 conan 2.0 还魔改了呢,break 了一堆

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


I think try/catch is unnecessary, because if there is no such package, the above infofile will return directly, and some packages vcpkg can definitely be queried.

Everything must be done carefully, and there is no 100% guarantee of success. For example: subsequent upgrades and updates to vcpkg cause the depend-info parameter to change to break. For example, the infofile path format changes, causing subsequent judgments to become invalid. . All situations must be considered and it is impossible to be 100% sure.

Everything is possible. For example, conan 2.0 has been modified and broken a lot.

@138436724
Copy link
Contributor Author

1失败和6跳过,那个失败看起来像是系统环境的问题,跳过不知道是什么原因。我需要rebase到最新的提交然后强制推送一下吗

@waruqi
Copy link
Member

waruqi commented Feb 10, 2026

不用

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


1 fails and 6 skips. That failure seems to be a problem with the system environment. I don’t know why it is skipped. Do I need to rebase to the latest commit and then force push it?

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Need not

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@waruqi waruqi merged commit ee98b61 into xmake-io:dev Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants