Skip to content

Commit 94f15a6

Browse files
authored
First step to install cxx_module (#92)
* First step to install cxx_module * Allow CI workflow to run on every branch * Disable g++ builds for now * Cleanup * Set CXX_MODULES_DIRECTORY and CMAKE_DEBUG_POSTFIX * Fix module example * Prevent linker problems with sanitizer or gcov
1 parent bdd2da2 commit 94f15a6

File tree

12 files changed

+72
-139
lines changed

12 files changed

+72
-139
lines changed

.github/workflows/linux.yml

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,7 @@ name: Linux Build
55

66
on:
77
push:
8-
branches: ["main"]
9-
paths:
10-
- "include/**"
11-
- "src/**"
12-
- "tests/**"
13-
- "examples/**"
14-
- "cmake/**"
15-
- "Makefile"
16-
- "CMakePresets.json"
17-
- "CMakeLists.txt"
18-
- ".github/workflows/linux.yml"
198
pull_request:
20-
branches: ["main"]
21-
paths:
22-
- "include/**"
23-
- "src/**"
24-
- "tests/**"
25-
- "examples/**"
26-
- "cmake/**"
27-
- "Makefile"
28-
- "CMakePresets.json"
29-
- "CMakeLists.txt"
30-
- ".github/workflows/linux.yml"
319

3210
jobs:
3311
build:
@@ -38,7 +16,8 @@ jobs:
3816
matrix:
3917
# TODO: sanitizer: [debug, release, asan, usan, tsan, lsan, msan]
4018
preset: [debug, release]
41-
compiler: [g++-14, clang++-19]
19+
# TODO: compiler: [g++-15, clang++-19]
20+
compiler: [clang++-19]
4221

4322
steps:
4423
- uses: actions/checkout@v4

.github/workflows/macos.yml

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,7 @@ name: Macos Build
55

66
on:
77
push:
8-
branches: ["main"]
9-
paths:
10-
- "include/**"
11-
- "src/**"
12-
- "tests/**"
13-
- "examples/**"
14-
- "cmake/**"
15-
- "Makefile"
16-
- "CMakePresets.json"
17-
- "CMakeLists.txt"
18-
- ".github/workflows/macos.yml"
198
pull_request:
20-
branches: ["main"]
21-
paths:
22-
- "include/**"
23-
- "src/**"
24-
- "tests/**"
25-
- "examples/**"
26-
- "cmake/**"
27-
- "Makefile"
28-
- "CMakePresets.json"
29-
- "CMakeLists.txt"
30-
- ".github/workflows/macos.yml"
319

3210
jobs:
3311
build:
@@ -37,8 +15,8 @@ jobs:
3715

3816
matrix:
3917
preset: [debug, release]
40-
# TODO: compiler: [g++, clang++-19]
41-
compiler: [g++, clang++-18]
18+
# TODO: compiler: [g++-15, clang++-19]
19+
compiler: [clang++-19]
4220

4321
steps:
4422
- uses: actions/checkout@v4
@@ -47,23 +25,20 @@ jobs:
4725
# if: startsWith(matrix.compiler, 'clang')
4826
uses: aminya/setup-cpp@v1
4927
with:
50-
# TODO: compiler: llvm-19
51-
# clangtidy: true
52-
# cmake: true
5328
ninja: true
5429

5530
- name: Install llvm-19
5631
if: startsWith(matrix.compiler, 'clang')
5732
run: |
5833
brew install llvm@19 || echo ignored
5934
60-
- name: macos clang++-18 ${{ matrix.preset }}
35+
- name: macos clang++-19 ${{ matrix.preset }}
6136
if: startsWith(matrix.compiler, 'clang')
62-
run: CXX=$(brew --prefix llvm@18)/bin/clang++ cmake --workflow --preset ${{ matrix.preset }}
37+
run: CXX=$(brew --prefix llvm@19)/bin/clang++ cmake --workflow --preset ${{ matrix.preset }}
6338

64-
- name: macos clang++-18 sanitizer
39+
- name: macos clang++-19 sanitizer
6540
if: startsWith(matrix.compiler, 'clang') && startsWith(matrix.preset, 'debug')
66-
run: CXX=$(brew --prefix llvm@18)/bin/clang++ make all
41+
run: CXX=$(brew --prefix llvm@19)/bin/clang++ make all
6742

6843
- name: macos g++ ${{ matrix.preset }}
6944
if: startsWith(matrix.compiler, 'g++')

.github/workflows/windows.yml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,7 @@ name: Windows Build
55

66
on:
77
push:
8-
branches: ["main"]
9-
paths:
10-
- "include/**"
11-
- "src/**"
12-
- "tests/**"
13-
- "examples/**"
14-
- "cmake/**"
15-
- "CMakePresets.json"
16-
- "CMakeLists.txt"
17-
- ".github/workflows/windows.yml"
188
pull_request:
19-
branches: ["main"]
20-
paths:
21-
- "include/**"
22-
- "src/**"
23-
- "tests/**"
24-
- "examples/**"
25-
- "cmake/**"
26-
- "CMakePresets.json"
27-
- "CMakeLists.txt"
28-
- ".github/workflows/windows.yml"
299

3010
jobs:
3111
build:

CMakeLists.txt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44
# cmake-format: on
55

6-
cmake_minimum_required(VERSION 3.25...3.31)
6+
cmake_minimum_required(VERSION 3.30...3.31)
77

8-
project(beman_execution26 VERSION 0.0.1 LANGUAGES CXX)
8+
project(beman_execution26 VERSION 0.1.0 LANGUAGES CXX)
99

1010
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
1111
message(FATAL_ERROR "In-source builds are not allowed!")
1212
endif()
1313

14-
set(CMAKE_CXX_SCAN_FOR_MODULES ON)
14+
# Note that scanning is only performed if C++20 or higher is enabled for the target. Scanning for modules in the target's
15+
# sources belonging to file sets of type CXX_MODULES is always performed.
16+
# not needed: set(CMAKE_CXX_SCAN_FOR_MODULES ON)
17+
1518
set(TARGET_NAME execution26)
1619
set(TARGET_NAMESPACE beman) # FIXME: not used in install(EXPORT ...) CK?
1720
set(TARGET_PREFIX ${TARGET_NAMESPACE}.${TARGET_NAME})
@@ -20,6 +23,9 @@ set(TARGET_ALIAS ${TARGET_LIBRARY}::${TARGET_LIBRARY})
2023
set(TARGET_PACKAGE_NAME ${PROJECT_NAME}-config)
2124
set(TARGETS_EXPORT_NAME ${PROJECT_NAME}-targets)
2225

26+
# This variable is a special case of the more-general CMAKE_<CONFIG>_POSTFIX variable for the DEBUG configuration.
27+
set(CMAKE_DEBUG_POSTFIX D)
28+
2329
include(GNUInstallDirs)
2430
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
2531

@@ -56,7 +62,7 @@ if(CMAKE_BUILD_TYPE STREQUAL Debug)
5662
ENABLE_SANITIZER_POINTER_COMPARE
5763
ENABLE_SANITIZER_POINTER_SUBTRACT
5864
ENABLE_CONTROL_FLOW_PROTECTION
59-
ENABLE_STACK_PROTECTION
65+
# XXX ENABLE_STACK_PROTECTION
6066
ENABLE_OVERFLOW_PROTECTION
6167
# ENABLE_ELF_PROTECTION
6268
# ENABLE_RUNTIME_SYMBOLS_RESOLUTION
@@ -86,7 +92,7 @@ include(CMakePackageConfigHelpers)
8692
write_basic_package_version_file(
8793
${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PACKAGE_NAME}-version.cmake
8894
VERSION ${CMAKE_PROJECT_VERSION}
89-
COMPATIBILITY AnyNewerVersion
95+
COMPATIBILITY SameMajorVersion
9096
)
9197

9298
configure_package_config_file(

cmake/CMakeGenericPresets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"type": "path",
1313
"value": "${sourceDir}/stagedir"
1414
},
15-
"CMAKE_CXX_EXTENSIONS": false,
15+
"CMAKE_CXX_EXTENSIONS": true,
1616
"CMAKE_CXX_STANDARD": "23",
1717
"CMAKE_CXX_STANDARD_REQUIRED": true,
1818
"CMAKE_EXPORT_COMPILE_COMMANDS": true,

examples/modules.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33

44
// import std;
55
#include <iostream>
6+
#include <string>
67
#if __cpp_modules < 201907L
78
#include <beman/execution26/execution.hpp>
89
#else
9-
import beman.execution26;
10+
import beman_execution26;
1011
#endif
1112

1213
namespace ex = beman::execution26;
1314

14-
int main() {}
15+
int main() {
16+
auto [result] = ex::sync_wait(ex::when_all(ex::just(std::string("hello, ")), ex::just(std::string("world"))) |
17+
ex::then([](const auto& s1, const auto& s2) { return s1 + s2; }))
18+
.value_or(std::tuple(std::string("oops")));
19+
std::cout << "result='" << result << "'\n";
20+
}

src/beman/execution26/CMakeLists.txt

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ add_library(${TARGET_LIBRARY} STATIC)
77
add_library(${TARGET_ALIAS} ALIAS ${TARGET_LIBRARY})
88

99
if(CMAKE_BUILD_TYPE STREQUAL Debug)
10-
target_link_libraries(${TARGET_LIBRARY} PUBLIC $<BUILD_INTERFACE:${TARGET_LIBRARY}_project_options>)
10+
# NOTE: Sanitizer or gcov is not possible for CXX_MODULES! CK
11+
# XXX target_link_libraries(${TARGET_LIBRARY} PUBLIC $<BUILD_INTERFACE:${TARGET_LIBRARY}_project_options>)
1112
target_link_libraries(${TARGET_LIBRARY} PUBLIC $<BUILD_INTERFACE:${TARGET_LIBRARY}_project_warnings>)
1213
endif()
1314

@@ -188,33 +189,26 @@ target_compile_features(${TARGET_LIBRARY} PUBLIC
188189
)
189190

190191
target_sources(
191-
beman_execution26
192-
PUBLIC FILE_SET
193-
beman_execution26 TYPE CXX_MODULES FILES execution.cpp
192+
${TARGET_LIBRARY}
193+
PUBLIC FILE_SET ${TARGET_LIBRARY}_modules
194+
TYPE CXX_MODULES FILES execution.cppm
194195
)
195196

196-
if(FALSE)
197197
install(
198198
TARGETS ${TARGET_LIBRARY}
199-
EXPORT ${TARGETS_EXPORT_NAME}1
200-
ARCHIVE DESTINATION lib/$<CONFIG>
199+
EXPORT ${TARGETS_EXPORT_NAME}
200+
ARCHIVE # XXX DESTINATION lib/$<CONFIG>
201+
FILE_SET ${TARGET_LIBRARY}_modules
202+
# There's currently no convention for this location
203+
DESTINATION ${INSTALL_CONFIGDIR}/src
201204
FILE_SET ${TARGET_LIBRARY}_public_headers
202205
FILE_SET ${TARGET_LIBRARY}_detail_headers
203206
)
204207

205208
install(
206-
EXPORT ${TARGETS_EXPORT_NAME}1
207-
FILE ${TARGETS_EXPORT_NAME}.cmake
209+
EXPORT ${TARGETS_EXPORT_NAME}
208210
DESTINATION "${INSTALL_CONFIGDIR}"
211+
CXX_MODULES_DIRECTORY .
209212
NAMESPACE ${TARGET_LIBRARY}::
210213
)
211-
212-
#-dk:TODO build/default/src/beman/execution26/CMakeFiles/beman_execution26.dir/beman.execution26.pcm
213-
install(
214-
TARGETS beman_execution26
215-
EXPORT beman_execution26
216-
COMPONENT FILE_SET beman_execution26
217-
DESTINATION lib/beman/execution26
218-
)
219-
endif()
220-
# cmake-format: on
214+
# cmake-format: on
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module;
88
#include <beman/execution26/execution.hpp>
99
#include <beman/execution26/stop_token.hpp>
1010

11-
export module beman.execution26;
11+
export module beman_execution26;
1212

1313
namespace beman::execution26 {
1414
export int version(0);

tests/beman/execution26/CMakeLists.txt

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
# src/beman/execution26/tests/CMakeLists.txt
22
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3-
cmake_minimum_required(VERSION 3.25...3.31)
3+
cmake_minimum_required(VERSION 3.30...3.31)
44

55
project(beman_execution26_tests LANGUAGES CXX)
66

77
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
88
message(FATAL_ERROR "In-source builds are not allowed!")
99
endif()
1010

11-
list(
12-
APPEND
13-
execution_tests
14-
execution-module.test
15-
stop-token-module.test
16-
)
11+
list(APPEND execution_tests execution-module.test stop-token-module.test)
1712

1813
list(
1914
APPEND
@@ -113,9 +108,10 @@ endif()
113108

114109
if(PROJECT_IS_TOP_LEVEL)
115110
enable_testing()
116-
find_package(beman_execution26 0.0.1 EXACT QUIET)
111+
find_package(beman_execution26 0.1.0 EXACT QUIET)
117112
if(beman_execution26_FOUND)
118-
set(execution_tests exec-awaitable.test) # only one sample to save time! CK
113+
set(execution_tests exec-awaitable.test) # only some samples to save time! CK
114+
list(APPEND execution_tests execution-module.test)
119115
else()
120116
add_subdirectory(../../.. beman_execution26)
121117

@@ -133,27 +129,24 @@ foreach(test ${execution_tests})
133129
add_test(NAME ${TEST_EXE} COMMAND $<TARGET_FILE:${TEST_EXE}>)
134130
endforeach()
135131

136-
if(FALSE)
137132
if(NOT PROJECT_IS_TOP_LEVEL)
138-
# test if the targets are findable from the build directory
133+
# test if the targets are findable from the install directory
139134
# cmake-format: off
140-
add_test(NAME find-package-test
141-
COMMAND ${CMAKE_CTEST_COMMAND}
142-
# --verbose
143-
--output-on-failure
144-
-C $<CONFIG>
145-
--build-and-test
146-
"${CMAKE_CURRENT_SOURCE_DIR}"
147-
"${CMAKE_CURRENT_BINARY_DIR}/find-package-test"
148-
--build-generator ${CMAKE_GENERATOR}
149-
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
150-
--build-options
151-
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
152-
"-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
153-
"-DCMAKE_BUILD_TYPE=$<CONFIG>"
154-
"-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}"
155-
# TODO(CK): Needed too? "--config $<CONFIG>"
156-
)
157-
# cmake-format: on
158-
endif()
135+
add_test(NAME find-package-test
136+
COMMAND ${CMAKE_CTEST_COMMAND}
137+
# --verbose
138+
--output-on-failure
139+
-C $<CONFIG>
140+
--build-and-test
141+
"${CMAKE_CURRENT_SOURCE_DIR}"
142+
"${CMAKE_CURRENT_BINARY_DIR}/find-package-test"
143+
--build-generator ${CMAKE_GENERATOR}
144+
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
145+
--build-options
146+
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
147+
"-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
148+
"-DCMAKE_BUILD_TYPE=$<CONFIG>"
149+
"-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}"
150+
)
151+
# cmake-format: on
159152
endif()

tests/beman/execution26/execution-module.test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#if 0
66
#include <beman/execution26/execution.hpp>
77
#else
8-
import beman.execution26;
8+
import beman_execution26;
99
#endif
1010

1111
// ----------------------------------------------------------------------------
@@ -172,8 +172,8 @@ TEST(execution_modules) {
172172

173173
// [exec.util.cmplsig.trans]
174174
//-dk:TODO template <typename S> using transform_completion_signatures =
175-
//test_stdex::transform_completion_signatures<S>; -dk:TODO template <typename S> using
176-
//transform_completion_signatures_of = test_stdex::transform_completion_signatures_of<S>;
175+
// test_stdex::transform_completion_signatures<S>; -dk:TODO template <typename S> using
176+
// transform_completion_signatures_of = test_stdex::transform_completion_signatures_of<S>;
177177

178178
// [exec.run.loop], run_loop
179179
test::use_type<test_stdex::run_loop>();
@@ -191,4 +191,4 @@ TEST(execution_modules) {
191191

192192
// [exec.with.awaitable.senders]
193193
//-dk:TODO test::use_template<test_stdex::with_awaitable_senders>();
194-
}
194+
}

0 commit comments

Comments
 (0)