Skip to content

Support HPX::auto_wrap_main with clang targeting the MSVC ABI - #8171

Merged
hkaiser merged 1 commit into
masterfrom
windows-clang-auto-wrap-main
Nov 21, 2026
Merged

hkaiser merged 1 commit into
masterfrom
windows-clang-auto-wrap-main

Conversation

@hkaiser

@hkaiser hkaiser commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

With MSVC, HPX::auto_wrap_main force-includes hpx/hpx_main.hpp into the executable's own C++ sources, since the MSVC ABI has neither weak symbols nor a linker that can wrap main(). clang on Windows (target x86_64-pc-windows-msvc, GNU-style driver) has the same limitations, but CMake's MSVC is false for it: HPX::auto_wrap_main then linked hpx_auto_wrap (the Linux mechanism), and main() silently didn't run as an HPX thread.

The force-include is now used for every compiler with the MSVC ABI (MSVC OR CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC", i.e. MSVC, clang-cl and clang), spelled -include for the GNU-style driver and /FI otherwise, and hpx_auto_wrap isn't built for them. MinGW is unchanged. The comments that said "on MSVC" now say "with the MSVC ABI".

Tested with clang 22.1 on Windows (on top of #8150, which master needs to link with clang there): tests.unit.init.auto_wrap_main and tests.unit.init.manage_runtime pass, and a minimal program linked with HPX::auto_wrap_main now runs main() on an HPX thread (before: not).

This came up while building the benchmarks of the HPX backend for CCCL (NVIDIA/cccl#7680) with clang on Windows.

@hkaiser hkaiser added this to the 2.1.0 milestone Nov 20, 2026
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2f8a4a03-578a-4939-8964-252e3f110de3
Commits

Reviewing files that changed from the base of the PR and between 637fe21 and 15116dc.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • HPX::auto_wrap_main now supports compilers using the MSVC ABI, including non-MSVC compiler frontends. This broadens automatic main() handling to additional toolchains.
  • Documentation
    • Clarified how automatic main wrapping works for MSVC ABI targets, including force-included headers and the behavior for non-C++ sources.

CMake now applies auto-wrap configuration to native MSVC and toolchains that simulate the MSVC ABI. The force-include option depends on compiler frontend, and hpx_auto_wrap creation and installation exclude both toolchain types.

Changes: MSVC ABI auto-wrap handling

Layer / File(s) Summary
CMake configuration and contract comments
libs/CMakeLists.txt, wrap/CMakeLists.txt, wrap/include/hpx/hpx_main.hpp, wrap/include/hpx/wrap_main.hpp, wrap/src/hpx_main_impl.cpp, tests/unit/init/auto_wrap_main_helper.cpp
For MSVC-ABI toolchains, CMake selects the force-include option by compiler frontend and excludes those toolchains from hpx_auto_wrap creation and installation. Related comments and the test helper describe the MSVC ABI condition.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

  • TheHPXProject/hpx#8081: This PR changes platform-based selection for hpx_auto_wrap and hpx_main.hpp, which shares the build-time platform contract addressed here.

Suggested reviewers: rohanonkeys

Merge Risk: Minimal · previous review 637fe

This change makes HPX::auto_wrap_main force-include hpx/hpx_main.hpp for clang targeting the MSVC ABI, so main() runs on an HPX thread. No merge-blocking risk was found in the reviewed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: HPX::auto_wrap_main now works with clang targeting the MSVC ABI. The changeset force-includes hpx/hpx_main.hpp for MSVC-ABI toolchains and stops building hpx_auto_wrap…
Description check Passed The description explains the problem, the fix, the affected compilers (MSVC, clang-cl, clang with the MSVC ABI), the MinGW exception, and the testing done. It matches the changeset in libs/CMakeLists.…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: HPX::auto_wrap_main now works with clang targeting the MSVC ABI. The changeset force-includes hpx/hpx_main.hpp for MSVC-ABI toolchains and stops building hpx_auto_wrap for them, which matches the title.

Full details: Description check

Explanation

The description explains the problem, the fix, the affected compilers (MSVC, clang-cl, clang with the MSVC ABI), the MinGW exception, and the testing done. It matches the changeset in libs/CMakeLists.txt, wrap/CMakeLists.txt, and the comment updates.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5b4eba46-df0f-4aa5-bdf4-08225ae6ef4d
Commits

Reviewing files that changed from the base of the PR and between 0ef6f22 and 637fe21.

Files selected for processing: 6

  • libs/CMakeLists.txt
  • tests/unit/init/auto_wrap_main_helper.cpp
  • wrap/CMakeLists.txt
  • wrap/include/hpx/hpx_main.hpp
  • wrap/include/hpx/wrap_main.hpp
  • wrap/src/hpx_main_impl.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@codacy-production

Copy link
Copy Markdown

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.

clang on Windows (x86_64-pc-windows-msvc) has no weak symbols either and its linker can't wrap main(), but CMake's MSVC is false for its GNU-style driver: HPX::auto_wrap_main linked hpx_auto_wrap, and main() didn't run as an HPX thread. Every compiler with the MSVC ABI (MSVC, clang-cl and clang) now gets hpx/hpx_main.hpp force-included, with -include for the GNU-style driver and /FI otherwise, and hpx_auto_wrap isn't built for them.

Signed-off-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>
@hkaiser
hkaiser force-pushed the windows-clang-auto-wrap-main branch from 637fe21 to 15116dc Compare November 21, 2026 01:30
@hkaiser
hkaiser merged commit e279227 into master Nov 21, 2026
161 checks passed
@hkaiser
hkaiser deleted the windows-clang-auto-wrap-main branch November 21, 2026 20:03
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.

1 participant