Skip to content

Commit

Permalink
First step to install cxx_module (#92)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ClausKlein authored Nov 28, 2024
1 parent bdd2da2 commit 94f15a6
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 139 deletions.
25 changes: 2 additions & 23 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,7 @@ name: Linux Build

on:
push:
branches: ["main"]
paths:
- "include/**"
- "src/**"
- "tests/**"
- "examples/**"
- "cmake/**"
- "Makefile"
- "CMakePresets.json"
- "CMakeLists.txt"
- ".github/workflows/linux.yml"
pull_request:
branches: ["main"]
paths:
- "include/**"
- "src/**"
- "tests/**"
- "examples/**"
- "cmake/**"
- "Makefile"
- "CMakePresets.json"
- "CMakeLists.txt"
- ".github/workflows/linux.yml"

jobs:
build:
Expand All @@ -38,7 +16,8 @@ jobs:
matrix:
# TODO: sanitizer: [debug, release, asan, usan, tsan, lsan, msan]
preset: [debug, release]
compiler: [g++-14, clang++-19]
# TODO: compiler: [g++-15, clang++-19]
compiler: [clang++-19]

steps:
- uses: actions/checkout@v4
Expand Down
37 changes: 6 additions & 31 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,7 @@ name: Macos Build

on:
push:
branches: ["main"]
paths:
- "include/**"
- "src/**"
- "tests/**"
- "examples/**"
- "cmake/**"
- "Makefile"
- "CMakePresets.json"
- "CMakeLists.txt"
- ".github/workflows/macos.yml"
pull_request:
branches: ["main"]
paths:
- "include/**"
- "src/**"
- "tests/**"
- "examples/**"
- "cmake/**"
- "Makefile"
- "CMakePresets.json"
- "CMakeLists.txt"
- ".github/workflows/macos.yml"

jobs:
build:
Expand All @@ -37,8 +15,8 @@ jobs:

matrix:
preset: [debug, release]
# TODO: compiler: [g++, clang++-19]
compiler: [g++, clang++-18]
# TODO: compiler: [g++-15, clang++-19]
compiler: [clang++-19]

steps:
- uses: actions/checkout@v4
Expand All @@ -47,23 +25,20 @@ jobs:
# if: startsWith(matrix.compiler, 'clang')
uses: aminya/setup-cpp@v1
with:
# TODO: compiler: llvm-19
# clangtidy: true
# cmake: true
ninja: true

- name: Install llvm-19
if: startsWith(matrix.compiler, 'clang')
run: |
brew install llvm@19 || echo ignored
- name: macos clang++-18 ${{ matrix.preset }}
- name: macos clang++-19 ${{ matrix.preset }}
if: startsWith(matrix.compiler, 'clang')
run: CXX=$(brew --prefix llvm@18)/bin/clang++ cmake --workflow --preset ${{ matrix.preset }}
run: CXX=$(brew --prefix llvm@19)/bin/clang++ cmake --workflow --preset ${{ matrix.preset }}

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

- name: macos g++ ${{ matrix.preset }}
if: startsWith(matrix.compiler, 'g++')
Expand Down
20 changes: 0 additions & 20 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,7 @@ name: Windows Build

on:
push:
branches: ["main"]
paths:
- "include/**"
- "src/**"
- "tests/**"
- "examples/**"
- "cmake/**"
- "CMakePresets.json"
- "CMakeLists.txt"
- ".github/workflows/windows.yml"
pull_request:
branches: ["main"]
paths:
- "include/**"
- "src/**"
- "tests/**"
- "examples/**"
- "cmake/**"
- "CMakePresets.json"
- "CMakeLists.txt"
- ".github/workflows/windows.yml"

jobs:
build:
Expand Down
16 changes: 11 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# cmake-format: on

cmake_minimum_required(VERSION 3.25...3.31)
cmake_minimum_required(VERSION 3.30...3.31)

project(beman_execution26 VERSION 0.0.1 LANGUAGES CXX)
project(beman_execution26 VERSION 0.1.0 LANGUAGES CXX)

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

set(CMAKE_CXX_SCAN_FOR_MODULES ON)
# Note that scanning is only performed if C++20 or higher is enabled for the target. Scanning for modules in the target's
# sources belonging to file sets of type CXX_MODULES is always performed.
# not needed: set(CMAKE_CXX_SCAN_FOR_MODULES ON)

set(TARGET_NAME execution26)
set(TARGET_NAMESPACE beman) # FIXME: not used in install(EXPORT ...) CK?
set(TARGET_PREFIX ${TARGET_NAMESPACE}.${TARGET_NAME})
Expand All @@ -20,6 +23,9 @@ set(TARGET_ALIAS ${TARGET_LIBRARY}::${TARGET_LIBRARY})
set(TARGET_PACKAGE_NAME ${PROJECT_NAME}-config)
set(TARGETS_EXPORT_NAME ${PROJECT_NAME}-targets)

# This variable is a special case of the more-general CMAKE_<CONFIG>_POSTFIX variable for the DEBUG configuration.
set(CMAKE_DEBUG_POSTFIX D)

include(GNUInstallDirs)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})

