Skip to content

Commit 5b59fe9

Browse files
committed
Remove capy auto-fetch so FetchContent consumers provide it themselves
The three-tier capy resolution (target check, find_package, FetchContent) introduced order dependence and network non-determinism at configure time. Consumers now provide Boost::capy via their own mechanism; CMake resolves the target reference at generation time regardless of declaration order.
1 parent 7d29b69 commit 5b59fe9

File tree

3 files changed

+48
-69
lines changed

3 files changed

+48
-69
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,28 @@ jobs:
586586
toolchain: ${{ env.CMAKE_TOOLCHAIN_FILE }}
587587
ref-source-dir: boost-root/libs/corosio/test/cmake_test
588588

589+
# Standalone root-project builds (build-cmake, coverage, clang-tidy)
590+
# need the consumer to provide Boost::capy. Inject it via
591+
# CMAKE_PROJECT_boost_corosio_INCLUDE so the already-cloned capy-root
592+
# is added as a subdirectory at configure time.
593+
- name: Create capy provider for standalone builds
594+
if: ${{ matrix.build-cmake || matrix.coverage || matrix.clang-tidy }}
595+
shell: bash
596+
run: |
597+
workspace_root=$(echo "$GITHUB_WORKSPACE" | sed 's/\\/\//g')
598+
cat > "${workspace_root}/provide-capy.cmake" << 'EOF'
599+
set(BOOST_CAPY_BUILD_TESTS OFF CACHE BOOL "" FORCE)
600+
set(BOOST_CAPY_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
601+
# Co-locate DLLs with executables so post-build test discovery works
602+
if(BUILD_SHARED_LIBS)
603+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
604+
endif()
605+
add_subdirectory("${COROSIO_CI_CAPY_SOURCE_DIR}"
606+
"${CMAKE_BINARY_DIR}/_deps/capy-build" EXCLUDE_FROM_ALL)
607+
EOF
608+
echo "COROSIO_CI_PROVIDE_CAPY=${workspace_root}/provide-capy.cmake" >> $GITHUB_ENV
609+
echo "COROSIO_CI_CAPY_DIR=${workspace_root}/capy-root" >> $GITHUB_ENV
610+
589611
- name: Root Project CMake Workflow
590612
uses: alandefreitas/cpp-actions/cmake-workflow@v1.9.0
591613
if: ${{ matrix.build-cmake || matrix.coverage }}
@@ -606,6 +628,8 @@ jobs:
606628
cmake-version: '>=3.20'
607629
extra-args: |
608630
-D Boost_VERBOSE=ON
631+
-D CMAKE_PROJECT_boost_corosio_INCLUDE=${{ env.COROSIO_CI_PROVIDE_CAPY }}
632+
-D COROSIO_CI_CAPY_SOURCE_DIR=${{ env.COROSIO_CI_CAPY_DIR }}
609633
${{ matrix.compiler == 'mingw' && '-D CMAKE_VERBOSE_MAKEFILE=ON' || '' }}
610634
${{ contains(matrix.generator || '', 'Visual Studio') && format('-D CMAKE_CONFIGURATION_TYPES={0}', matrix.build-type) || '' }}
611635
${{ env.CMAKE_WOLFSSL_INCLUDE && format('-D WolfSSL_INCLUDE_DIR={0}', env.CMAKE_WOLFSSL_INCLUDE) || '' }}
@@ -630,6 +654,8 @@ jobs:
630654
cmake-version: '>=3.20'
631655
extra-args: |
632656
-D CMAKE_EXPORT_COMPILE_COMMANDS=ON
657+
-D CMAKE_PROJECT_boost_corosio_INCLUDE=${{ env.COROSIO_CI_PROVIDE_CAPY }}
658+
-D COROSIO_CI_CAPY_SOURCE_DIR=${{ env.COROSIO_CI_CAPY_DIR }}
633659
${{ env.CMAKE_WOLFSSL_INCLUDE && format('-D WolfSSL_INCLUDE_DIR={0}', env.CMAKE_WOLFSSL_INCLUDE) || '' }}
634660
${{ env.CMAKE_WOLFSSL_LIBRARY && format('-D WolfSSL_LIBRARY={0}', env.CMAKE_WOLFSSL_LIBRARY) || '' }}
635661
${{ env.CMAKE_OPENSSL_ROOT && format('-D OPENSSL_ROOT_DIR="{0}"', env.CMAKE_OPENSSL_ROOT) || '' }}

README.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,25 @@ Boost.Corosio is a coroutine-only I/O library for C++20 that provides asynchrono
99

1010
## Quick Start
1111

12-
### Standalone build
13-
14-
```bash
15-
git clone https://github.com/cppalliance/corosio.git
16-
cd corosio
17-
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
18-
cmake --build build
19-
```
20-
2112
### Consume via CMake
2213

23-
Use `FetchContent` or `add_subdirectory` to add corosio to your project,
24-
then link against `Boost::corosio`:
14+
Corosio depends on [Capy](https://github.com/cppalliance/capy). Both must
15+
be made available before linking. Use `FetchContent`, `add_subdirectory`,
16+
or `find_package` — declaration order does not matter:
2517

2618
```cmake
2719
include(FetchContent)
20+
21+
FetchContent_Declare(capy
22+
GIT_REPOSITORY https://github.com/cppalliance/capy.git
23+
GIT_TAG develop
24+
GIT_SHALLOW TRUE)
2825
FetchContent_Declare(corosio
2926
GIT_REPOSITORY https://github.com/cppalliance/corosio.git
3027
GIT_TAG develop
3128
GIT_SHALLOW TRUE)
32-
FetchContent_MakeAvailable(corosio)
29+
30+
FetchContent_MakeAvailable(capy corosio)
3331
3432
target_link_libraries(my_app Boost::corosio)
3533
```

cmake/CorosioBuild.cmake

Lines changed: 12 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
# corosio_resolve_deps()
1111
#
12-
# Resolve all build dependencies: sibling Boost libraries when inside a
13-
# boost tree, Capy via find_package / FetchContent, and Threads.
12+
# Resolve build dependencies: sibling Boost libraries when inside a
13+
# boost tree, and Threads. Capy (Boost::capy) must be provided by
14+
# the consumer — CMake resolves the target reference at generation
15+
# time, so declaration order does not matter.
1416
#
1517
# Must be a macro so find_package results propagate to the caller's scope.
1618
macro(corosio_resolve_deps)
@@ -29,55 +31,6 @@ macro(corosio_resolve_deps)
2931
unset(CMAKE_FOLDER)
3032
endif()
3133

32-
# Capy: prefer already-available target, then find_package, then FetchContent
33-
if(NOT TARGET Boost::capy)
34-
find_package(boost_capy QUIET)
35-
endif()
36-
37-
if(NOT TARGET Boost::capy)
38-
include(FetchContent)
39-
40-
# Match capy branch to corosio's current branch when possible
41-
if(NOT DEFINED CACHE{BOOST_COROSIO_CAPY_TAG})
42-
execute_process(
43-
COMMAND git rev-parse --abbrev-ref HEAD
44-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
45-
OUTPUT_VARIABLE _corosio_branch
46-
OUTPUT_STRIP_TRAILING_WHITESPACE
47-
ERROR_QUIET
48-
RESULT_VARIABLE _git_result)
49-
if(_git_result EQUAL 0 AND _corosio_branch)
50-
execute_process(
51-
COMMAND git ls-remote --heads
52-
https://github.com/cppalliance/capy.git
53-
${_corosio_branch}
54-
OUTPUT_VARIABLE _capy_has_branch
55-
OUTPUT_STRIP_TRAILING_WHITESPACE
56-
ERROR_QUIET
57-
TIMEOUT 30)
58-
if(_capy_has_branch)
59-
set(_default_capy_tag "${_corosio_branch}")
60-
endif()
61-
endif()
62-
if(NOT DEFINED _default_capy_tag)
63-
set(_default_capy_tag "develop")
64-
endif()
65-
endif()
66-
set(BOOST_COROSIO_CAPY_TAG "${_default_capy_tag}" CACHE STRING
67-
"Git tag/branch for capy when fetching via FetchContent")
68-
69-
message(STATUS "Fetching capy...")
70-
set(BOOST_CAPY_BUILD_TESTS OFF CACHE BOOL "" FORCE)
71-
set(BOOST_CAPY_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
72-
FetchContent_Declare(
73-
capy
74-
GIT_REPOSITORY https://github.com/cppalliance/capy.git
75-
GIT_TAG ${BOOST_COROSIO_CAPY_TAG}
76-
GIT_SHALLOW TRUE
77-
)
78-
FetchContent_MakeAvailable(capy)
79-
endif()
80-
8134
find_package(Threads REQUIRED)
8235
endmacro()
8336

@@ -196,9 +149,11 @@ function(corosio_install)
196149
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
197150
endforeach()
198151

199-
if(boost_capy_FOUND)
200-
# Capy from find_package (imported target): full install with
201-
# CMake package config and export sets.
152+
get_target_property(_capy_imported boost_capy IMPORTED)
153+
154+
if(_capy_imported)
155+
# Capy is an imported target (find_package, vcpkg, conan):
156+
# full install with export sets and package config.
202157
include(CMakePackageConfigHelpers)
203158

204159
set(BOOST_COROSIO_INSTALL_CMAKEDIR
@@ -233,9 +188,9 @@ function(corosio_install)
233188
install(FILES ${_corosio_config_files}
234189
DESTINATION ${BOOST_COROSIO_INSTALL_CMAKEDIR})
235190
else()
236-
# Capy from source tree (boost root or FetchContent): export sets
237-
# can't work because capy isn't an imported target. Install the
238-
# library and headers only.
191+
# Capy from source tree (boost root, FetchContent,
192+
# add_subdirectory): export sets can't reference a
193+
# non-exported dependency.
239194
install(TARGETS ${_corosio_install_targets}
240195
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
241196
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}

0 commit comments

Comments
 (0)