Conversation
Summary of ChangesHello @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
🧠 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 AssistThe 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
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 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
|
There was a problem hiding this comment.
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:
- There's a missing check to prevent PCH builds during
compile_commands.jsongeneration for C++ targets without modules. - 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.
| if not has_modules then | ||
| import("private.action.build.pcheader").build(target, jobgraph, "cxx", opt) | ||
| end |
There was a problem hiding this comment.
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
| 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}) | ||
|
|
There was a problem hiding this comment.
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:
- Removing the
add_orderscall, as ordering is now handled by build stages. - Adding conditional logic based on
target:data("cxx.has_modules")to build PCH inbefore_prepareif modules are present, andbefore_buildotherwise. - Including the
if not os.getenv("XMAKE_IN_COMPILE_COMMANDS_PROJECT_GENERATOR")check for consistency and correctness duringcompile_commands.jsongeneration.
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})
#4167