Skip to content

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

Open
arpittkhandelwal wants to merge 2 commits 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 2 commits 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

Not up to standards ⛔

🔴 Issues 2 high

Alerts:
⚠ 2 issues (≤ 0 issues of at least minor severity)

Results:
2 new issues

Category Results
Security 2 high

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
Comment on lines 86 to 90
@@ -110,28 +89,6 @@ function(hpx_configure_module_producer producer)
return()
endif()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can this be removed as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, absolutely! Since the manual compiler flags that were below it have been removed, that return() check became a dangling zombie.

I've just pushed a commit that completely removes the redundant if(MSVC) checks from both the producer and consumer blocks.

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 on lines +238 to +244
hpx_configure_module_consumer(${target} HPXInternal::hpx_core_module_if)
endif()

if(TARGET hpx_full_module_if)
hpx_configure_module_consumer(${target} hpx_full_module_if)
elseif(TARGET HPXInternal::hpx_full_module_if)
hpx_configure_module_consumer(${target} HPXInternal::hpx_full_module_if)
if(TARGET hpx_full_module_if)
hpx_configure_module_consumer(${target} hpx_full_module_if)
elseif(TARGET HPXInternal::hpx_full_module_if)
hpx_configure_module_consumer(${target} HPXInternal::hpx_full_module_if)
@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
@arpittkhandelwal arpittkhandelwal force-pushed the fix/cxx-modules-external-build branch from cf503da to d252c42 Compare 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 CMake support for C++20 modules to rely on CMake’s native module/BMI handling (CMake ≥ 3.29) and re-enables the previously disabled external build tests when HPX_WITH_CXX_MODULES=ON.

Changes:

  • Remove manual BMI output/prebuilt-module-path flag injection and simplify module producer/consumer wiring.
  • Re-enable tests/unit/build external build tests with modules enabled, with adjustments for pkg-config based builds.
  • Improve robustness of module consumer setup by supporting both build-tree and installed (HPXInternal::) module interface targets.

Reviewed changes

Copilot reviewed 18 out of 18 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; adjusts pkg-config compile flags to disable module imports for that test path.
libs/CMakeLists.txt Updates module producer configuration call site to match simplified signature.
examples/hello_world_component/CMakeLists.txt Adds module interface target linking and enables module scanning via hpx_setup_target(... SCAN_FOR_MODULES ON) in macro setup.
cmake/HPX_SetupTarget.cmake Makes module consumer setup work with both non-namespaced and HPXInternal:: imported module interface targets; errors if missing.
cmake/HPX_CXXModules.cmake Simplifies module producer/consumer macros to rely on CMake-native module scanning/installation behavior (removes manual flag injection).
.cmake-format.py Updates formatting config for the changed hpx_configure_module_producer signature.

Comment on lines 103 to 107
"${PROJECT_SOURCE_DIR}/examples/hello_world_component/Makefile"
SRC_DIR=${PROJECT_SOURCE_DIR}/examples/hello_world_component
HPX_DIR=${hpx_dir} CXX=${CMAKE_CXX_COMPILER} CC=${CMAKE_C_COMPILER}
CXX_FLAGS=${CMAKE_CXX_FLAGS_SAFE} PKG_CONFIG=${PKG_CONFIG_EXECUTABLE}
CXX_FLAGS=${PKGCONFIG_CXX_FLAGS} PKG_CONFIG=${PKG_CONFIG_EXECUTABLE}
BUILD_TYPE=$<CONFIGURATION>
Comment on lines +34 to +39
if(HPX_WITH_CXX_MODULES)
if(TARGET hpx_core_module_if)
if(TARGET hello_world_component)
target_link_libraries(
hello_world_component PRIVATE hpx_core_module_if
)
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