Skip to content

improve to export def rules for binary#6915

Merged
waruqi merged 1 commit intodevfrom
export
Oct 10, 2025
Merged

improve to export def rules for binary#6915
waruqi merged 1 commit intodevfrom
export

Conversation

@waruqi
Copy link
Member

@waruqi waruqi commented Oct 10, 2025

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

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

@waruqi waruqi added this to the v3.0.4 milestone Oct 10, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @waruqi, 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 enhances Xmake's symbol export capabilities on Windows by extending the application of .def file rules and the symbol export list utility to include binary executables in addition to shared libraries. The changes refine how linker flags are applied for .def files, particularly for clangxx, and ensure that generated export files are correctly tracked as link dependencies, resulting in a more comprehensive and robust symbol export mechanism for various Windows target types.

Highlights

  • Expanded Scope for .def Rules: The platform.windows.def rule now applies to both shared libraries and binary executables on Windows, extending its utility beyond just shared components.
  • Enhanced Symbol Export for Binaries: The utils.symbols.export_list rule has been updated to support binary targets on Windows, enabling symbol export from executables, which was previously limited to shared targets.
  • Improved Linker Flag Handling: Explicit ldflags are now added alongside shflags for .def files, and specific handling for clangxx on Windows ensures correct -Wl,/def: flag usage, making the linking process more robust.
  • Dependency Tracking for Export Files: Generated export files are now explicitly added to linkdepfiles, ensuring proper build dependency tracking for these critical files.
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 extends the support for .def files to binaries on Windows, in addition to shared libraries. The changes are generally in the right direction, but there are a couple of places where the toolchain detection is too specific, which could cause issues with common MinGW setups using GCC. I've suggested expanding the compiler checks to be more robust. Additionally, I've noted some duplicated logic for flag generation that could be refactored to improve maintainability.

Comment on lines +35 to +38
elseif target:has_tool("ld", "clangxx") then
flag = "-Wl,/def:" .. flag
matched = true
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

The check target:has_tool("ld", "clangxx") is too specific and doesn't cover other GNU-like compilers such as gcc, g++, or clang which are common on MinGW. This could lead to .def files not being processed correctly for those toolchains. It should be expanded to include them to ensure correctness on different MinGW setups.

                    elseif target:has_tool("ld", "clang", "clangxx", "gcc", "gxx") then
                        flag = "-Wl,/def:" .. flag
                        matched = true
                    end

Comment on lines +79 to +83
elseif target:is_plat("windows") and target:has_tool("ld", "clangxx") then
exportkind = "def"
exportfile = path.join(target:autogendir(), "rules", "symbols", "export_list.def")
target:add("shflags", "-Wl,/def:" .. exportfile, {force = true})
target:add("ldflags", "-Wl,/def:" .. exportfile, {force = true})
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Similar to the other file, the condition target:has_tool("ld", "clangxx") is too specific. For MinGW, gcc and g++ are common linkers. Without including them, this rule will fall back to generating a version script (.map file), which is incorrect for Windows PE targets. The condition should be expanded to include other GNU-like compilers.

        elseif target:is_plat("windows") and target:has_tool("ld", "clang", "clangxx", "gcc", "gxx") then
            exportkind = "def"
            exportfile = path.join(target:autogendir(), "rules", "symbols", "export_list.def")
            target:add("shflags", "-Wl,/def:" .. exportfile, {force = true})
            target:add("ldflags", "-Wl,/def:" .. exportfile, {force = true})

Comment on lines +32 to +38
if target:has_tool("ld", "link") then
flag = "/def:" .. flag
matched = true
elseif target:has_tool("ld", "clangxx") then
flag = "-Wl,/def:" .. flag
matched = true
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 logic for generating the linker flag for .def files is duplicated in xmake/rules/utils/symbols/export_list/xmake.lua. To improve maintainability and avoid inconsistencies, consider creating a helper function that encapsulates this logic. This function could take the target and filepath as arguments and return the appropriate flag string based on the detected toolchain (MSVC vs. GNU-like). This would centralize the logic for handling .def files on Windows.

@waruqi waruqi mentioned this pull request Oct 10, 2025
@ChrisCatCP
Copy link
Contributor

implib感觉也可以加上

@Issues-translate-bot
Copy link

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


Implib feels like it can also be added

@waruqi waruqi merged commit 64112b9 into dev Oct 10, 2025
46 of 51 checks passed
@waruqi waruqi deleted the export branch October 10, 2025 15:21
@waruqi
Copy link
Member Author

waruqi commented Oct 10, 2025

implib感觉也可以加上

#6916

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