Skip to content

Fix C++ modules BMI installation and re-enable external build tests#7206

Open
arpittkhandelwal wants to merge 1 commit intoTheHPXProject:masterfrom
arpittkhandelwal:fix/cxx-modules-external-build
Open

Fix C++ modules BMI installation and re-enable external build tests#7206
arpittkhandelwal wants to merge 1 commit intoTheHPXProject:masterfrom
arpittkhandelwal:fix/cxx-modules-external-build

Conversation

@arpittkhandelwal
Copy link
Copy Markdown
Contributor

Summary
This PR standardizes the export of C++ module BMI files to external projects and officially re-enables the external build tests when HPX_WITH_CXX_MODULES=ON.

Fixes #7197
Closes #7202

Problem
Previously, external build tests were disabled (#7190) because HPX lacked the CMake infrastructure to correctly export and install the Binary Module Interface (BMI) generation paths downstream. Without these paths, any external project trying to import HPX modules structurally failed.

Root Cause
CMake 3.28 natively supports C++20 module dependency tracking via the FILE_SET CXX_MODULES feature, generating proper module interfaces. However, the custom macros hpx_configure_module_producer and hpx_configure_module_consumer were overriding this by manually injecting -fmodule-output= and -fprebuilt-module-path= compiler flags. This hardcoded manipulation fundamentally conflicts with modern CMake's internal module tracking and installation processes, corrupting the exported target configuration (HPXTargets.cmake).

What changed
Since HPX_WITH_CXX_MODULES now enforces CMAKE_VERSION >= 3.29, we can entirely rely on native functionality:

  • Stripped the manual -fmodule-output= flags from HPX_CXXModules.cmake.
  • Stripped the manual -fprebuilt-module-path= flags from HPX_CXXModules.cmake (safely retained fuse-ld=lld specifically for Clang).
  • Removed the return() check block from tests/unit/build/CMakeLists.txt that bypassed downstream tests.

Why this fixes the issue
The native CMake target definitions now assume full control over BMI file sets, successfully resolving paths dynamically. When an external project consumes HPX via find_package(HPX) through the CI pipeline, CMake inherently handles the BMI dependencies.

Copilot AI review requested due to automatic review settings April 20, 2026 01:52
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented Apr 20, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates HPX’s CMake module support to rely on CMake’s native C++20 modules/BMI handling (requiring CMake ≥ 3.29) and re-enables the external dependent-project build tests when HPX_WITH_CXX_MODULES=ON.

Changes:

  • Removed manual compiler flag injection for module BMI output (-fmodule-output=...) and prebuilt module search paths (-fprebuilt-module-path=...) in HPX_CXXModules.cmake.
  • Re-enabled tests/unit/build external build tests for module-enabled builds by removing the early return() guard.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tests/unit/build/CMakeLists.txt Re-enables external build tests when modules are enabled.
cmake/HPX_CXXModules.cmake Drops manual module BMI flag management to let modern CMake manage BMI generation/consumption.

Comment thread cmake/HPX_CXXModules.cmake Outdated
Comment thread cmake/HPX_CXXModules.cmake Outdated
@arpittkhandelwal arpittkhandelwal force-pushed the fix/cxx-modules-external-build branch from 549eca4 to 70290e8 Compare April 20, 2026 02:09
Comment thread cmake/HPX_CXXModules.cmake
Comment thread cmake/HPX_CXXModules.cmake Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates HPX’s CMake C++20 modules support to rely on CMake’s native module/BMI handling (CMake ≥ 3.29) and re-enables downstream external-build CI coverage when HPX_WITH_CXX_MODULES=ON.

Changes:

  • Re-enabled external build tests by removing the HPX_WITH_CXX_MODULES early-return in tests/unit/build/CMakeLists.txt.
  • Simplified module producer configuration to stop overriding CMake’s BMI/output handling, leaning on native FILE_SET ... TYPE CXX_MODULES / CXX_MODULES_BMI.
  • Updated cmake-format command metadata to match the updated hpx_configure_module_producer signature.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
tests/unit/build/CMakeLists.txt Removes the guard that skipped external build tests when modules are enabled.
libs/CMakeLists.txt Updates module producer invocation to match the simplified macro API.
cmake/HPX_CXXModules.cmake Removes manual module output/prebuilt-path flags and relies on CMake-native scanning/export behavior.
.cmake-format.py Adjusts formatting metadata for the updated CMake function signature.

@arpittkhandelwal arpittkhandelwal force-pushed the fix/cxx-modules-external-build branch from c27ae7d to 3738eb9 Compare April 20, 2026 04:30
Copilot AI review requested due to automatic review settings April 20, 2026 15:19
@arpittkhandelwal arpittkhandelwal force-pushed the fix/cxx-modules-external-build branch from 3738eb9 to 7a3c5a2 Compare April 20, 2026 15:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates HPX’s CMake support for C++20 modules to rely on CMake’s native FILE_SET CXX_MODULES/BMI handling (now that HPX_WITH_CXX_MODULES requires newer CMake), and re-enables external build tests that were previously disabled for modules-enabled builds.

Changes:

  • Remove manual compiler flag injection for module BMI output/consumption from HPX_CXXModules.cmake and simplify the producer macro API.
  • Re-enable tests/unit/build external build tests when C++ modules are enabled, with a pkg-config build tweak to force header fallback where needed.
  • Make module-consumer setup more robust across build-tree vs installed-target naming by checking for HPXInternal:: targets.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/unit/build/CMakeLists.txt Re-enables external build tests with modules enabled; adjusts pkg-config build flags to disable module imports for that test path.
libs/CMakeLists.txt Updates module producer setup to match the simplified hpx_configure_module_producer API.
cmake/HPX_SetupTarget.cmake Adds support for consuming either build-tree or HPXInternal::-namespaced module interface targets when configuring module scanning.
cmake/HPX_CXXModules.cmake Removes manual -fmodule-output/-fprebuilt-module-path flag management, relying on native CMake module handling.
.cmake-format.py Updates cmake-format parser config for the updated hpx_configure_module_producer signature.
Comments suppressed due to low confidence (1)

cmake/HPX_CXXModules.cmake:91

  • The doc comment for hpx_configure_module_consumer says it "sets necessary consumer compiler flags for clang and gcc", but the function now only propagates CXX_SCAN_FOR_MODULES and adds Clang linker flags (-fuse-ld=lld, --error-limit=0). Please update the comment to reflect the current behavior (or reintroduce the described compiler-flag propagation if still required).
# hpx_configure_module_consumer(<consumer> <producer>])
#
# * propagates module-related properties from producer interface target
# * sets necessary consumer compiler flags for clang and gcc
function(hpx_configure_module_consumer consumer producer)

Comment thread cmake/HPX_SetupTarget.cmake
Comment thread cmake/HPX_SetupTarget.cmake
@hkaiser
Copy link
Copy Markdown
Contributor

hkaiser commented Apr 23, 2026

@arpittkhandelwal The changes to the build system seem not to have broken anything - good. However, they have notfixed anything either :/ Also, I think the copilot comments bear some truths with them.

@arpittkhandelwal arpittkhandelwal force-pushed the fix/cxx-modules-external-build branch from 7a3c5a2 to 7b8741f Compare April 26, 2026 14:11
Copilot AI review requested due to automatic review settings April 26, 2026 14:39
@arpittkhandelwal arpittkhandelwal force-pushed the fix/cxx-modules-external-build branch from 7b8741f to 7e8f2a6 Compare April 26, 2026 14:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates HPX’s CMake infrastructure for C++20 modules to rely on CMake’s native BMI/module handling, and re-enables external build tests when HPX_WITH_CXX_MODULES=ON so downstream find_package(HPX) consumers are exercised again.

Changes:

  • Remove manual compiler flag injection for module BMI output/consumption and rely on CMake’s native module scanning/FILE_SET behavior.
  • Re-enable external build tests for module-enabled builds and adjust pkg-config external test flags.
  • Improve module-consumer setup logic to handle both in-tree and exported HPXInternal:: module interface targets.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/unit/build/CMakeLists.txt Re-enables external build tests with modules and adjusts pkg-config CXX flags.
libs/CMakeLists.txt Updates module producer configuration call to match the simplified producer macro.
examples/hello_world_component/CMakeLists.txt Adds module-aware linking/scanning for the external hello-world example.
cmake/HPX_SetupTarget.cmake Makes module consumer configuration robust to HPXInternal:: exported target names.
cmake/HPX_CXXModules.cmake Removes manual BMI path flags and simplifies producer/consumer module configuration.
.cmake-format.py Updates formatting metadata for the changed CMake macro signature.

Comment thread examples/hello_world_component/CMakeLists.txt Outdated
Comment thread cmake/HPX_CXXModules.cmake Outdated
@hkaiser
Copy link
Copy Markdown
Contributor

hkaiser commented Apr 27, 2026

@arpittkhandelwal I like your solution to the issue a lot. Thanks. However, while some of the external target now build, some others do not build yet. Please have a look at #7202, which applies other changes that may be helpful in resolving the issue.

Could you please tend to the cmake-format issue reported? Also, please either accept the copilot changes or mark them as being irrelevant.

@arpittkhandelwal arpittkhandelwal force-pushed the fix/cxx-modules-external-build branch from 7e8f2a6 to cf503da Compare April 27, 2026 17:10
Copilot AI review requested due to automatic review settings April 27, 2026 17:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates HPX’s external-build test infrastructure and example consumer project to work again when HPX_WITH_CXX_MODULES=ON, aiming to standardize downstream module/BMI consumption and re-enable CI coverage for external builds.

Changes:

  • Re-enabled tests/unit/build external build tests with C++ modules enabled, adding module-target build ordering where needed.
  • Updated the hello_world_component external example to enable module scanning and link to module interface targets when modules are enabled.
  • Adjusted cmake-format parsing config for hpx_configure_module_producer.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

File Description
tests/unit/build/CMakeLists.txt Removes the modules early-exit and adds module-related dependencies/flags for external build and pkg-config tests.
examples/hello_world_component/CMakeLists.txt Enables module scanning and links module interface targets in the external example when modules are enabled.
cmake/HPX_SetupTarget.cmake Makes module-consumer configuration robust to both in-tree and HPXInternal:: imported target names.
.cmake-format.py Updates cmake-format’s custom command parsing for hpx_configure_module_producer.

Comment thread tests/unit/build/CMakeLists.txt Outdated
Comment thread .cmake-format.py
@arpittkhandelwal
Copy link
Copy Markdown
Contributor Author

@arpittkhandelwal Could you please separate the github action changes into a new PR?

yes sir I will raise the new pr for that changes

Comment thread examples/hello_world_component/CMakeLists.txt Outdated
Comment thread libs/CMakeLists.txt Outdated
Comment thread tests/unit/build/CMakeLists.txt Outdated
Comment thread tests/unit/build/CMakeLists.txt Outdated
Comment thread examples/hello_world_component/CMakeLists.txt Outdated
Comment thread cmake/HPX_CXXModules.cmake Outdated
@hkaiser
Copy link
Copy Markdown
Contributor

hkaiser commented Apr 29, 2026

@arpittkhandelwal thanks for refining this PR. Unfortunately, the original issue has not been solved yet. Any ideas what is missing? Does it work for you locally?

Copilot AI review requested due to automatic review settings April 29, 2026 15:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates HPX’s CMake support for C++20 modules to rely on CMake’s native module dependency tracking (CMake 3.29+), ensuring BMIs are properly exported/installed for downstream consumers, and re-enables external build tests when HPX_WITH_CXX_MODULES=ON.

Changes:

  • Simplifies module producer/consumer helpers to avoid manually injecting module output/prebuilt paths and instead rely on FILE_SET CXX_MODULES + scan propagation.
  • Re-enables and adjusts external build tests (including pkg-config-based build checks) for module-enabled builds.
  • Updates downstream example setup to propagate module scanning through hpx_setup_target, and refreshes cmake-format command metadata.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/unit/build/CMakeLists.txt Re-enables external build tests with modules and adjusts pkg-config test flags.
libs/CMakeLists.txt Stops passing a custom module output directory to module producer helper.
examples/hello_world_component/CMakeLists.txt Ensures module scanning is enabled at the right point and passed through hpx_setup_target.
cmake/HPX_SetupTarget.cmake Improves robustness by supporting both build-tree and exported HPXInternal:: module interface targets.
cmake/HPX_CXXModules.cmake Removes manual BMI path flagging and relies on CMake-native module scanning propagation.
.cmake-format.py Updates formatter metadata for the changed module producer function signature.

Comment thread cmake/HPX_CXXModules.cmake Outdated
@arpittkhandelwal
Copy link
Copy Markdown
Contributor Author

arpittkhandelwal commented Apr 29, 2026

@arpittkhandelwal thanks for refining this PR. Unfortunately, the original issue has not been solved yet. Any ideas what is missing? Does it work for you locally?

I tracked down the HPX.Core CI failures it was a mismatch between our manual module flags and CMake’s built-in module handling. We were forcing Clang to write BMIs to a different path than where CMake expected them, which broke imports.

I’ve removed the manual -fmodule-output and -fprebuilt-module-path flags and switched fully to CMake’s native FILE_SET CXX_MODULES with INTERFACE_CXX_SCAN_FOR_MODULES ON.

This should fix the path issues now let’s wait for CI

Copilot AI review requested due to automatic review settings April 29, 2026 18:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Comment thread tests/unit/build/CMakeLists.txt Outdated
Comment thread cmake/HPX_CollectStdHeaders.cmake Outdated
Copilot AI review requested due to automatic review settings April 30, 2026 03:10
@arpittkhandelwal arpittkhandelwal force-pushed the fix/cxx-modules-external-build branch from 9dccae0 to e194bd0 Compare April 30, 2026 03:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Comment thread cmake/HPX_SetupTarget.cmake
Comment thread cmake/HPX_CXXModules.cmake
Comment thread tests/unit/build/CMakeLists.txt
@arpittkhandelwal arpittkhandelwal force-pushed the fix/cxx-modules-external-build branch from a1cc7b7 to b1e91ae Compare April 30, 2026 05:16
Copilot AI review requested due to automatic review settings April 30, 2026 05:24
@arpittkhandelwal arpittkhandelwal force-pushed the fix/cxx-modules-external-build branch from 0f6b9d8 to 86e1a3d Compare April 30, 2026 05:24
@arpittkhandelwal arpittkhandelwal force-pushed the fix/cxx-modules-external-build branch from 86e1a3d to 203151f Compare April 30, 2026 05:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 225 out of 232 changed files in this pull request and generated 3 comments.

Comment thread cmake/HPX_GeneratePackage.cmake
Comment thread cmake/HPX_GeneratePackage.cmake
Comment thread cmake/HPX_SetupTarget.cmake
@arpittkhandelwal arpittkhandelwal force-pushed the fix/cxx-modules-external-build branch from 203151f to 0da2cf7 Compare April 30, 2026 09:54
- Resolved Linux configuration mismatches (GNU extensions) by propagating CMAKE_CXX_EXTENSIONS and HPX_CXX_STANDARD to external tests.
- Fixed Windows installation crashes by removing CXX_MODULES_DIRECTORY from install(EXPORT) and adding MSVC guards for Clang linker flags.
- Improved module metadata propagation by explicitly linking HPXInternal module targets in external examples.
- Added CXX_STANDARD support to hpx_setup_target and applied it to hello_world_component.
- Skipped pkg-config tests when modules are enabled due to lack of BMI discovery support.
- Fixed CMake quoting and logic bugs in standard header collection.
- Applied project-wide cmake-format and resolved CI linting failures.
Copilot AI review requested due to automatic review settings April 30, 2026 11:43
@arpittkhandelwal arpittkhandelwal force-pushed the fix/cxx-modules-external-build branch from 0da2cf7 to 2977701 Compare April 30, 2026 11:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Comment on lines +22 to +26
# CXX_MODULES_DIRECTORY was added in CMake 3.28
set(_cxx_modules_directory_arg)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.28")
set(_cxx_modules_directory_arg CXX_MODULES_DIRECTORY cxx-modules)
endif()
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

_cxx_modules_directory_arg is applied to the build-tree export() calls, but the corresponding install(EXPORT ...) blocks for HPXInternalTargets and HPXTargets do not pass CXX_MODULES_DIRECTORY. If install(EXPORT) is missing this argument, the installed package may not install/generate the per-target C++ module metadata directory, breaking downstream find_package(HPX) consumption of modules from an install tree. Consider forwarding the same ${_cxx_modules_directory_arg} (guarded by the same CMake version check) to both install(EXPORT ...) calls as well.

Copilot uses AI. Check for mistakes.
Comment on lines +138 to +139
# Capture standard library headers (with or without extensions, e.g.
# <vector>, <link.h>, <dlfcn.h>).
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

The comment mentions capturing headers like <link.h>/<dlfcn.h>, but those are not present in STANDARD_LIBRARY_HEADERS above. As written, they will never be captured by the IN_LIST STANDARD_LIBRARY_HEADERS check. Either add the intended headers to STANDARD_LIBRARY_HEADERS (if you want them treated as “standard” for this purpose), or adjust the comment to match the actual list being checked.

Suggested change
# Capture standard library headers (with or without extensions, e.g.
# <vector>, <link.h>, <dlfcn.h>).
# Capture only headers explicitly listed in STANDARD_LIBRARY_HEADERS
# (for example, <vector>).

Copilot uses AI. Check for mistakes.
@arpittkhandelwal
Copy link
Copy Markdown
Contributor Author

arpittkhandelwal commented Apr 30, 2026

@hkaiser sir I found the root cause of the HPX.Core not found CI failures.

We had a conflict between our manual compiler flags and CMake 3.28+'s native module tracking. CMake automatically generates BMIs to CMakeFiles/.dir/ via FILE_SET CXX_MODULES, but our manual -fmodule-output flags were forcing Clang to write to a completely different directory. This caused a path mismatch when consumers tried to import HPX.Core.

Fix: I completely removed the manual -fmodule-output and -fprebuilt-module-path flags from HPX_CXXModules.cmake. We now rely 100% on CMake's native FILE_SET CXX_MODULES and INTERFACE_CXX_SCAN_FOR_MODULES ON to automatically map dependencies and paths for both internal and external builds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix external builds with C++ modules enabled

3 participants