Skip to content

Improve c++/objc rules#7088

Merged
waruqi merged 5 commits intodevfrom
rule
Dec 2, 2025
Merged

Improve c++/objc rules#7088
waruqi merged 5 commits intodevfrom
rule

Conversation

@waruqi
Copy link
Member

@waruqi waruqi commented Dec 2, 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.6 milestone Dec 2, 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 refactors the C++ and Objective-C build rules within Xmake to improve modularity and maintainability. By centralizing configuration logic into dedicated config modules, it streamlines the application of various build settings such as exception handling, Link-Time Optimization (LTO), sanitizer checks, and Objective-C specific features. This change enhances the robustness and extensibility of the build system, making it easier to manage and expand language-specific configurations.

Highlights

  • Consolidated C++/Objective-C Configuration: The build rules for C++ and Objective-C (c.build, c++.build, objc.build, objc++.build) now delegate their configuration logic to new, centralized config modules, replacing direct dependency declarations for optimization and sanitizers.
  • Modular Configuration Structure: New config directories and files have been introduced (e.g., xmake/rules/c++/config/basic.lua, xmake/rules/objc++/config/main.lua) to organize and encapsulate specific configuration aspects, improving modularity.
  • Enhanced C++ Basic Settings: Default C++ exception handling for Windows and specific handling for the TCC compiler on Windows static libraries (setting .a extension and lib prefix) are now managed within c++/config/basic.lua.
  • Improved Objective-C/C++ Basic Settings: Logic has been implemented in objc++/config/basic.lua to manage Objective-C Automatic Reference Counting (ARC) flags and automatically add Foundation and CoreFoundation frameworks for Apple platforms.
  • Refined Optimization and Sanitizer Flag Handling: The optimization.lua and sanitizer.lua modules now use more comprehensive flag mapping for different source kinds (C, C++, Objective-C, Objective-C++) to ensure correct compiler flags are applied for Link-Time Optimization (LTO) and sanitizer checks.
  • OpenMP Rule Lifecycle Change: The OpenMP rules (c.openmp, c++.openmp) have been updated to use the on_load callback instead of on_config, potentially altering when OpenMP-related configurations are applied during the build process.
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.

@waruqi waruqi force-pushed the rule branch 2 times, most recently from 366f442 to 597839a Compare December 2, 2025 03:09
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 refactors the C++ and Objective-C++ rules to centralize configuration logic, which is a great improvement for modularity and code reuse. I've found a couple of areas where the new code can be made more maintainable. Specifically, I've suggested refactoring some duplicated logic in the new Objective-C++ basic configuration and improving the readability of flag selection in the optimization configuration.

Comment on lines +33 to +39
local flagnames = {
cc = "cflags",
cxx = "cxxflags",
mm = "mflags",
mxx = "mxxflags"
}
local cflag = flagnames[sourcekind] or (sourcekind == "cxx" and "cxxflags" or "cflags")
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This block can be made more readable. While the or chain works, separating the lookup from the fallback logic improves clarity and maintainability, especially for developers who may not be deeply familiar with this part of the codebase.

    local flagnames = {
        cc = "cflags",
        cxx = "cxxflags",
        mm = "mflags",
        mxx = "mxxflags"
    }
    local cflag = flagnames[sourcekind]
    if not cflag then
        -- Fallback for other source kinds to maintain previous behavior.
        cflag = sourcekind == "cxx" and "cxxflags" or "cflags"
    end

Comment on lines +24 to +40
if sourcekind == "mm" then
-- deprecated, we only need to use `add_mflags("-fno-objc-arc")` to override it
if target:values("objc.build.arc") == false then
target:add("mflags", "-fno-objc-arc")
end
if target:is_plat("macosx", "iphoneos", "watchos") then
target:add("frameworks", "Foundation", "CoreFoundation")
end
elseif sourcekind == "mxx" then
-- deprecated, we only need to use `add_mxxflags("-fno-objc-arc")` to override it
if target:values("objc++.build.arc") == false then
target:add("mxxflags", "-fno-objc-arc")
end
if target:is_plat("macosx", "iphoneos", "watchos") then
target:add("frameworks", "Foundation", "CoreFoundation")
end
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 mm and mxx source kinds is very similar, leading to code duplication. You can refactor this to be more concise and maintainable by using a configuration table. This also makes it easier to add support for other similar source kinds in the future.

    local configs = {
        mm = {arc_value = "objc.build.arc", flags = "mflags"},
        mxx = {arc_value = "objc++.build.arc", flags = "mxxflags"}
    }
    local config = configs[sourcekind]
    if config then
        -- deprecated, we only need to use `add_mflags("-fno-objc-arc")` to override it
        if target:values(config.arc_value) == false then
            target:add(config.flags, "-fno-objc-arc")
        end
        if target:is_plat("macosx", "iphoneos", "watchos") then
            target:add("frameworks", "Foundation", "CoreFoundation")
        end
    end

@waruqi waruqi force-pushed the rule branch 2 times, most recently from 2eb8228 to a3f3678 Compare December 2, 2025 03:14
@waruqi waruqi merged commit bc7caf9 into dev Dec 2, 2025
71 checks passed
@waruqi waruqi deleted the rule branch December 2, 2025 08:16
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.

1 participant