Skip to content

Conversation

@SnowinterCat
Copy link

fix #7073


  • 增加新特性和新模块之前,请先到issues提交相关特性说明,经过讨论评估确认后,再进行相应的代码提交,避免做无用工作。
  • 编写友好可读的提交信息,并使用与工程代码相同的代码规范,代码请用4个空格字符代替tab缩进。
  • 请提交代码到dev分支,如果通过,我们会在特定时间合并到master分支上。
  • 为了规范化提交日志的格式,commit消息,不要用中文,请用英文描述。

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @SnowinterCat, 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 resolves an issue where Xmake failed to locate libc++ std modules, specifically when the clang compiler path was a symbolic link. It introduces a new function to robustly resolve symbolic links, which is then used to correctly determine the std module directory, thereby enhancing the reliability of C++ module support within Xmake.

Highlights

  • Symbolic Link Resolution: Introduced a new utility function, parse_link_files, to accurately resolve symbolic links to their canonical target paths.
  • Improved std Module Discovery: Modified the get_stdmodules function to leverage the new parse_link_files utility, ensuring correct identification of the std module directory even when the clang executable path is a symbolic link.
  • Fix for libc++ Module Loading: Addresses an issue where libc++ std modules could not be found, particularly in environments where the clang compiler is accessed via a symbolic link, by correctly resolving the compiler's true location.
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 aims to fix an issue with locating libc++ standard modules by introducing a helper function parse_link_files to resolve symbolic links. However, the implementation of parse_link_files is incomplete as it doesn't handle chained symbolic links, a common scenario on Linux systems. Additionally, the logic for resolving module paths has been changed to be relative to the clang executable's directory, which contradicts LLVM's documentation and is likely incorrect. I have provided suggestions to address both of these issues to ensure robust and correct behavior.

@waruqi waruqi requested a review from Arthapz November 28, 2025 06:49
@SnowinterCat
Copy link
Author

/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 improves the logic for locating libc++ standard modules by adding more robust path resolution, including handling for symbolic links and various relative path scenarios. The changes are logical and address the described problem. I've provided a few suggestions to prevent potential runtime errors from nil values and to improve code style by scoping helper functions locally.

wprint("libc++.modules.json is invalid! path: %s", path.normalize(modules_json_path))
return
end
local std_module_directory = path.directory(modules_json.modules[1]["source-path"])
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 code does not check if modules_json.modules[1]["source-path"] exists before using it. If it's nil, path.directory(nil) will be called, which becomes path.directory("nil") and returns . This would lead to incorrect path resolution. It's safer to check for the existence of "source-path" and print a warning if it's missing.

            local source_path = modules_json.modules[1]["source-path"]
            if not source_path then
                wprint("source-path not found in libc++.modules.json: %s", path.normalize(modules_json_path))
                return
            end
            local std_module_directory = path.directory(source_path)

Comment on lines +297 to +300
try_std_module_directory = path.join(path.directory(get_original_file(get_clang_path(target))), std_module_directory)
if os.isdir(try_std_module_directory) then
return {path.normalize(path.join(try_std_module_directory, "std.cppm")), path.normalize(path.join(try_std_module_directory, "std.compat.cppm"))}
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

get_clang_path(target) can return nil, which would cause get_original_file(nil) to be called. This will likely lead to a runtime error. You should check if get_clang_path returns a valid path before using it.

            local clang_path = get_clang_path(target)
            if clang_path then
                try_std_module_directory = path.join(path.directory(get_original_file(clang_path)), std_module_directory)
                if os.isdir(try_std_module_directory) then
                    return {path.normalize(path.join(try_std_module_directory, "std.cppm")), path.normalize(path.join(try_std_module_directory, "std.compat.cppm"))}
                end
            end

Comment on lines +246 to +262
function parse_link_files(filepath)
if not os.islink(filepath) then
return filepath
end
local target = os.readlink(filepath)
if path.is_absolute(target) then
return target
end
return path.join(path.directory(filepath), target)
end

function get_original_file(filepath)
while os.islink(filepath) do
filepath = parse_link_files(filepath)
end
return filepath
end
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The new functions parse_link_files and get_original_file are only used within this file. It's good practice to declare them as local to limit their scope and avoid polluting the module's global namespace.

local function parse_link_files(filepath)
    if not os.islink(filepath) then
        return filepath
    end
    local target = os.readlink(filepath)
    if path.is_absolute(target) then
        return target
    end
    return path.join(path.directory(filepath), target)
end

local function get_original_file(filepath)
    while os.islink(filepath) do
        filepath = parse_link_files(filepath)
    end
    return filepath
end

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.

The module support file for libc++ cannot be found.

1 participant