Expand Down Expand Up @@ -56,7 +62,7 @@ if(CMAKE_BUILD_TYPE STREQUAL Debug)
ENABLE_SANITIZER_POINTER_COMPARE
ENABLE_SANITIZER_POINTER_SUBTRACT
ENABLE_CONTROL_FLOW_PROTECTION
ENABLE_STACK_PROTECTION
# XXX ENABLE_STACK_PROTECTION
ENABLE_OVERFLOW_PROTECTION
# ENABLE_ELF_PROTECTION
# ENABLE_RUNTIME_SYMBOLS_RESOLUTION
Expand Down Expand Up @@ -86,7 +92,7 @@ include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PACKAGE_NAME}-version.cmake
VERSION ${CMAKE_PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
COMPATIBILITY SameMajorVersion
)

configure_package_config_file(
Expand Down
2 changes: 1 addition & 1 deletion cmake/CMakeGenericPresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"type": "path",
"value": "${sourceDir}/stagedir"
},
"CMAKE_CXX_EXTENSIONS": false,
"CMAKE_CXX_EXTENSIONS": true,
"CMAKE_CXX_STANDARD": "23",
"CMAKE_CXX_STANDARD_REQUIRED": true,
"CMAKE_EXPORT_COMPILE_COMMANDS": true,
Expand Down
10 changes: 8 additions & 2 deletions examples/modules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@

// import std;
#include <iostream>
#include <string>
#if __cpp_modules < 201907L
#include <beman/execution26/execution.hpp>
#else
import beman.execution26;
import beman_execution26;
#endif

namespace ex = beman::execution26;

int main() {}
int main() {
auto [result] = ex::sync_wait(ex::when_all(ex::just(std::string("hello, ")), ex::just(std::string("world"))) |
ex::then([](const auto& s1, const auto& s2) { return s1 + s2; }))
.value_or(std::tuple(std::string("oops")));
std::cout << "result='" << result << "'\n";
}
32 changes: 13 additions & 19 deletions src/beman/execution26/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ add_library(${TARGET_LIBRARY} STATIC)
add_library(${TARGET_ALIAS} ALIAS ${TARGET_LIBRARY})

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

Expand Down Expand Up @@ -188,33 +189,26 @@ target_compile_features(${TARGET_LIBRARY} PUBLIC
)

target_sources(
beman_execution26
PUBLIC FILE_SET
beman_execution26 TYPE CXX_MODULES FILES execution.cpp
${TARGET_LIBRARY}
PUBLIC FILE_SET ${TARGET_LIBRARY}_modules
TYPE CXX_MODULES FILES execution.cppm
)

if(FALSE)
install(
TARGETS ${TARGET_LIBRARY}
EXPORT ${TARGETS_EXPORT_NAME}1
ARCHIVE DESTINATION lib/$<CONFIG>
EXPORT ${TARGETS_EXPORT_NAME}
ARCHIVE # XXX DESTINATION lib/$<CONFIG>
FILE_SET ${TARGET_LIBRARY}_modules
# There's currently no convention for this location
DESTINATION ${INSTALL_CONFIGDIR}/src
FILE_SET ${TARGET_LIBRARY}_public_headers
FILE_SET ${TARGET_LIBRARY}_detail_headers
)

