Skip to content

Commit c186879

Browse files
author
Hackathon User
committed
fix(include_local): remove automatic hpx_main.hpp inclusion from local.hpp
hpx/local.hpp is a convenience umbrella header for the Standard Parallel Toolkit. It must never include hpx_main.hpp automatically because that header has observable, TU-wide side effects: 1. On Linux/macOS with HPX_HAVE_DYNAMIC_HPX_MAIN, wrap_main.hpp emits non-weak *strong* definitions of hpx_start::include_libhpx_wrap and hpx_start::app_name_libhpx_wrap into every TU that includes it. These conflict with the definitions in libhpx_wrap.so and cause 'multiple definition' linker errors in distributed-runtime builds (e.g. the 18-contracts-lcos_local CI job). 2. Without HPX_HAVE_DYNAMIC_HPX_MAIN (static linking, Windows), it executes '#define main hpx_startup::user_main', which silently renames the program entry point in every TU and breaks test executables that define their own main(). Both issues require that hpx_main.hpp remain an *explicit* user opt-in, included only in the single translation unit that owns the program's entry point. An umbrella convenience header is the wrong place for it. Also remove the now-redundant #define HPX_NO_MAIN guard from the local_header unit test since local.hpp no longer includes hpx_main.hpp. Refs: #7070 Signed-off-by: shivansh023023 <singhshivansh023@gmail.com>
1 parent fb114de commit c186879

2 files changed

Lines changed: 14 additions & 16 deletions

File tree

libs/core/include_local/include/hpx/local.hpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,27 @@
1010
/// This header bundles the **Standard Parallel Toolkit** -- the most commonly
1111
/// used HPX facilities for local (single-node) execution:
1212
///
13-
/// - \c hpx/algorithm.hpp -- Parallel algorithms (for_each, sort, ...)
14-
/// - \c hpx/execution.hpp -- Execution policies (par, par_unseq, seq)
15-
/// - \c hpx/future.hpp -- Futures and dataflow
16-
/// - \c hpx/numeric.hpp -- Parallel numeric (reduce, transform_reduce, ...)
13+
/// - \c hpx/modules/algorithms.hpp -- Parallel algorithms (for_each, sort, ...)
14+
/// - \c hpx/modules/execution.hpp -- Execution policies (par, par_unseq, seq)
15+
/// - \c hpx/modules/futures.hpp -- Futures and dataflow
16+
/// - \c hpx/numeric.hpp -- Parallel numeric (reduce, transform_reduce, ...)
1717
///
1818
/// **Selection criteria**: each header is part of the HPX core module,
1919
/// provides ISO C++ Standard Library parallel equivalents, and has no
2020
/// dependency on the distributed runtime or networking layer.
21+
///
22+
/// \note This header intentionally does NOT include hpx/hpx_main.hpp.
23+
/// Including hpx_main.hpp has observable side effects: it emits
24+
/// non-weak symbol definitions (hpx_start::include_libhpx_wrap,
25+
/// hpx_start::app_name_libhpx_wrap) into every translation unit
26+
/// that includes it, and redefines 'main' via a preprocessor macro.
27+
/// Users who need the zero-boilerplate HPX runtime entry-point should
28+
/// include hpx/hpx_main.hpp explicitly in their *single* main TU.
2129

2230
#pragma once
2331

2432
#include <hpx/config.hpp>
2533

26-
#if !defined(HPX_HAVE_DISTRIBUTED_RUNTIME) && !defined(HPX_NO_MAIN)
27-
#if __has_include(<hpx/hpx_main.hpp>)
28-
#include <hpx/hpx_main.hpp> // hpxinspect:noinclude:hpx/hpx_main.hpp
29-
#endif
30-
#endif
31-
3234
// --- Standard Parallel Toolkit (core, no networking dependency) ---
3335
#include <hpx/modules/algorithms.hpp>
3436
#include <hpx/modules/execution.hpp>

libs/core/include_local/tests/unit/local_header.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@
77
// Verify that hpx/local.hpp provides access to the Standard Parallel Toolkit:
88
// parallel algorithms, numeric algorithms, and execution policies.
99
//
10-
// We use hpx::local::init to avoid any dependency on the full wrap module.
10+
// We use hpx::local::init to drive the HPX runtime without requiring any
11+
// dependency on the wrap module (hpx_main.hpp / HPX::wrap_main).
1112

1213
#include <hpx/config.hpp>
13-
14-
// Define HPX_NO_MAIN to ensure the test itself does not trigger inclusion
15-
// of hpx_main.hpp from local.hpp, thus bypassing any circular dependency
16-
// during the core module test build.
17-
#define HPX_NO_MAIN
1814
#include <hpx/init.hpp>
1915
#include <hpx/local.hpp>
2016

0 commit comments

Comments
 (0)