Skip to content

Switch integration flags to KCENON_WITH_* macros#336

Merged
kcenon merged 15 commits into
mainfrom
feature/335-switch-integration-flags-to-kcenon
Dec 23, 2025
Merged

Switch integration flags to KCENON_WITH_* macros#336
kcenon merged 15 commits into
mainfrom
feature/335-switch-integration-flags-to-kcenon

Conversation

@kcenon

@kcenon kcenon commented Dec 22, 2025

Copy link
Copy Markdown
Owner

Summary

This PR implements issue #335 by switching integration flags from BUILD_WITH_* to KCENON_WITH_* macros for consistent feature detection across the codebase.

Changes Made

  1. Source Files - Added #include <kcenon/common/config/feature_flags.h> and replaced BUILD_WITH_* with KCENON_WITH_* macros:

    • src/integration/*.cpp
    • src/core/*.cpp
    • src/network_system.cpp
    • src/metrics/network_metrics.cpp
  2. Header Files - Same changes applied to:

    • include/kcenon/network/integration/*.h
    • include/kcenon/network/core/*.h
    • include/kcenon/network/concepts/*.h
    • include/kcenon/network/utils/*.h
    • include/kcenon/network/di/*.h
    • include/kcenon/network/compatibility.h
  3. CMake Files - Changed target_compile_definitions() from BUILD_WITH_* to WITH_*_SYSTEM:

    • cmake/NetworkSystemIntegration.cmake
    • CMakeLists.txt
    • tests/CMakeLists.txt and subdirectories
    • benchmarks/CMakeLists.txt
    • samples/messaging_system_integration/CMakeLists.txt
  4. Test Files - Updated test files with feature_flags.h and KCENON_WITH_* macros:

    • tests/unit/test_thread_system_adapter.cpp
    • tests/integration/test_compatibility.cpp
    • verify_build.cpp
  5. Documentation - Updated code examples to use KCENON_WITH_* macros:

    • README.md, README_KO.md
    • docs/INTEGRATION.md, docs/INTEGRATION_KO.md
    • docs/FEATURES.md
    • docs/API_REFERENCE_KO.md
    • docs/integration/with-common-system.md
    • docs/integration/with-monitoring.md
    • docs/implementation/02-dependency-and-testing.md

How It Works

  • CMake options remain user-facing as BUILD_WITH_* (e.g., -DBUILD_WITH_THREAD_SYSTEM=ON)
  • CMake compile definitions now use WITH_*_SYSTEM (e.g., WITH_THREAD_SYSTEM)
  • feature_system_deps.h detects these definitions and sets KCENON_WITH_* macros
  • Source code uses #if KCENON_WITH_* for feature detection

Benefits

  • Unified feature detection through feature_flags.h entry point
  • Consistent naming convention across the kcenon ecosystem
  • Clear separation between CMake configuration and source code feature flags
  • Backward compatible (CMake options unchanged)

Test plan

  • Build with default options
  • Build with all integrations enabled: -DBUILD_WITH_THREAD_SYSTEM=ON -DBUILD_WITH_CONTAINER_SYSTEM=ON -DBUILD_WITH_LOGGER_SYSTEM=ON
  • Build with integrations disabled: -DBUILD_WITH_THREAD_SYSTEM=OFF -DBUILD_WITH_CONTAINER_SYSTEM=OFF
  • Run unit tests: ctest --output-on-failure
  • Run verify_build to confirm core headers compile correctly

Closes #335

- Include feature_flags.h header in all integration entry points
- Replace BUILD_WITH_THREAD_SYSTEM with KCENON_WITH_THREAD_SYSTEM
- Replace BUILD_WITH_CONTAINER_SYSTEM with KCENON_WITH_CONTAINER_SYSTEM
- Replace BUILD_WITH_MONITORING_SYSTEM with KCENON_WITH_MONITORING_SYSTEM
- Replace BUILD_WITH_COMMON_SYSTEM with KCENON_WITH_COMMON_SYSTEM
- Update comments to reference new macro names

Part of #335: Align integration gating with unified flag contract
- Include feature_flags.h in all public headers
- Replace BUILD_WITH_THREAD_SYSTEM with KCENON_WITH_THREAD_SYSTEM
- Replace BUILD_WITH_CONTAINER_SYSTEM with KCENON_WITH_CONTAINER_SYSTEM
- Replace BUILD_WITH_MONITORING_SYSTEM with KCENON_WITH_MONITORING_SYSTEM
- Replace BUILD_WITH_COMMON_SYSTEM with KCENON_WITH_COMMON_SYSTEM
- Update documentation comments to reference new macro names

Part of #335: Align integration gating with unified flag contract
Update all target_compile_definitions() to use WITH_*_SYSTEM
instead of BUILD_WITH_*. This allows feature_system_deps.h to
properly detect and define KCENON_WITH_* macros.

Changes:
- BUILD_WITH_CONTAINER_SYSTEM -> WITH_CONTAINER_SYSTEM
- BUILD_WITH_THREAD_SYSTEM -> WITH_THREAD_SYSTEM
- BUILD_WITH_LOGGER_SYSTEM -> WITH_LOGGER_SYSTEM
- BUILD_WITH_COMMON_SYSTEM -> WITH_COMMON_SYSTEM
- BUILD_WITH_MONITORING_SYSTEM -> WITH_MONITORING_SYSTEM

BUILD_WITH_* option() declarations are preserved for backward
compatibility with existing build scripts.

Part of #335: Align integration gating with unified flag contract
Update test files and verify_build.cpp to use feature_flags.h header
and KCENON_WITH_* macros instead of BUILD_WITH_* macros for
consistent feature detection across the codebase.

- Add kcenon/common/config/feature_flags.h include
- Replace BUILD_WITH_THREAD_SYSTEM with KCENON_WITH_THREAD_SYSTEM
- Replace BUILD_WITH_CONTAINER_SYSTEM with KCENON_WITH_CONTAINER_SYSTEM
- Replace BUILD_WITH_LOGGER_SYSTEM with KCENON_WITH_LOGGER_SYSTEM
- Replace BUILD_MESSAGING_BRIDGE with KCENON_WITH_MESSAGING_BRIDGE

Part of #335
Update documentation code examples to use KCENON_WITH_* macros
instead of BUILD_WITH_* for feature detection in source code.

CMake command-line options (-DBUILD_WITH_*) remain unchanged as
they are user-facing configuration options.

Updated files:
- README.md, README_KO.md: Integration example
- docs/INTEGRATION.md, docs/INTEGRATION_KO.md: Feature check examples
- docs/FEATURES.md: Dual API support example
- docs/API_REFERENCE_KO.md: Thread system adapter examples
- docs/integration/with-common-system.md: Concepts integration
- docs/integration/with-monitoring.md: Monitoring adapter example
- docs/implementation/02-dependency-and-testing.md: Test examples

Part of #335
@github-actions

Copy link
Copy Markdown
Contributor

Performance Comparison

Base Branch Results

No base results

PR Branch Results

No PR results

Create network_system's own feature_flags.h that works both with
and without common_system dependency:

- When common_system is available (WITH_COMMON_SYSTEM defined),
  include common_system's feature_flags.h
- When common_system is not available, define KCENON_WITH_* macros
  locally based on CMake definitions (WITH_*_SYSTEM)

Update all source and header files to use the local feature_flags.h
at <kcenon/network/config/feature_flags.h> instead of requiring
common_system's header.

This fixes standalone builds (Minimal Build) that were failing due
to missing common_system headers.

Part of #335
@github-actions

Copy link
Copy Markdown
Contributor

Performance Comparison

Base Branch Results

No base results

PR Branch Results

No PR results

When thread_system is built with common_system, it uses
KCENON_HAS_COMMON_EXECUTOR=1 which affects the class layout of
thread_pool (conditional inheritance from IExecutor interface).

network_system must define the same macro when including thread_system
headers to ensure consistent class layout across compilation units.
Without this, Windows MSVC fails with LNK2019 unresolved external
symbol errors for thread_pool::is_running().
@github-actions

Copy link
Copy Markdown
Contributor

Performance Comparison

Base Branch Results

No base results

PR Branch Results

No PR results

Update remaining code examples in documentation to use the new
KCENON_WITH_* macro style instead of the old BUILD_WITH_* or
#ifdef patterns, consistent with the codebase changes.
@github-actions

Copy link
Copy Markdown
Contributor

Performance Comparison

Base Branch Results

No base results

PR Branch Results

No PR results

Fix ODR violation that caused ServerStartupOnUsedPort test to abort.
The integration tests were defining BUILD_WITH_* macros but
feature_flags.h only detects WITH_*_SYSTEM macros. This caused
KCENON_WITH_COMMON_SYSTEM to be 0 in tests but 1 in the library,
resulting in class layout mismatch (messaging_server has conditional
members based on KCENON_WITH_COMMON_SYSTEM).

Changes:
- BUILD_WITH_COMMON_SYSTEM -> WITH_COMMON_SYSTEM
- BUILD_WITH_LOGGER_SYSTEM -> WITH_LOGGER_SYSTEM
- BUILD_WITH_THREAD_SYSTEM -> WITH_THREAD_SYSTEM
- Add missing WITH_CONTAINER_SYSTEM

This aligns integration tests with all other test CMakeLists.txt
which already use WITH_*_SYSTEM macros.
@github-actions

Copy link
Copy Markdown
Contributor

Performance Comparison

Base Branch Results

No base results

PR Branch Results

No PR results

Document the feature flag changes made in PR #336:
- Switch from BUILD_WITH_* to KCENON_WITH_* macros
- Add feature_flags.h for unified feature detection
- Fix ODR violation in integration tests

Closes #335
@github-actions

Copy link
Copy Markdown
Contributor

Performance Comparison

Base Branch Results

No base results

PR Branch Results

No PR results

Fix ODR violation that caused "corrupted size vs. prev_size" error
on Ubuntu Debug and test failures on macOS Release.

The integration_tests were using BUILD_WITH_* CMake options to
determine compile definitions, but these don't always match the
actual system availability detected by NetworkSystemIntegration.cmake.

Changes:
- Use *_SYSTEM_INCLUDE_DIR variables instead of BUILD_WITH_* options
  to detect actual system availability
- Add KCENON_HAS_COMMON_EXECUTOR=1 when both thread_system and
  common_system are available (required for consistent thread_pool
  class layout)

This aligns integration_tests compile definitions with the pattern
used in tests/CMakeLists.txt and tests/integration/CMakeLists.txt.

Part of #335
On macOS, localhost resolves to IPv6 (::1) first, then falls back
to IPv4 (127.0.0.1) when the connection fails. This fallback process
can take 5-10 seconds, causing test timeouts in CI environments.

Changes:
- Replace "localhost" with "127.0.0.1" in ConnectClient()
- Replace "localhost" with "127.0.0.1" in ConnectAllClients()
- Increase CI timeout from 2-3 seconds to 5 seconds for consistency

This fixes ServerShutdownWithActiveConnections test failures on
macOS Release builds.

Part of #335
@github-actions

Copy link
Copy Markdown
Contributor

Performance Comparison

Base Branch Results

No base results

PR Branch Results

No PR results

Add details about the ODR violation fix and macOS IPv6 delay fix
to the KCENON_WITH_* feature flag unification section:
- *_SYSTEM_INCLUDE_DIR pattern for consistent macro definitions
- KCENON_HAS_COMMON_EXECUTOR for thread_pool class layout
- 127.0.0.1 instead of localhost to avoid IPv6 fallback delays

Part of #335
@github-actions

Copy link
Copy Markdown
Contributor

Performance Comparison

Base Branch Results

No base results

PR Branch Results

No PR results

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

Performance Comparison

Base Branch Results

No base results

PR Branch Results

No PR results

When start_server() fails due to port binding errors (e.g., address
already in use), previously created resources (io_context_, work_guard_)
were not cleaned up. This caused heap corruption during object destruction.

Changes:
- Add resource cleanup in start_server() catch blocks to release
  partially created resources before returning error
- Add explicit resource cleanup in destructor to handle cases where
  stop_server() returns early due to is_running_ being false

This fixes "corrupted size vs. prev_size" errors in
ConnectionLifecycleTest.ServerStartupOnUsedPort on Linux Debug builds.
Document the heap corruption fix in both English and Korean changelogs.
@github-actions

Copy link
Copy Markdown
Contributor

Performance Comparison

Base Branch Results

No base results

PR Branch Results

No PR results

@kcenon kcenon merged commit 6971192 into main Dec 23, 2025
44 checks passed
@kcenon kcenon deleted the feature/335-switch-integration-flags-to-kcenon branch December 23, 2025 02:39
kcenon added a commit that referenced this pull request Apr 13, 2026
* refactor(integration): switch to KCENON_WITH_* macros in source files

- Include feature_flags.h header in all integration entry points
- Replace BUILD_WITH_THREAD_SYSTEM with KCENON_WITH_THREAD_SYSTEM
- Replace BUILD_WITH_CONTAINER_SYSTEM with KCENON_WITH_CONTAINER_SYSTEM
- Replace BUILD_WITH_MONITORING_SYSTEM with KCENON_WITH_MONITORING_SYSTEM
- Replace BUILD_WITH_COMMON_SYSTEM with KCENON_WITH_COMMON_SYSTEM
- Update comments to reference new macro names

Part of #335: Align integration gating with unified flag contract

* refactor(headers): switch to KCENON_WITH_* macros in header files

- Include feature_flags.h in all public headers
- Replace BUILD_WITH_THREAD_SYSTEM with KCENON_WITH_THREAD_SYSTEM
- Replace BUILD_WITH_CONTAINER_SYSTEM with KCENON_WITH_CONTAINER_SYSTEM
- Replace BUILD_WITH_MONITORING_SYSTEM with KCENON_WITH_MONITORING_SYSTEM
- Replace BUILD_WITH_COMMON_SYSTEM with KCENON_WITH_COMMON_SYSTEM
- Update documentation comments to reference new macro names

Part of #335: Align integration gating with unified flag contract

* build(cmake): switch compile definitions to WITH_*_SYSTEM

Update all target_compile_definitions() to use WITH_*_SYSTEM
instead of BUILD_WITH_*. This allows feature_system_deps.h to
properly detect and define KCENON_WITH_* macros.

Changes:
- BUILD_WITH_CONTAINER_SYSTEM -> WITH_CONTAINER_SYSTEM
- BUILD_WITH_THREAD_SYSTEM -> WITH_THREAD_SYSTEM
- BUILD_WITH_LOGGER_SYSTEM -> WITH_LOGGER_SYSTEM
- BUILD_WITH_COMMON_SYSTEM -> WITH_COMMON_SYSTEM
- BUILD_WITH_MONITORING_SYSTEM -> WITH_MONITORING_SYSTEM

BUILD_WITH_* option() declarations are preserved for backward
compatibility with existing build scripts.

Part of #335: Align integration gating with unified flag contract

* test: switch to KCENON_WITH_* macros in test files

Update test files and verify_build.cpp to use feature_flags.h header
and KCENON_WITH_* macros instead of BUILD_WITH_* macros for
consistent feature detection across the codebase.

- Add kcenon/common/config/feature_flags.h include
- Replace BUILD_WITH_THREAD_SYSTEM with KCENON_WITH_THREAD_SYSTEM
- Replace BUILD_WITH_CONTAINER_SYSTEM with KCENON_WITH_CONTAINER_SYSTEM
- Replace BUILD_WITH_LOGGER_SYSTEM with KCENON_WITH_LOGGER_SYSTEM
- Replace BUILD_MESSAGING_BRIDGE with KCENON_WITH_MESSAGING_BRIDGE

Part of #335

* docs: update code examples to use KCENON_WITH_* macros

Update documentation code examples to use KCENON_WITH_* macros
instead of BUILD_WITH_* for feature detection in source code.

CMake command-line options (-DBUILD_WITH_*) remain unchanged as
they are user-facing configuration options.

Updated files:
- README.md, README_KO.md: Integration example
- docs/INTEGRATION.md, docs/INTEGRATION_KO.md: Feature check examples
- docs/FEATURES.md: Dual API support example
- docs/API_REFERENCE_KO.md: Thread system adapter examples
- docs/integration/with-common-system.md: Concepts integration
- docs/integration/with-monitoring.md: Monitoring adapter example
- docs/implementation/02-dependency-and-testing.md: Test examples

Part of #335

* fix: add local feature_flags.h for standalone builds

Create network_system's own feature_flags.h that works both with
and without common_system dependency:

- When common_system is available (WITH_COMMON_SYSTEM defined),
  include common_system's feature_flags.h
- When common_system is not available, define KCENON_WITH_* macros
  locally based on CMake definitions (WITH_*_SYSTEM)

Update all source and header files to use the local feature_flags.h
at <kcenon/network/config/feature_flags.h> instead of requiring
common_system's header.

This fixes standalone builds (Minimal Build) that were failing due
to missing common_system headers.

Part of #335

* fix(cmake): add KCENON_HAS_COMMON_EXECUTOR for thread_system integration

When thread_system is built with common_system, it uses
KCENON_HAS_COMMON_EXECUTOR=1 which affects the class layout of
thread_pool (conditional inheritance from IExecutor interface).

network_system must define the same macro when including thread_system
headers to ensure consistent class layout across compilation units.
Without this, Windows MSVC fails with LNK2019 unresolved external
symbol errors for thread_pool::is_running().

* docs: update code examples to use KCENON_WITH_* macros

Update remaining code examples in documentation to use the new
KCENON_WITH_* macro style instead of the old BUILD_WITH_* or
#ifdef patterns, consistent with the codebase changes.

* fix(cmake): use WITH_*_SYSTEM macros in integration tests

Fix ODR violation that caused ServerStartupOnUsedPort test to abort.
The integration tests were defining BUILD_WITH_* macros but
feature_flags.h only detects WITH_*_SYSTEM macros. This caused
KCENON_WITH_COMMON_SYSTEM to be 0 in tests but 1 in the library,
resulting in class layout mismatch (messaging_server has conditional
members based on KCENON_WITH_COMMON_SYSTEM).

Changes:
- BUILD_WITH_COMMON_SYSTEM -> WITH_COMMON_SYSTEM
- BUILD_WITH_LOGGER_SYSTEM -> WITH_LOGGER_SYSTEM
- BUILD_WITH_THREAD_SYSTEM -> WITH_THREAD_SYSTEM
- Add missing WITH_CONTAINER_SYSTEM

This aligns integration tests with all other test CMakeLists.txt
which already use WITH_*_SYSTEM macros.

* docs: add CHANGELOG entries for KCENON_WITH_* feature flag unification

Document the feature flag changes made in PR #336:
- Switch from BUILD_WITH_* to KCENON_WITH_* macros
- Add feature_flags.h for unified feature detection
- Fix ODR violation in integration tests

Closes #335

* fix(cmake): use *_SYSTEM_INCLUDE_DIR for integration test definitions

Fix ODR violation that caused "corrupted size vs. prev_size" error
on Ubuntu Debug and test failures on macOS Release.

The integration_tests were using BUILD_WITH_* CMake options to
determine compile definitions, but these don't always match the
actual system availability detected by NetworkSystemIntegration.cmake.

Changes:
- Use *_SYSTEM_INCLUDE_DIR variables instead of BUILD_WITH_* options
  to detect actual system availability
- Add KCENON_HAS_COMMON_EXECUTOR=1 when both thread_system and
  common_system are available (required for consistent thread_pool
  class layout)

This aligns integration_tests compile definitions with the pattern
used in tests/CMakeLists.txt and tests/integration/CMakeLists.txt.

Part of #335

* fix(test): use 127.0.0.1 instead of localhost to avoid IPv6 delays

On macOS, localhost resolves to IPv6 (::1) first, then falls back
to IPv4 (127.0.0.1) when the connection fails. This fallback process
can take 5-10 seconds, causing test timeouts in CI environments.

Changes:
- Replace "localhost" with "127.0.0.1" in ConnectClient()
- Replace "localhost" with "127.0.0.1" in ConnectAllClients()
- Increase CI timeout from 2-3 seconds to 5 seconds for consistency

This fixes ServerShutdownWithActiveConnections test failures on
macOS Release builds.

Part of #335

* docs: update CHANGELOG with ODR and IPv6 fix details

Add details about the ODR violation fix and macOS IPv6 delay fix
to the KCENON_WITH_* feature flag unification section:
- *_SYSTEM_INCLUDE_DIR pattern for consistent macro definitions
- KCENON_HAS_COMMON_EXECUTOR for thread_pool class layout
- 127.0.0.1 instead of localhost to avoid IPv6 fallback delays

Part of #335

* fix(server): prevent heap corruption when start_server fails

When start_server() fails due to port binding errors (e.g., address
already in use), previously created resources (io_context_, work_guard_)
were not cleaned up. This caused heap corruption during object destruction.

Changes:
- Add resource cleanup in start_server() catch blocks to release
  partially created resources before returning error
- Add explicit resource cleanup in destructor to handle cases where
  stop_server() returns early due to is_running_ being false

This fixes "corrupted size vs. prev_size" errors in
ConnectionLifecycleTest.ServerStartupOnUsedPort on Linux Debug builds.

* docs: add changelog entries for messaging_server resource cleanup fix

Document the heap corruption fix in both English and Korean changelogs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch integration flags to KCENON_*

1 participant