install(
EXPORT ${TARGETS_EXPORT_NAME}1
FILE ${TARGETS_EXPORT_NAME}.cmake
EXPORT ${TARGETS_EXPORT_NAME}
DESTINATION "${INSTALL_CONFIGDIR}"
CXX_MODULES_DIRECTORY .
NAMESPACE ${TARGET_LIBRARY}::
)

#-dk:TODO build/default/src/beman/execution26/CMakeFiles/beman_execution26.dir/beman.execution26.pcm
install(
TARGETS beman_execution26
EXPORT beman_execution26
COMPONENT FILE_SET beman_execution26
DESTINATION lib/beman/execution26
)
endif()
# cmake-format: on
# cmake-format: on
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module;
#include <beman/execution26/execution.hpp>
#include <beman/execution26/stop_token.hpp>

export module beman.execution26;
export module beman_execution26;

namespace beman::execution26 {
export int version(0);
Expand Down
53 changes: 23 additions & 30 deletions tests/beman/execution26/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
# src/beman/execution26/tests/CMakeLists.txt
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required(VERSION 3.25...3.31)
cmake_minimum_required(VERSION 3.30...3.31)

project(beman_execution26_tests LANGUAGES CXX)

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

list(
APPEND
execution_tests
execution-module.test
stop-token-module.test
)
list(APPEND execution_tests execution-module.test stop-token-module.test)

list(
APPEND
Expand Down Expand Up @@ -113,9 +108,10 @@ endif()

if(PROJECT_IS_TOP_LEVEL)
enable_testing()
find_package(beman_execution26 0.0.1 EXACT QUIET)
find_package(beman_execution26 0.1.0 EXACT QUIET)
if(beman_execution26_FOUND)
set(execution_tests exec-awaitable.test) # only one sample to save time! CK
set(execution_tests exec-awaitable.test) # only some samples to save time! CK
list(APPEND execution_tests execution-module.test)
else()
add_subdirectory(../../.. beman_execution26)

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

if(FALSE)
if(NOT PROJECT_IS_TOP_LEVEL)
# test if the targets are findable from the build directory
# test if the targets are findable from the install directory
# cmake-format: off
add_test(NAME find-package-test
COMMAND ${CMAKE_CTEST_COMMAND}
# --verbose
--output-on-failure
-C $<CONFIG>
--build-and-test
"${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_BINARY_DIR}/find-package-test"
--build-generator ${CMAKE_GENERATOR}
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
--build-options
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
"-DCMAKE_BUILD_TYPE=$<CONFIG>"
"-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}"
# TODO(CK): Needed too? "--config $<CONFIG>"
)
# cmake-format: on
endif()
add_test(NAME find-package-test
COMMAND ${CMAKE_CTEST_COMMAND}
# --verbose
--output-on-failure
-C $<CONFIG>
--build-and-test
"${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_BINARY_DIR}/find-package-test"
--build-generator ${CMAKE_GENERATOR}
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
--build-options
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
"-DCMAKE_BUILD_TYPE=$<CONFIG>"
"-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}"
)
# cmake-format: on
endif()
8 changes: 4 additions & 4 deletions tests/beman/execution26/execution-module.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#if 0
#include <beman/execution26/execution.hpp>
#else
import beman.execution26;
import beman_execution26;
#endif

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -172,8 +172,8 @@ TEST(execution_modules) {

// [exec.util.cmplsig.trans]
//-dk:TODO template <typename S> using transform_completion_signatures =
//test_stdex::transform_completion_signatures<S>; -dk:TODO template <typename S> using
//transform_completion_signatures_of = test_stdex::transform_completion_signatures_of<S>;
// test_stdex::transform_completion_signatures<S>; -dk:TODO template <typename S> using
// transform_completion_signatures_of = test_stdex::transform_completion_signatures_of<S>;

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

// [exec.with.awaitable.senders]
//-dk:TODO test::use_template<test_stdex::with_awaitable_senders>();
}
}
2 changes: 1 addition & 1 deletion tests/beman/execution26/include/test/execution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace beman::execution26 {}

namespace beman::execution26::detail {};
namespace beman::execution26::detail {}

namespace test_std = ::beman::execution26;
namespace test_stdex = ::beman::execution26;
Expand Down
Loading

0 comments on commit 94f15a6

Please sign in to comment.