Skip to content

fix(nuget): improve library file matching with score-based selection #7223

Merged
waruqi merged 1 commit intoxmake-io:devfrom
KochabStar:dev
Jan 14, 2026
Merged

fix(nuget): improve library file matching with score-based selection #7223
waruqi merged 1 commit intoxmake-io:devfrom
KochabStar:dev

Conversation

@KochabStar
Copy link
Contributor

  • add path component matching to avoid x86/x86_64 confusion
  • implement score-based lib file selection for better architecture matching
  • support multiple include directory patterns
  • deduplicate includedirs and linkdirs in result
  • Before adding new features and new modules, please go to issues to submit the relevant feature description first.
  • Write good commit messages and use the same coding conventions as the rest of the project.
  • Please commit code to dev branch and we will merge into master branch in feature
  • Ensure your edited codes with four spaces instead of TAB.

#7222

- add path component matching to avoid x86/x86_64 confusion
- implement score-based lib file selection for better architecture matching
- support multiple include directory patterns
- deduplicate includedirs and linkdirs in result
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @KochabStar, 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 refines how NuGet packages are processed by improving the selection of native library files and include directories. The core change introduces a sophisticated scoring system to accurately match library files based on various build parameters, resolving potential conflicts and ensuring optimal file selection. Additionally, it enhances the flexibility of include path detection and cleans up the final output by deduplicating paths.

Highlights

  • Improved Library File Matching: Implemented a new score-based selection mechanism for library files, which prioritizes architecture, toolset, library mode, and runtime to ensure the most appropriate library is chosen. This includes precise path component matching to avoid ambiguity between similar architecture names like 'x86' and 'x86_64'.
  • Flexible Include Directory Detection: The logic for detecting include directories has been enhanced to support multiple patterns, allowing for more varied directory structures (e.g., 'include/' or 'inc/') and identifying them based on header file extensions.
  • Deduplication of Paths: Added explicit deduplication for both includedirs and linkdirs in the final result, preventing redundant paths from being added to the build configuration.

🧠 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.

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 significantly improves the logic for finding native library and include files within NuGet packages. The introduction of _match_path_component and a score-based system in _match_libfile makes architecture matching more robust, correctly handling cases like 'x86' vs 'x86_64'. The changes to include directory detection are also more flexible.

The overall approach is solid. I have a couple of suggestions to further improve efficiency and robustness. One is to move a constant table out of a frequently called function to avoid its recreation. The other is to use the new path component matching function more consistently to prevent potential partial matches.

Great work on making the NuGet package handling more reliable!

Comment on lines +83 to +91
if toolset and file_lower:find(toolset:lower(), 1, true) then
score = score + 4
end
if file_lower:find(libmode:lower(), 1, true) then
score = score + 2
end
if file_lower:find(runtime:lower(), 1, true) then
score = score + 1
end
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Using string.find for toolset, libmode, and runtime can lead to incorrect partial matches (e.g., a libmode of "Release" matching a path component "PreRelease"). For more robust matching, you should use the _match_path_component function here as well, which ensures that only whole path components are matched.

    if toolset and _match_path_component(file_lower, toolset:lower()) then
        score = score + 4
    end
    if _match_path_component(file_lower, libmode:lower()) then
        score = score + 2
    end
    if _match_path_component(file_lower, runtime:lower()) then
        score = score + 1
    end

Comment on lines +53 to +57
local arch_patterns = {
x64 = {"x64", "amd64", "x86_64"},
Win32 = {"win32", "x86", "i386", "i686"},
arm64 = {"arm64", "aarch64"},
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For efficiency, it's better to define arch_patterns as a constant (upvalue) outside of the _match_libfile function, so it's not recreated on every call. Since this function is called inside a loop in _find_package, you can define arch_patterns once at the module level before _match_libfile to improve performance.

@waruqi waruqi merged commit 6889b86 into xmake-io:dev Jan 14, 2026
35 checks passed
@waruqi waruqi added this to the v3.0.7 milestone Jan 14, 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.

2 participants