Skip to content

Improve pch concurrently to the other targets#7262

Merged
waruqi merged 4 commits intodevfrom
pch
Jan 25, 2026
Merged

Improve pch concurrently to the other targets#7262
waruqi merged 4 commits intodevfrom
pch

Conversation

@waruqi
Copy link
Member

@waruqi waruqi commented Jan 24, 2026

@waruqi waruqi added this to the v3.0.7 milestone Jan 24, 2026
@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 the efficiency of Precompiled Header (PCH) generation within Xmake by strategically adjusting the build phases for PCH compilation. The changes enable PCH files to be built in parallel with other independent compilation tasks, addressing potential bottlenecks in multi-target projects and leading to faster overall build times for C, C++, and Objective-C projects. The update also includes a new, robust test suite to ensure the reliability of these concurrency improvements.

Highlights

  • Enhanced PCH Concurrency: The Precompiled Header (PCH) build logic for C, C++, Objective-C, and Objective-C++ rules has been refactored to allow PCH generation to run concurrently with other target compilations, significantly improving overall build performance.
  • Conditional PCH Building Stages: For C++ targets, PCH is now built in the before_prepare stage only if C++ modules are present. Otherwise, it is deferred to the before_build stage to prevent blocking and enable greater parallelism. Similar adjustments move C, Objective-C, and Objective-C++ PCH builds to before_build.
  • PCH Rule Enablement Control: The on_config phase for PCH rules now explicitly checks the success of PCH configuration and disables the rule if it fails, providing more robust control over PCH processing.
  • New Test Case for Multi-Target PCH: A comprehensive new test project (precompiled_header_multiple_targets) has been added to validate the concurrent PCH building behavior across various target types and dependencies, ensuring the stability and correctness of the concurrency improvements.

🧠 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 improves build parallelism by moving precompiled header (PCH) generation to a later build stage, which is a great enhancement. The new test case is comprehensive and covers various PCH scenarios.

I've identified a couple of areas for improvement to ensure consistency and correctness across different configurations:

  1. There's a missing check to prevent PCH builds during compile_commands.json generation for C++ targets without modules.
  2. The PCH build logic for Objective-C++ is oversimplified and could fail in projects that use C++20 modules.

My review comments include specific suggestions to address these points. Overall, this is a valuable change that will improve build performance.

Comment on lines +62 to 64
if not has_modules then
import("private.action.build.pcheader").build(target, jobgraph, "cxx", opt)
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 if not os.getenv("XMAKE_IN_COMPILE_COMMANDS_PROJECT_GENERATOR") is missing here. It's present in the before_prepare block for targets with modules, and also for C targets. For consistency and to avoid running the build during compile_commands.json generation, it should be added here as well.

        if not has_modules and not os.getenv("XMAKE_IN_COMPILE_COMMANDS_PROJECT_GENERATOR") then
            import("private.action.build.pcheader").build(target, jobgraph, "cxx", opt)
        end

Comment on lines 35 to 51
rule("objc++.build.pcheader")
add_orders("objc++.build.pcheader", "c++.build.modules.builder")
on_config(function (target, opt)
import("private.action.build.pcheader").config(target, "mxx", opt)
import("private.action.build.pcheader")
if not pcheader.config(target, "mxx", opt) then
target:rule_enable("objc++.build.pcheader", false)
end
end)
before_prepare(function (target, jobgraph, opt)

-- Since Objective-C typically does not have C++ modules,
-- we can always enable parallel compilation across targets
-- without blocking the compilation of other cpp files,
-- we perform this as much as possible during the before_build stage.
before_build(function (target, jobgraph, opt)
import("private.action.build.pcheader").build(target, jobgraph, "mxx", opt)
end, {jobgraph = 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

The implementation for objc++.build.pcheader has been simplified to always build PCH in before_build. While the comment notes that Objective-C++ doesn't typically use C++ modules, xmake should probably handle the case where it does for completeness. This implementation could break builds for projects that use both Objective-C++ and C++20 modules.

I suggest aligning this rule with c++.build.pcheader by:

  1. Removing the add_orders call, as ordering is now handled by build stages.
  2. Adding conditional logic based on target:data("cxx.has_modules") to build PCH in before_prepare if modules are present, and before_build otherwise.
  3. Including the if not os.getenv("XMAKE_IN_COMPILE_COMMANDS_PROJECT_GENERATOR") check for consistency and correctness during compile_commands.json generation.
rule("objc++.build.pcheader")
    on_config(function (target, opt)
        import("private.action.build.pcheader")
        if not pcheader.config(target, "mxx", opt) then
            target:rule_enable("objc++.build.pcheader", false)
        end
    end)

    -- If the current target has a C++ modules file,
    -- we can only compile it earlier in the before_prepare stage,
    -- because the C++ modules will perform a complete dependency scan of
    -- the C++ files in on_prepare and then build the dependency graph.
    -- At this time, the pch header file must have already been generated.
    before_prepare(function (target, jobgraph, opt)
        if target:data("cxx.has_modules") and not os.getenv("XMAKE_IN_COMPILE_COMMANDS_PROJECT_GENERATOR") then
            import("private.action.build.pcheader").build(target, jobgraph, "mxx", opt)
        end
    end, {jobgraph = true})

    -- To enable parallel compilation across targets
    -- without blocking the compilation of other cpp files,
    -- we perform this as much as possible during the before_build stage.
    before_build(function (target, jobgraph, opt)
        if not target:data("cxx.has_modules") and not os.getenv("XMAKE_IN_COMPILE_COMMANDS_PROJECT_GENERATOR") then
            import("private.action.build.pcheader").build(target, jobgraph, "mxx", opt)
        end
    end, {jobgraph = true})

@waruqi waruqi merged commit c3989a3 into dev Jan 25, 2026
72 checks passed
@waruqi waruqi deleted the pch branch January 25, 2026 02:20
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