From 828cb17f179632cf9320ff5b996a730320e55b96 Mon Sep 17 00:00:00 2001 From: Darius Neatu Date: Sat, 29 Jun 2024 01:28:35 +0300 Subject: [PATCH 01/20] Split build production vs testing --- .github/workflows/ci.yml | 2 +- .gitmodules | 3 --- CMakeLists.txt | 18 +++++++++++++++--- CMakePresets.json | 10 +++++++++- extern/CMakeLists.txt | 6 ------ extern/googletest | 1 - src/Beman/Optional26/CMakeLists.txt | 21 +++------------------ src/Beman/Optional26/tests/CMakeLists.txt | 22 ++++++++++++++++++++++ 8 files changed, 50 insertions(+), 33 deletions(-) delete mode 100644 extern/CMakeLists.txt delete mode 160000 extern/googletest create mode 100644 src/Beman/Optional26/tests/CMakeLists.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68bd07bb..a14260bb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,7 +66,7 @@ jobs: cd .build echo ${{ matrix.config.cmake_args }} echo ${{ matrix.config.toolchain }} - cmake ${{ matrix.config.cmake_args }} -DCMAKE_TOOLCHAIN_FILE=etc/${{ matrix.config.toolchain }} -B . -S .. + cmake ${{ matrix.config.cmake_args }} -DCMAKE_TOOLCHAIN_FILE=etc/${{ matrix.config.toolchain }} -DCMAKE_BUILD_TESTS=true -B . -S .. - name: Build run: | set -x diff --git a/.gitmodules b/.gitmodules index 9c4e4556..b44d8c09 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "papers/wg21"] path = papers/P2988/wg21 url = https://github.com/mpark/wg21.git -[submodule "extern/googletest"] - path = extern/googletest - url = https://github.com/google/googletest.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 564e9d76..b2647469 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,18 +3,30 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # cmake-format: on -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.27) project( beman_optional26 VERSION 0.0.0 LANGUAGES CXX) -enable_testing() +cmake_policy(VERSION 3.27) set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}Targets) -add_subdirectory(extern) +if("${CMAKE_BUILD_TESTS}") + enable_testing() + + # Fetch GoogleTest + include(FetchContent) + FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG f8d7d77c06936315286eb55f8de22cd23c188571 # release-1.14.0 + ) + FetchContent_MakeAvailable(googletest) +endif() + add_subdirectory(src) add_subdirectory(examples) diff --git a/CMakePresets.json b/CMakePresets.json index 40cb22a2..3f0b39f9 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -14,7 +14,8 @@ "binaryDir": "${sourceDir}/.build/${presetName}", "installDir": "${sourceDir}/.install/${presetName}", "cacheVariables": { - "CMAKE_CONFIGURATION_TYPES": "RelWithDebInfo;Debug;Tsan;Asan" + "CMAKE_CONFIGURATION_TYPES": "RelWithDebInfo;Debug;Tsan;Asan", + "CMAKE_BUILD_TESTS": true } }, { @@ -68,26 +69,32 @@ }, { "name": "system", + "inherits": "common", "configurePreset": "system" }, { "name": "gcc-14", + "inherits": "common", "configurePreset": "gcc-14" }, { "name": "gcc-13", + "inherits": "common", "configurePreset": "gcc-13" }, { "name": "clang-19", + "inherits": "common", "configurePreset": "clang-19" }, { "name": "clang-18", + "inherits": "common", "configurePreset": "clang-18" }, { "name": "clang-17", + "inherits": "common", "configurePreset": "clang-17" } ], @@ -95,6 +102,7 @@ { "name": "common", "hidden": true, + "configuration": "Asan", "output": { "outputOnFailure": true }, diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt deleted file mode 100644 index 31f2a6fc..00000000 --- a/extern/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -# cmake-format: off -# extern/CMakeLists.txt -*-makefile-*- -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# cmake-format: on - -add_subdirectory(googletest EXCLUDE_FROM_ALL) diff --git a/extern/googletest b/extern/googletest deleted file mode 160000 index 305e5a23..00000000 --- a/extern/googletest +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 305e5a238b3c8d11266fbafd85520fb6b3184851 diff --git a/src/Beman/Optional26/CMakeLists.txt b/src/Beman/Optional26/CMakeLists.txt index 9cdd38ac..28393cbe 100644 --- a/src/Beman/Optional26/CMakeLists.txt +++ b/src/Beman/Optional26/CMakeLists.txt @@ -35,21 +35,6 @@ install( target_link_libraries("${TARGET_LIBRARY}") # Tests -add_executable(optional_test "") - -target_sources( - optional_test - PRIVATE tests/optional.t.cpp tests/optional_ref.t.cpp - tests/optional_monadic.t.cpp tests/optional_range_support.t.cpp - tests/optional_ref_monadic.t.cpp tests/detail/iterator.t.cpp) - -target_link_libraries(optional_test "${TARGET_LIBRARY}") -target_link_libraries(optional_test gtest) -target_link_libraries(optional_test gtest_main) - -include(GoogleTest) - -# Note: clang-19 + gtest_discover_tests + Asan setup causes errors on some platforms. -# Temporary switch to gtest_add_tests and skip some Asan checks. -enable_testing() -gtest_add_tests(optional_test "" AUTO) +if("${CMAKE_BUILD_TESTS}") + add_subdirectory(tests) +endif() diff --git a/src/Beman/Optional26/tests/CMakeLists.txt b/src/Beman/Optional26/tests/CMakeLists.txt new file mode 100644 index 00000000..47df9168 --- /dev/null +++ b/src/Beman/Optional26/tests/CMakeLists.txt @@ -0,0 +1,22 @@ +# cmake-format: off +# src/Beman/Optional26/tests/CMakeLists.txt -*-makefile-*- +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# cmake-format: on + +# Tests +add_executable(optional_test "") + +target_sources( + optional_test + PRIVATE optional.t.cpp optional_ref.t.cpp + optional_monadic.t.cpp optional_range_support.t.cpp + optional_ref_monadic.t.cpp detail/iterator.t.cpp) + +target_link_libraries(optional_test "${TARGET_LIBRARY}" GTest::gtest GTest::gtest_main) + +include(GoogleTest) + +# Note: clang-19 + gtest_discover_tests + Asan setup causes errors on some platforms. +# Temporary switch to gtest_add_tests and skip some Asan checks. +enable_testing() +gtest_add_tests(optional_test "" AUTO) From 5df2e7ec9998ccdb40785c0c9725fdd59a9c73a4 Mon Sep 17 00:00:00 2001 From: Darius Neatu Date: Mon, 15 Jul 2024 20:10:25 +0300 Subject: [PATCH 02/20] Cleanup in CMakeLists.txt --- CMakeLists.txt | 2 +- src/Beman/Optional26/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b2647469..9503ab7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ cmake_policy(VERSION 3.27) set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}Targets) -if("${CMAKE_BUILD_TESTS}") +if(${CMAKE_BUILD_TESTS}) enable_testing() # Fetch GoogleTest diff --git a/src/Beman/Optional26/CMakeLists.txt b/src/Beman/Optional26/CMakeLists.txt index 28393cbe..d6771d72 100644 --- a/src/Beman/Optional26/CMakeLists.txt +++ b/src/Beman/Optional26/CMakeLists.txt @@ -35,6 +35,6 @@ install( target_link_libraries("${TARGET_LIBRARY}") # Tests -if("${CMAKE_BUILD_TESTS}") +if(${CMAKE_BUILD_TESTS}) add_subdirectory(tests) endif() From 51ef49e935b96f7ba2ff285a35fec2b00348733f Mon Sep 17 00:00:00 2001 From: Darius Neatu Date: Mon, 15 Jul 2024 20:19:04 +0300 Subject: [PATCH 03/20] Switch to conditional cmake BUILD_TESTING --- .github/workflows/ci.yml | 2 +- CMakeLists.txt | 6 +++++- CMakePresets.json | 3 +-- src/Beman/Optional26/CMakeLists.txt | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a14260bb..68bd07bb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,7 +66,7 @@ jobs: cd .build echo ${{ matrix.config.cmake_args }} echo ${{ matrix.config.toolchain }} - cmake ${{ matrix.config.cmake_args }} -DCMAKE_TOOLCHAIN_FILE=etc/${{ matrix.config.toolchain }} -DCMAKE_BUILD_TESTS=true -B . -S .. + cmake ${{ matrix.config.cmake_args }} -DCMAKE_TOOLCHAIN_FILE=etc/${{ matrix.config.toolchain }} -B . -S .. - name: Build run: | set -x diff --git a/CMakeLists.txt b/CMakeLists.txt index 9503ab7a..032a35a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,11 @@ cmake_policy(VERSION 3.27) set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}Targets) -if(${CMAKE_BUILD_TESTS}) +# Include the CTest module. +include(CTest) + +# Build the tests only if enabled via the CLI flag: BUILD_TESTING. +if(BUILD_TESTING) enable_testing() # Fetch GoogleTest diff --git a/CMakePresets.json b/CMakePresets.json index 3f0b39f9..eb05f0c9 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -14,8 +14,7 @@ "binaryDir": "${sourceDir}/.build/${presetName}", "installDir": "${sourceDir}/.install/${presetName}", "cacheVariables": { - "CMAKE_CONFIGURATION_TYPES": "RelWithDebInfo;Debug;Tsan;Asan", - "CMAKE_BUILD_TESTS": true + "CMAKE_CONFIGURATION_TYPES": "RelWithDebInfo;Debug;Tsan;Asan" } }, { diff --git a/src/Beman/Optional26/CMakeLists.txt b/src/Beman/Optional26/CMakeLists.txt index d6771d72..ff94803a 100644 --- a/src/Beman/Optional26/CMakeLists.txt +++ b/src/Beman/Optional26/CMakeLists.txt @@ -35,6 +35,6 @@ install( target_link_libraries("${TARGET_LIBRARY}") # Tests -if(${CMAKE_BUILD_TESTS}) +if(BUILD_TESTING) add_subdirectory(tests) endif() From ceb96474d910dc4884627dbc2b4c71a1f2704f3b Mon Sep 17 00:00:00 2001 From: Darius Neatu Date: Mon, 15 Jul 2024 20:24:52 +0300 Subject: [PATCH 04/20] Simplify tree: avoid CMakeLists.txt files which simply passes control to other subdirectory --- CMakeLists.txt | 2 +- src/Beman/CMakeLists.txt | 6 ------ src/CMakeLists.txt | 6 ------ 3 files changed, 1 insertion(+), 13 deletions(-) delete mode 100644 src/Beman/CMakeLists.txt delete mode 100644 src/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 032a35a9..37cd9c12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,7 @@ if(BUILD_TESTING) FetchContent_MakeAvailable(googletest) endif() -add_subdirectory(src) +add_subdirectory(src/Beman/Optional26) add_subdirectory(examples) include(GNUInstallDirs) diff --git a/src/Beman/CMakeLists.txt b/src/Beman/CMakeLists.txt deleted file mode 100644 index 45dfa2b8..00000000 --- a/src/Beman/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -# cmake-format: off -# src/Beman/CMakeLists.txt -*-makefile-*- -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# cmake-format: on - -add_subdirectory(Optional26) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt deleted file mode 100644 index 5d1346f1..00000000 --- a/src/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -# cmake-format: off -# src/CMakeLists.txt -*-makefile-*- -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# cmake-format: on - -add_subdirectory(Beman) From 0113c157f69e02a434a28b14cb88aa9a297397a7 Mon Sep 17 00:00:00 2001 From: Darius Neatu Date: Mon, 15 Jul 2024 21:17:21 +0300 Subject: [PATCH 05/20] Remove warnings from CI --- .github/workflows/ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68bd07bb..eebd6252 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,12 +12,12 @@ jobs: fail-fast: false matrix: config: - - {name: "Ubuntu Clang 17", os: ubuntu-24.04, toolchain: "clang-17-toolchain.cmake", clang_version: 17, installed_clang_version: 14, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" "} - - {name: "Ubuntu Clang 18", os: ubuntu-24.04, toolchain: "clang-18-toolchain.cmake", clang_version: 18, installed_clang_version: 14, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" "} + - {name: "Ubuntu Clang 17", os: ubuntu-24.04, toolchain: "clang-17-toolchain.cmake", clang_version: 17, installed_clang_version: 17, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" "} + - {name: "Ubuntu Clang 18", os: ubuntu-24.04, toolchain: "clang-18-toolchain.cmake", clang_version: 18, installed_clang_version: 17, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" "} # Note: clang-19 + Asan setup causes errors on some platforms. Temporary skip some checks via .asan_options. - - {name: "Ubuntu Clang 19", os: ubuntu-24.04, toolchain: "clang-19-toolchain.cmake", clang_version: 19, installed_clang_version: 14, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" ", asan_options: "new_delete_type_mismatch=0"} - - {name: "Ubuntu GCC 13", os: ubuntu-24.04, toolchain: "gcc-13-toolchain.cmake", clang_version: 17, installed_clang_version: 14, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" "} - - {name: "Ubuntu GCC 14", os: ubuntu-24.04, toolchain: "gcc-14-toolchain.cmake", clang_version: 17, installed_clang_version: 14, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" "} + - {name: "Ubuntu Clang 19", os: ubuntu-24.04, toolchain: "clang-19-toolchain.cmake", clang_version: 19, installed_clang_version: 17, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" ", asan_options: "new_delete_type_mismatch=0"} + - {name: "Ubuntu GCC 13", os: ubuntu-24.04, toolchain: "gcc-13-toolchain.cmake", clang_version: 17, installed_clang_version: 17, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" "} + - {name: "Ubuntu GCC 14", os: ubuntu-24.04, toolchain: "gcc-14-toolchain.cmake", clang_version: 17, installed_clang_version: 17, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" "} steps: - uses: actions/checkout@v3 with: From d680da6915a4fd94bd7d79fb8b60e74234b083f3 Mon Sep 17 00:00:00 2001 From: Darius Neatu Date: Mon, 15 Jul 2024 23:14:29 +0300 Subject: [PATCH 06/20] Remove unused cmake enable_testing --- CMakeLists.txt | 2 -- src/Beman/Optional26/tests/CMakeLists.txt | 1 - 2 files changed, 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 37cd9c12..7653c826 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,8 +19,6 @@ include(CTest) # Build the tests only if enabled via the CLI flag: BUILD_TESTING. if(BUILD_TESTING) - enable_testing() - # Fetch GoogleTest include(FetchContent) FetchContent_Declare( diff --git a/src/Beman/Optional26/tests/CMakeLists.txt b/src/Beman/Optional26/tests/CMakeLists.txt index 47df9168..15673d71 100644 --- a/src/Beman/Optional26/tests/CMakeLists.txt +++ b/src/Beman/Optional26/tests/CMakeLists.txt @@ -18,5 +18,4 @@ include(GoogleTest) # Note: clang-19 + gtest_discover_tests + Asan setup causes errors on some platforms. # Temporary switch to gtest_add_tests and skip some Asan checks. -enable_testing() gtest_add_tests(optional_test "" AUTO) From 7b4486604dc3f62e0400e77ef64121d236130d4d Mon Sep 17 00:00:00 2001 From: Darius Neatu Date: Mon, 15 Jul 2024 23:15:35 +0300 Subject: [PATCH 07/20] Simplify root CMakeLists.txt --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7653c826..15cad5d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,13 +14,13 @@ cmake_policy(VERSION 3.27) set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}Targets) -# Include the CTest module. +# Includes include(CTest) +include(FetchContent) # Build the tests only if enabled via the CLI flag: BUILD_TESTING. if(BUILD_TESTING) # Fetch GoogleTest - include(FetchContent) FetchContent_Declare( googletest GIT_REPOSITORY https://github.com/google/googletest.git From 05f2788d133e76d7c39871f5baad3cec670100bf Mon Sep 17 00:00:00 2001 From: Darius Neatu Date: Mon, 15 Jul 2024 23:18:12 +0300 Subject: [PATCH 08/20] Simplify tests CMakeLists.txt --- src/Beman/Optional26/tests/CMakeLists.txt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Beman/Optional26/tests/CMakeLists.txt b/src/Beman/Optional26/tests/CMakeLists.txt index 15673d71..e88a9f51 100644 --- a/src/Beman/Optional26/tests/CMakeLists.txt +++ b/src/Beman/Optional26/tests/CMakeLists.txt @@ -3,19 +3,20 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # cmake-format: on -# Tests -add_executable(optional_test "") +include(GoogleTest) -target_sources( - optional_test - PRIVATE optional.t.cpp optional_ref.t.cpp - optional_monadic.t.cpp optional_range_support.t.cpp - optional_ref_monadic.t.cpp detail/iterator.t.cpp) +# Tests +add_executable(optional_test + optional.t.cpp + optional_ref.t.cpp + optional_monadic.t.cpp + optional_range_support.t.cpp + optional_ref_monadic.t.cpp + detail/iterator.t.cpp +) target_link_libraries(optional_test "${TARGET_LIBRARY}" GTest::gtest GTest::gtest_main) -include(GoogleTest) - # Note: clang-19 + gtest_discover_tests + Asan setup causes errors on some platforms. # Temporary switch to gtest_add_tests and skip some Asan checks. gtest_add_tests(optional_test "" AUTO) From d99381e9e5198aef48889e473249f7f5f4565a90 Mon Sep 17 00:00:00 2001 From: Darius Neatu Date: Mon, 15 Jul 2024 23:23:48 +0300 Subject: [PATCH 09/20] Improve naming for target library in CMakeLists.txt --- src/Beman/Optional26/CMakeLists.txt | 12 +++++------- src/Beman/Optional26/tests/CMakeLists.txt | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Beman/Optional26/CMakeLists.txt b/src/Beman/Optional26/CMakeLists.txt index ff94803a..d44bcd36 100644 --- a/src/Beman/Optional26/CMakeLists.txt +++ b/src/Beman/Optional26/CMakeLists.txt @@ -3,24 +3,22 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # cmake-format: on -set(TARGET_LIBRARY "beman_optional26") +add_library(beman_optional26 STATIC "") -add_library("${TARGET_LIBRARY}" STATIC "") - -target_sources("${TARGET_LIBRARY}" PRIVATE optional.cpp detail/iterator.cpp) +target_sources(beman_optional26 PRIVATE optional.cpp detail/iterator.cpp) include(GNUInstallDirs) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories( - "${TARGET_LIBRARY}" + beman_optional26 PUBLIC $ $ # /include/scratch ) install( - TARGETS "${TARGET_LIBRARY}" + TARGETS beman_optional26 EXPORT ${TARGETS_EXPORT_NAME}1 DESTINATION ${CMAKE_INSTALL_LIBDIR}) @@ -32,7 +30,7 @@ install( FILES_MATCHING PATTERN "*.hpp") -target_link_libraries("${TARGET_LIBRARY}") +target_link_libraries(beman_optional26) # Tests if(BUILD_TESTING) diff --git a/src/Beman/Optional26/tests/CMakeLists.txt b/src/Beman/Optional26/tests/CMakeLists.txt index e88a9f51..2fc778f7 100644 --- a/src/Beman/Optional26/tests/CMakeLists.txt +++ b/src/Beman/Optional26/tests/CMakeLists.txt @@ -15,7 +15,7 @@ add_executable(optional_test detail/iterator.t.cpp ) -target_link_libraries(optional_test "${TARGET_LIBRARY}" GTest::gtest GTest::gtest_main) +target_link_libraries(optional_test beman_optional26 GTest::gtest GTest::gtest_main) # Note: clang-19 + gtest_discover_tests + Asan setup causes errors on some platforms. # Temporary switch to gtest_add_tests and skip some Asan checks. From 03f85a45a88e4040082cd174befcf183615cde5f Mon Sep 17 00:00:00 2001 From: Darius Neatu Date: Tue, 16 Jul 2024 08:38:57 +0300 Subject: [PATCH 10/20] Link issue --- src/Beman/Optional26/tests/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Beman/Optional26/tests/CMakeLists.txt b/src/Beman/Optional26/tests/CMakeLists.txt index 2fc778f7..b47def96 100644 --- a/src/Beman/Optional26/tests/CMakeLists.txt +++ b/src/Beman/Optional26/tests/CMakeLists.txt @@ -17,6 +17,7 @@ add_executable(optional_test target_link_libraries(optional_test beman_optional26 GTest::gtest GTest::gtest_main) +# Issue #32: Re-enable ASAN run CI/clang-19 # Note: clang-19 + gtest_discover_tests + Asan setup causes errors on some platforms. -# Temporary switch to gtest_add_tests and skip some Asan checks. +# Temporary switch to gtest_add_tests and skip some Asan checks. Change also applied for CI flows. gtest_add_tests(optional_test "" AUTO) From 49dd45ae4f61e2c37eb13c40f85de220a0855428 Mon Sep 17 00:00:00 2001 From: Darius Neatu Date: Tue, 16 Jul 2024 08:44:24 +0300 Subject: [PATCH 11/20] More tweaks for bulding --- CMakeLists.txt | 6 ++---- src/Beman/Optional26/CMakeLists.txt | 7 ++++--- src/Beman/Optional26/tests/CMakeLists.txt | 11 +++++++++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 15cad5d6..2187dbfc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,14 +10,12 @@ project( VERSION 0.0.0 LANGUAGES CXX) -cmake_policy(VERSION 3.27) - -set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}Targets) - # Includes include(CTest) include(FetchContent) +set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}Targets) + # Build the tests only if enabled via the CLI flag: BUILD_TESTING. if(BUILD_TESTING) # Fetch GoogleTest diff --git a/src/Beman/Optional26/CMakeLists.txt b/src/Beman/Optional26/CMakeLists.txt index d44bcd36..4f2e9612 100644 --- a/src/Beman/Optional26/CMakeLists.txt +++ b/src/Beman/Optional26/CMakeLists.txt @@ -3,9 +3,10 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # cmake-format: on -add_library(beman_optional26 STATIC "") - -target_sources(beman_optional26 PRIVATE optional.cpp detail/iterator.cpp) +add_library(beman_optional26 STATIC + optional.cpp + detail/iterator.cpp +) include(GNUInstallDirs) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/Beman/Optional26/tests/CMakeLists.txt b/src/Beman/Optional26/tests/CMakeLists.txt index b47def96..91c757fb 100644 --- a/src/Beman/Optional26/tests/CMakeLists.txt +++ b/src/Beman/Optional26/tests/CMakeLists.txt @@ -15,9 +15,16 @@ add_executable(optional_test detail/iterator.t.cpp ) -target_link_libraries(optional_test beman_optional26 GTest::gtest GTest::gtest_main) +target_link_libraries(optional_test + beman_optional26 + GTest::gtest + GTest::gtest_main +) # Issue #32: Re-enable ASAN run CI/clang-19 # Note: clang-19 + gtest_discover_tests + Asan setup causes errors on some platforms. # Temporary switch to gtest_add_tests and skip some Asan checks. Change also applied for CI flows. -gtest_add_tests(optional_test "" AUTO) +gtest_add_tests(TARGET optional_test + "" + AUTO +) From 3905061c58cc0e151c75d1a30acd6b0c8e6401f7 Mon Sep 17 00:00:00 2001 From: Darius Neatu Date: Tue, 16 Jul 2024 09:45:51 +0300 Subject: [PATCH 12/20] Addd build instructions --- README.md | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bddf6e49..6ce794e0 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,26 @@ This repository implements `std::optional` extensions targeting C++26. The `Bema * [Give *std::optional* Range Support (P3168R2)](https://wg21.link/P3168R2) * [`std::optional` (P2988R5)](https://wg21.link/P2988R5) + +## Table of Contents + +- [Beman.Optional26: C++26 Extensions for std::optional](#bemanoptional26-c26-extensions-for-stdoptional) + - [Table of Contents](#table-of-contents) + - [License](#license) + - [Examples](#examples) + - [range\_loop](#range_loop) + - [optional\_ref](#optional_ref) + - [How to Build](#how-to-build) + - [Compiler Support](#compiler-support) + - [Dependencies](#dependencies) + - [Instructions](#instructions) + - [Default Build and Test Flow](#default-build-and-test-flow) + - [More Complex Cases](#more-complex-cases) + - [Step by Step Build: Build and Run Tests](#step-by-step-build-build-and-run-tests) + - [Step by Step Build: Build Production and Skip Tests](#step-by-step-build-build-production-and-skip-tests) + - [Papers](#papers) + + ## License Source is licensed with the Apache 2.0 license with LLVM exceptions @@ -123,7 +143,7 @@ apt-get install \ Full set of supported toolchains can be found in [.github/workflows/ci.yml](.github/workflows/ci.yml). -#### Basic Build +#### Default Build and Test Flow This project strives to be as normal and simple a CMake project as possible. This build workflow in particular will work, producing a static `beman_optional26` library, ready to package: @@ -168,7 +188,7 @@ Total Test time (real) = 0.09 sec This should build and run the tests with GCC 14 with the address and undefined behavior sanitizers enabled. -#### More complex cases +#### More Complex Cases The CMake preset system suffers from combinitorial explosion. There is a makefile in the root of the repository to aid in running more configurations. @@ -178,6 +198,63 @@ make -k TOOLCHAIN=clang-18 CONFIG=Tsan VERBOSE=1 The makefile will use your system compiler, `c++`, if no toolchain name is provided, otherwise it will use the toolchain in the etc/ directory to perform the build. The Ninja multi config generator is used, with configurations for `RelWithDebugInfo`, `Debug`, `Tsan`, and `Asan` configured by default. +#### Step by Step Build: Build and Run Tests + +CI current build and test flows: + +```shell +# Configure build: default build production code + tests (BUILD_TESTING=ON by default). +$ rm -rf .build/ +$ mkdir -p .build +$ cd .build +$ cmake -G "Ninja Multi-Config" -DCMAKE_CONFIGURATION_TYPES="RelWithDebInfo;Asan" -DCMAKE_TOOLCHAIN_FILE=etc/clang-19-toolchain.cmake -B . -S .. +-- The CXX compiler identification is Clang 19.0.0 +... +-- Build files have been written to: /home/dariusn/git/Beman/Beman.Optional26/.build + +# Build. +$ cd .. +$ cmake --build .build --config Asan --target all -- -k 0 +... +[30/30] Linking CXX executable examples/Asan/sample + +# Run tests. +$ cd .build +$ ctest --build-config Asan --output-on-failure +Test project /home/dariusn/git/Beman/Beman.Optional26/.build +... +100% tests passed, 0 tests failed out of 82 + +Total Test time (real) = 0.67 sec +``` + +#### Step by Step Build: Build Production and Skip Tests + +By default, we build and run tests. You can provide `-DBUILD_TESTING=OFF` and completely disable building tests: + +```shell +# Configure build: build production code, skip tests (BUILD_TESTING=OFF). +$ rm -rf .build/ +$ mkdir -p .build +$ cd .build +$ cmake -G "Ninja Multi-Config" -DCMAKE_CONFIGURATION_TYPES="RelWithDebInfo;Asan" -DCMAKE_TOOLCHAIN_FILE=etc/clang-19-toolchain.cmake -DBUILD_TESTING=OFF -B . -S .. +-- The CXX compiler identification is Clang 19.0.0 +... +-- Build files have been written to: /home/dariusn/git/Beman/Beman.Optional26/.build + +# Build. +$ cd .. +$ cmake --build .build --config Asan --target all -- -k 0 +... +[15/15] Linking CXX executable examples/Asan/sample + +# Check that tests are not built/installed. +$ cd .build +$ ctest --build-config Asan --output-on-failure +Test project /home/dariusn/git/Beman/Beman.Optional26/.build +No tests were found!!! +``` + ## Papers Latest revision(s) of the papers can be built / found at: From 0282cd52b45ce94d49a955106f6e4af93c45e33c Mon Sep 17 00:00:00 2001 From: Darius Neatu Date: Tue, 16 Jul 2024 13:23:56 +0300 Subject: [PATCH 13/20] Skip Clang install for GCC target setups --- .github/workflows/ci.yml | 37 ++++++++----- Ubuntu-24.04.Dockerfile | 114 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+), 13 deletions(-) create mode 100644 Ubuntu-24.04.Dockerfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eebd6252..66193455 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,12 +12,12 @@ jobs: fail-fast: false matrix: config: - - {name: "Ubuntu Clang 17", os: ubuntu-24.04, toolchain: "clang-17-toolchain.cmake", clang_version: 17, installed_clang_version: 17, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" "} - - {name: "Ubuntu Clang 18", os: ubuntu-24.04, toolchain: "clang-18-toolchain.cmake", clang_version: 18, installed_clang_version: 17, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" "} + - {name: "Ubuntu Clang 17", os: ubuntu-24.04, toolchain: "clang-17", clang_version: 17, installed_clang_version: 17, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" "} + - {name: "Ubuntu Clang 18", os: ubuntu-24.04, toolchain: "clang-18", clang_version: 18, installed_clang_version: 17, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" "} # Note: clang-19 + Asan setup causes errors on some platforms. Temporary skip some checks via .asan_options. - - {name: "Ubuntu Clang 19", os: ubuntu-24.04, toolchain: "clang-19-toolchain.cmake", clang_version: 19, installed_clang_version: 17, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" ", asan_options: "new_delete_type_mismatch=0"} - - {name: "Ubuntu GCC 13", os: ubuntu-24.04, toolchain: "gcc-13-toolchain.cmake", clang_version: 17, installed_clang_version: 17, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" "} - - {name: "Ubuntu GCC 14", os: ubuntu-24.04, toolchain: "gcc-14-toolchain.cmake", clang_version: 17, installed_clang_version: 17, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" "} + - {name: "Ubuntu Clang 19", os: ubuntu-24.04, toolchain: "clang-19", clang_version: 19, installed_clang_version: 17, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" ", asan_options: "new_delete_type_mismatch=0"} + - {name: "Ubuntu GCC 13", os: ubuntu-24.04, toolchain: "gcc-13", cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" "} + - {name: "Ubuntu GCC 14", os: ubuntu-24.04, toolchain: "gcc-14", cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" "} steps: - uses: actions/checkout@v3 with: @@ -26,10 +26,11 @@ jobs: - name: Activate verbose shell run: set -x - name: Install LLVM+Clang - if: startsWith(matrix.config.os, 'ubuntu-') + if: startsWith(matrix.config.name, 'Ubuntu Clang') run: | set -x cat /etc/lsb-release + # Remove existing Clang installations. sudo apt-get remove clang-${{matrix.config.installed_clang_version}} \ lldb-${{matrix.config.installed_clang_version}} \ lld-${{matrix.config.installed_clang_version}} \ @@ -48,17 +49,27 @@ jobs: libclang-${{matrix.config.installed_clang_version}}-dev \ libclang-cpp${{matrix.config.installed_clang_version}}-dev \ libunwind-${{matrix.config.installed_clang_version}}-dev + # Install LLVM+Clang. wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh sudo ./llvm.sh ${{matrix.config.clang_version}} all sudo apt-get install libc++-dev libc++1 libc++abi-dev libc++abi1 - - name: Install GCC 14 - if: matrix.config.name == 'Ubuntu GCC 14' + find /usr/lib -name libc++.so* + ${{matrix.config.toolchain}} --version + - name: Install GCC + if: startsWith(matrix.config.name, 'Ubuntu GCC') run: | set -x + # Remove existing GCC installations. + sudo apt-get remove gcc-13 g++-13 gcc-14 g++-14 gcc g++ sudo apt update - sudo apt-get install g++-14 - - name: Configure + # Install GCC. + GCC_VERSION=$(echo ${{matrix.config.toolchain}} | cut -d '-' -f2) + echo "GCC_VERSION=$GCC_VERSION" + sudo apt-get install g++-${GCC_VERSION} gcc-${GCC_VERSION} + find /usr/lib -name libstdc++.so* + ${{matrix.config.toolchain}} --version + - name: CMake Configure run: | set -x rm -rf .build @@ -66,12 +77,12 @@ jobs: cd .build echo ${{ matrix.config.cmake_args }} echo ${{ matrix.config.toolchain }} - cmake ${{ matrix.config.cmake_args }} -DCMAKE_TOOLCHAIN_FILE=etc/${{ matrix.config.toolchain }} -B . -S .. - - name: Build + cmake ${{ matrix.config.cmake_args }} -DCMAKE_TOOLCHAIN_FILE="etc/${{ matrix.config.toolchain }}-toolchain.cmake" -B . -S .. + - name: CMake Build run: | set -x cmake --build .build --config Asan --target all -- -k 0 - - name: Test + - name: CTest run: | set -x cd .build diff --git a/Ubuntu-24.04.Dockerfile b/Ubuntu-24.04.Dockerfile new file mode 100644 index 00000000..a905590d --- /dev/null +++ b/Ubuntu-24.04.Dockerfile @@ -0,0 +1,114 @@ +FROM ubuntu:24.04 + +ARG TARGETPLATFORM +ARG RUNNER_VERSION +ARG RUNNER_CONTAINER_HOOKS_VERSION +# Docker and Docker Compose arguments +ARG CHANNEL=stable +ARG DOCKER_VERSION=24.0.7 +ARG DOCKER_COMPOSE_VERSION=v2.23.0 +ARG DUMB_INIT_VERSION=1.2.5 +ARG RUNNER_USER_UID=1001 +ARG DOCKER_GROUP_GID=121 + +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get update -y \ + && apt-get install -y software-properties-common \ + && add-apt-repository -y ppa:git-core/ppa \ + && apt-get update -y \ + && apt-get install -y --no-install-recommends \ + curl \ + ca-certificates \ + git \ + jq \ + sudo \ + unzip \ + zip \ + && rm -rf /var/lib/apt/lists/* + +# Download latest git-lfs version +RUN curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash && \ + apt-get install -y --no-install-recommends git-lfs + +RUN adduser --disabled-password --gecos "" --uid $RUNNER_USER_UID runner \ + && groupadd docker --gid $DOCKER_GROUP_GID \ + && usermod -aG sudo runner \ + && usermod -aG docker runner \ + && echo "%sudo ALL=(ALL:ALL) NOPASSWD:ALL" > /etc/sudoers \ + && echo "Defaults env_keep += \"DEBIAN_FRONTEND\"" >> /etc/sudoers + +ENV HOME=/home/runner + +RUN export ARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) \ + && if [ "$ARCH" = "arm64" ]; then export ARCH=aarch64 ; fi \ + && if [ "$ARCH" = "amd64" ] || [ "$ARCH" = "i386" ]; then export ARCH=x86_64 ; fi \ + && curl -fLo /usr/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v${DUMB_INIT_VERSION}/dumb-init_${DUMB_INIT_VERSION}_${ARCH} \ + && chmod +x /usr/bin/dumb-init + +ENV RUNNER_ASSETS_DIR=/runnertmp +RUN export ARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) \ + && if [ "$ARCH" = "amd64" ] || [ "$ARCH" = "x86_64" ] || [ "$ARCH" = "i386" ]; then export ARCH=x64 ; fi \ + && mkdir -p "$RUNNER_ASSETS_DIR" \ + && cd "$RUNNER_ASSETS_DIR" \ + && curl -fLo runner.tar.gz https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-linux-${ARCH}-${RUNNER_VERSION}.tar.gz \ + && tar xzf ./runner.tar.gz \ + && rm runner.tar.gz \ + && ./bin/installdependencies.sh \ + && mv ./externals ./externalstmp \ + # libyaml-dev is required for ruby/setup-ruby action. + # It is installed after installdependencies.sh and before removing /var/lib/apt/lists + # to avoid rerunning apt-update on its own. + && apt-get install -y libyaml-dev \ + && rm -rf /var/lib/apt/lists/* + +ENV RUNNER_TOOL_CACHE=/opt/hostedtoolcache +RUN mkdir /opt/hostedtoolcache \ + && chgrp docker /opt/hostedtoolcache \ + && chmod g+rwx /opt/hostedtoolcache + +RUN cd "$RUNNER_ASSETS_DIR" \ + && curl -fLo runner-container-hooks.zip https://github.com/actions/runner-container-hooks/releases/download/v${RUNNER_CONTAINER_HOOKS_VERSION}/actions-runner-hooks-k8s-${RUNNER_CONTAINER_HOOKS_VERSION}.zip \ + && unzip ./runner-container-hooks.zip -d ./k8s \ + && rm -f runner-container-hooks.zip + +RUN set -vx; \ + export ARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) \ + && if [ "$ARCH" = "arm64" ]; then export ARCH=aarch64 ; fi \ + && if [ "$ARCH" = "amd64" ] || [ "$ARCH" = "i386" ]; then export ARCH=x86_64 ; fi \ + && curl -fLo docker.tgz https://download.docker.com/linux/static/${CHANNEL}/${ARCH}/docker-${DOCKER_VERSION}.tgz \ + && tar zxvf docker.tgz \ + && install -o root -g root -m 755 docker/docker /usr/bin/docker \ + && rm -rf docker docker.tgz + +RUN export ARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) \ + && if [ "$ARCH" = "arm64" ]; then export ARCH=aarch64 ; fi \ + && if [ "$ARCH" = "amd64" ] || [ "$ARCH" = "i386" ]; then export ARCH=x86_64 ; fi \ + && mkdir -p /usr/libexec/docker/cli-plugins \ + && curl -fLo /usr/libexec/docker/cli-plugins/docker-compose https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-linux-${ARCH} \ + && chmod +x /usr/libexec/docker/cli-plugins/docker-compose \ + && ln -s /usr/libexec/docker/cli-plugins/docker-compose /usr/bin/docker-compose \ + && which docker-compose \ + && docker compose version + +# We place the scripts in `/usr/bin` so that users who extend this image can +# override them with scripts of the same name placed in `/usr/local/bin`. +COPY entrypoint.sh startup.sh logger.sh graceful-stop.sh update-status /usr/bin/ + +# Copy the docker shim which propagates the docker MTU to underlying networks +# to replace the docker binary in the PATH. +COPY docker-shim.sh /usr/local/bin/docker + +# Configure hooks folder structure. +COPY hooks /etc/arc/hooks/ + +# Add the Python "User Script Directory" to the PATH +ENV PATH="${PATH}:${HOME}/.local/bin/" +ENV ImageOS=ubuntu24 + +RUN echo "PATH=${PATH}" > /etc/environment \ + && echo "ImageOS=${ImageOS}" >> /etc/environment + +USER runner + +ENTRYPOINT ["/bin/bash", "-c"] +CMD ["entrypoint.sh"] From 8d0a51486e152085cd22ee057c67354fc9218ad8 Mon Sep 17 00:00:00 2001 From: Darius Neatu Date: Tue, 16 Jul 2024 14:13:50 +0300 Subject: [PATCH 14/20] Fix Clang build on CI --- .github/workflows/ci.yml | 29 +++++----- Ubuntu-24.04.Dockerfile | 114 --------------------------------------- 2 files changed, 17 insertions(+), 126 deletions(-) delete mode 100644 Ubuntu-24.04.Dockerfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 66193455..2f4c7989 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,9 +31,9 @@ jobs: set -x cat /etc/lsb-release # Remove existing Clang installations. - sudo apt-get remove clang-${{matrix.config.installed_clang_version}} \ - lldb-${{matrix.config.installed_clang_version}} \ - lld-${{matrix.config.installed_clang_version}} \ + sudo apt-get remove \ + clang-${{matrix.config.installed_clang_version}} \ + clang++-${{matrix.config.installed_clang_version}} \ clangd-${{matrix.config.installed_clang_version}} \ clang-tidy-${{matrix.config.installed_clang_version}} \ clang-format-${{matrix.config.installed_clang_version}} \ @@ -42,20 +42,25 @@ jobs: lld-${{matrix.config.installed_clang_version}} \ lldb-${{matrix.config.installed_clang_version}} \ llvm-${{matrix.config.installed_clang_version}}-tools \ - libomp-${{matrix.config.installed_clang_version}}-dev \ libc++-${{matrix.config.installed_clang_version}}-dev \ libc++abi-${{matrix.config.installed_clang_version}}-dev \ libclang-common-${{matrix.config.installed_clang_version}}-dev \ libclang-${{matrix.config.installed_clang_version}}-dev \ libclang-cpp${{matrix.config.installed_clang_version}}-dev \ - libunwind-${{matrix.config.installed_clang_version}}-dev + libomp-${{matrix.config.installed_clang_version}}-dev \ + libunwind-${{matrix.config.installed_clang_version}}-dev \ + libc++-dev libc++1 libc++abi-dev libc++abi1 # Install LLVM+Clang. + CLANG_VERSION=$(echo ${{matrix.config.toolchain}} | cut -d '-' -f2) wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh - sudo ./llvm.sh ${{matrix.config.clang_version}} all - sudo apt-get install libc++-dev libc++1 libc++abi-dev libc++abi1 - find /usr/lib -name libc++.so* - ${{matrix.config.toolchain}} --version + sudo ./llvm.sh ${CLANG_VERSION} all + # Link Clang libraries (if not done by llvm.sh - some links are already set). + sudo ln -fs /usr/lib/llvm-${CLANG_VERSION}/lib/lib* /usr/lib/x86_64-linux-gnu/ || true + # If Clang 17, install a newer version of libc++ and libc++abi. + [[ ${CLANG_VERSION} = 17 ]] && sudo apt-get install libc++-dev libc++1 libc++abi-dev libc++abi1 + find /usr/lib/x86_64-linux-gnu/ -name libc++.so* || true + clang++-${CLANG_VERSION} --version - name: Install GCC if: startsWith(matrix.config.name, 'Ubuntu GCC') run: | @@ -67,8 +72,8 @@ jobs: GCC_VERSION=$(echo ${{matrix.config.toolchain}} | cut -d '-' -f2) echo "GCC_VERSION=$GCC_VERSION" sudo apt-get install g++-${GCC_VERSION} gcc-${GCC_VERSION} - find /usr/lib -name libstdc++.so* - ${{matrix.config.toolchain}} --version + find /usr/lib/x86_64-linux-gnu/ -name libstdc++.so* + g++-${GCC_VERSION} --version - name: CMake Configure run: | set -x @@ -82,7 +87,7 @@ jobs: run: | set -x cmake --build .build --config Asan --target all -- -k 0 - - name: CTest + - name: CMake Test run: | set -x cd .build diff --git a/Ubuntu-24.04.Dockerfile b/Ubuntu-24.04.Dockerfile deleted file mode 100644 index a905590d..00000000 --- a/Ubuntu-24.04.Dockerfile +++ /dev/null @@ -1,114 +0,0 @@ -FROM ubuntu:24.04 - -ARG TARGETPLATFORM -ARG RUNNER_VERSION -ARG RUNNER_CONTAINER_HOOKS_VERSION -# Docker and Docker Compose arguments -ARG CHANNEL=stable -ARG DOCKER_VERSION=24.0.7 -ARG DOCKER_COMPOSE_VERSION=v2.23.0 -ARG DUMB_INIT_VERSION=1.2.5 -ARG RUNNER_USER_UID=1001 -ARG DOCKER_GROUP_GID=121 - -ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get update -y \ - && apt-get install -y software-properties-common \ - && add-apt-repository -y ppa:git-core/ppa \ - && apt-get update -y \ - && apt-get install -y --no-install-recommends \ - curl \ - ca-certificates \ - git \ - jq \ - sudo \ - unzip \ - zip \ - && rm -rf /var/lib/apt/lists/* - -# Download latest git-lfs version -RUN curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash && \ - apt-get install -y --no-install-recommends git-lfs - -RUN adduser --disabled-password --gecos "" --uid $RUNNER_USER_UID runner \ - && groupadd docker --gid $DOCKER_GROUP_GID \ - && usermod -aG sudo runner \ - && usermod -aG docker runner \ - && echo "%sudo ALL=(ALL:ALL) NOPASSWD:ALL" > /etc/sudoers \ - && echo "Defaults env_keep += \"DEBIAN_FRONTEND\"" >> /etc/sudoers - -ENV HOME=/home/runner - -RUN export ARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) \ - && if [ "$ARCH" = "arm64" ]; then export ARCH=aarch64 ; fi \ - && if [ "$ARCH" = "amd64" ] || [ "$ARCH" = "i386" ]; then export ARCH=x86_64 ; fi \ - && curl -fLo /usr/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v${DUMB_INIT_VERSION}/dumb-init_${DUMB_INIT_VERSION}_${ARCH} \ - && chmod +x /usr/bin/dumb-init - -ENV RUNNER_ASSETS_DIR=/runnertmp -RUN export ARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) \ - && if [ "$ARCH" = "amd64" ] || [ "$ARCH" = "x86_64" ] || [ "$ARCH" = "i386" ]; then export ARCH=x64 ; fi \ - && mkdir -p "$RUNNER_ASSETS_DIR" \ - && cd "$RUNNER_ASSETS_DIR" \ - && curl -fLo runner.tar.gz https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-linux-${ARCH}-${RUNNER_VERSION}.tar.gz \ - && tar xzf ./runner.tar.gz \ - && rm runner.tar.gz \ - && ./bin/installdependencies.sh \ - && mv ./externals ./externalstmp \ - # libyaml-dev is required for ruby/setup-ruby action. - # It is installed after installdependencies.sh and before removing /var/lib/apt/lists - # to avoid rerunning apt-update on its own. - && apt-get install -y libyaml-dev \ - && rm -rf /var/lib/apt/lists/* - -ENV RUNNER_TOOL_CACHE=/opt/hostedtoolcache -RUN mkdir /opt/hostedtoolcache \ - && chgrp docker /opt/hostedtoolcache \ - && chmod g+rwx /opt/hostedtoolcache - -RUN cd "$RUNNER_ASSETS_DIR" \ - && curl -fLo runner-container-hooks.zip https://github.com/actions/runner-container-hooks/releases/download/v${RUNNER_CONTAINER_HOOKS_VERSION}/actions-runner-hooks-k8s-${RUNNER_CONTAINER_HOOKS_VERSION}.zip \ - && unzip ./runner-container-hooks.zip -d ./k8s \ - && rm -f runner-container-hooks.zip - -RUN set -vx; \ - export ARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) \ - && if [ "$ARCH" = "arm64" ]; then export ARCH=aarch64 ; fi \ - && if [ "$ARCH" = "amd64" ] || [ "$ARCH" = "i386" ]; then export ARCH=x86_64 ; fi \ - && curl -fLo docker.tgz https://download.docker.com/linux/static/${CHANNEL}/${ARCH}/docker-${DOCKER_VERSION}.tgz \ - && tar zxvf docker.tgz \ - && install -o root -g root -m 755 docker/docker /usr/bin/docker \ - && rm -rf docker docker.tgz - -RUN export ARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) \ - && if [ "$ARCH" = "arm64" ]; then export ARCH=aarch64 ; fi \ - && if [ "$ARCH" = "amd64" ] || [ "$ARCH" = "i386" ]; then export ARCH=x86_64 ; fi \ - && mkdir -p /usr/libexec/docker/cli-plugins \ - && curl -fLo /usr/libexec/docker/cli-plugins/docker-compose https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-linux-${ARCH} \ - && chmod +x /usr/libexec/docker/cli-plugins/docker-compose \ - && ln -s /usr/libexec/docker/cli-plugins/docker-compose /usr/bin/docker-compose \ - && which docker-compose \ - && docker compose version - -# We place the scripts in `/usr/bin` so that users who extend this image can -# override them with scripts of the same name placed in `/usr/local/bin`. -COPY entrypoint.sh startup.sh logger.sh graceful-stop.sh update-status /usr/bin/ - -# Copy the docker shim which propagates the docker MTU to underlying networks -# to replace the docker binary in the PATH. -COPY docker-shim.sh /usr/local/bin/docker - -# Configure hooks folder structure. -COPY hooks /etc/arc/hooks/ - -# Add the Python "User Script Directory" to the PATH -ENV PATH="${PATH}:${HOME}/.local/bin/" -ENV ImageOS=ubuntu24 - -RUN echo "PATH=${PATH}" > /etc/environment \ - && echo "ImageOS=${ImageOS}" >> /etc/environment - -USER runner - -ENTRYPOINT ["/bin/bash", "-c"] -CMD ["entrypoint.sh"] From 456cee031797731c654d661e11e07fa669b86476 Mon Sep 17 00:00:00 2001 From: Darius Neatu Date: Wed, 17 Jul 2024 13:28:42 +0300 Subject: [PATCH 15/20] Rename test target --- src/Beman/Optional26/tests/CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Beman/Optional26/tests/CMakeLists.txt b/src/Beman/Optional26/tests/CMakeLists.txt index 91c757fb..52affaef 100644 --- a/src/Beman/Optional26/tests/CMakeLists.txt +++ b/src/Beman/Optional26/tests/CMakeLists.txt @@ -6,16 +6,16 @@ include(GoogleTest) # Tests -add_executable(optional_test - optional.t.cpp - optional_ref.t.cpp +add_executable(beman_optional26_test + detail/iterator.t.cpp optional_monadic.t.cpp optional_range_support.t.cpp optional_ref_monadic.t.cpp - detail/iterator.t.cpp + optional_ref.t.cpp + optional.t.cpp ) -target_link_libraries(optional_test +target_link_libraries(beman_optional26_test beman_optional26 GTest::gtest GTest::gtest_main @@ -24,7 +24,7 @@ target_link_libraries(optional_test # Issue #32: Re-enable ASAN run CI/clang-19 # Note: clang-19 + gtest_discover_tests + Asan setup causes errors on some platforms. # Temporary switch to gtest_add_tests and skip some Asan checks. Change also applied for CI flows. -gtest_add_tests(TARGET optional_test +gtest_add_tests(TARGET beman_optional26_test "" AUTO ) From 5f9170821f4f304ab6ac6399e6fdb16e517b2456 Mon Sep 17 00:00:00 2001 From: Darius Neatu Date: Wed, 17 Jul 2024 14:01:10 +0300 Subject: [PATCH 16/20] Simplify build instructions --- .github/workflows/ci.yml | 9 +++------ README.md | 28 ++++++++++------------------ src/Beman/Optional26/CMakeLists.txt | 8 +++++--- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2f4c7989..10a9ec2b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,12 +77,10 @@ jobs: - name: CMake Configure run: | set -x - rm -rf .build - mkdir -p .build - cd .build echo ${{ matrix.config.cmake_args }} echo ${{ matrix.config.toolchain }} - cmake ${{ matrix.config.cmake_args }} -DCMAKE_TOOLCHAIN_FILE="etc/${{ matrix.config.toolchain }}-toolchain.cmake" -B . -S .. + rm -rf .build + cmake ${{ matrix.config.cmake_args }} -DCMAKE_TOOLCHAIN_FILE="etc/${{ matrix.config.toolchain }}-toolchain.cmake" -B .build -S . - name: CMake Build run: | set -x @@ -90,6 +88,5 @@ jobs: - name: CMake Test run: | set -x - cd .build [[ ! -z "${{ matrix.config.asan_options }}" ]] && export ASAN_OPTIONS="${{ matrix.config.asan_options }}" - ctest --build-config Asan --output-on-failure + ctest --build-config Asan --output-on-failure --test-dir .build diff --git a/README.md b/README.md index 6ce794e0..2873eceb 100644 --- a/README.md +++ b/README.md @@ -204,24 +204,20 @@ CI current build and test flows: ```shell # Configure build: default build production code + tests (BUILD_TESTING=ON by default). -$ rm -rf .build/ -$ mkdir -p .build -$ cd .build -$ cmake -G "Ninja Multi-Config" -DCMAKE_CONFIGURATION_TYPES="RelWithDebInfo;Asan" -DCMAKE_TOOLCHAIN_FILE=etc/clang-19-toolchain.cmake -B . -S .. +$ cmake -G "Ninja Multi-Config" -DCMAKE_CONFIGURATION_TYPES="RelWithDebInfo;Asan" -DCMAKE_TOOLCHAIN_FILE=etc/clang-19-toolchain.cmake -B .build -S . -- The CXX compiler identification is Clang 19.0.0 ... --- Build files have been written to: /home/dariusn/git/Beman/Beman.Optional26/.build +-- Build files have been written to: /path/to/Optional26/.build # Build. -$ cd .. $ cmake --build .build --config Asan --target all -- -k 0 ... -[30/30] Linking CXX executable examples/Asan/sample +[30/30] Linking CXX executable ... # Run tests. -$ cd .build -$ ctest --build-config Asan --output-on-failure -Test project /home/dariusn/git/Beman/Beman.Optional26/.build +$ ctest --build-config Asan --output-on-failure --test-dir .build +Internal ctest changing into directory: /path/to/Optional26/.build +Test project /path/to/Optional26/.build ... 100% tests passed, 0 tests failed out of 82 @@ -234,23 +230,19 @@ By default, we build and run tests. You can provide `-DBUILD_TESTING=OFF` and co ```shell # Configure build: build production code, skip tests (BUILD_TESTING=OFF). -$ rm -rf .build/ -$ mkdir -p .build -$ cd .build -$ cmake -G "Ninja Multi-Config" -DCMAKE_CONFIGURATION_TYPES="RelWithDebInfo;Asan" -DCMAKE_TOOLCHAIN_FILE=etc/clang-19-toolchain.cmake -DBUILD_TESTING=OFF -B . -S .. +$ cmake -G "Ninja Multi-Config" -DCMAKE_CONFIGURATION_TYPES="RelWithDebInfo;Asan" -DCMAKE_TOOLCHAIN_FILE=etc/clang-19-toolchain.cmake -DBUILD_TESTING=OFF -B .build -S . -- The CXX compiler identification is Clang 19.0.0 ... --- Build files have been written to: /home/dariusn/git/Beman/Beman.Optional26/.build +-- Build files have been written to: /path/to/Optional26/.build # Build. -$ cd .. $ cmake --build .build --config Asan --target all -- -k 0 ... [15/15] Linking CXX executable examples/Asan/sample # Check that tests are not built/installed. -$ cd .build -$ ctest --build-config Asan --output-on-failure +$ ctest --build-config Asan --output-on-failure --test-dir .build +Internal ctest changing into directory: /home/dariusn/git/Beman/Beman.Optional26/.build Test project /home/dariusn/git/Beman/Beman.Optional26/.build No tests were found!!! ``` diff --git a/src/Beman/Optional26/CMakeLists.txt b/src/Beman/Optional26/CMakeLists.txt index 4f2e9612..5bc3167f 100644 --- a/src/Beman/Optional26/CMakeLists.txt +++ b/src/Beman/Optional26/CMakeLists.txt @@ -20,8 +20,9 @@ target_include_directories( install( TARGETS beman_optional26 - EXPORT ${TARGETS_EXPORT_NAME}1 - DESTINATION ${CMAKE_INSTALL_LIBDIR}) + EXPORT ${TARGETS_EXPORT_NAME} + DESTINATION ${CMAKE_INSTALL_LIBDIR} +) string(TOLOWER ${CMAKE_PROJECT_NAME} CMAKE_LOWER_PROJECT_NAME) @@ -29,7 +30,8 @@ install( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_LOWER_PROJECT_NAME} FILES_MATCHING - PATTERN "*.hpp") + PATTERN "*.hpp" +) target_link_libraries(beman_optional26) From c57d25066dd0726a57258acd87c1f4d68ef9fce0 Mon Sep 17 00:00:00 2001 From: Darius Neatu Date: Wed, 17 Jul 2024 14:10:16 +0300 Subject: [PATCH 17/20] Run linters --- CMakeLists.txt | 2 +- README.md | 38 +++++++++++------------ src/Beman/Optional26/CMakeLists.txt | 11 ++----- src/Beman/Optional26/tests/CMakeLists.txt | 32 +++++++------------ 4 files changed, 34 insertions(+), 49 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2187dbfc..812a1903 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ if(BUILD_TESTING) FetchContent_Declare( googletest GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG f8d7d77c06936315286eb55f8de22cd23c188571 # release-1.14.0 + GIT_TAG f8d7d77c06936315286eb55f8de22cd23c188571 # release-1.14.0 ) FetchContent_MakeAvailable(googletest) endif() diff --git a/README.md b/README.md index 2873eceb..ca7050cc 100644 --- a/README.md +++ b/README.md @@ -13,25 +13,23 @@ This repository implements `std::optional` extensions targeting C++26. The `Bema * [Give *std::optional* Range Support (P3168R2)](https://wg21.link/P3168R2) * [`std::optional` (P2988R5)](https://wg21.link/P2988R5) - ## Table of Contents -- [Beman.Optional26: C++26 Extensions for std::optional](#bemanoptional26-c26-extensions-for-stdoptional) - - [Table of Contents](#table-of-contents) - - [License](#license) - - [Examples](#examples) - - [range\_loop](#range_loop) - - [optional\_ref](#optional_ref) - - [How to Build](#how-to-build) - - [Compiler Support](#compiler-support) - - [Dependencies](#dependencies) - - [Instructions](#instructions) - - [Default Build and Test Flow](#default-build-and-test-flow) - - [More Complex Cases](#more-complex-cases) - - [Step by Step Build: Build and Run Tests](#step-by-step-build-build-and-run-tests) - - [Step by Step Build: Build Production and Skip Tests](#step-by-step-build-build-production-and-skip-tests) - - [Papers](#papers) - +* [Beman.Optional26: C++26 Extensions for std::optional](#bemanoptional26-c26-extensions-for-stdoptional) + * [Table of Contents](#table-of-contents) + * [License](#license) + * [Examples](#examples) + * [range\_loop](#range_loop) + * [optional\_ref](#optional_ref) + * [How to Build](#how-to-build) + * [Compiler Support](#compiler-support) + * [Dependencies](#dependencies) + * [Instructions](#instructions) + * [Default Build and Test Flow](#default-build-and-test-flow) + * [More Complex Cases](#more-complex-cases) + * [Step by Step Build: Build and Run Tests](#step-by-step-build-build-and-run-tests) + * [Step by Step Build: Build Production and Skip Tests](#step-by-step-build-build-production-and-skip-tests) + * [Papers](#papers) ## License @@ -193,7 +191,7 @@ This should build and run the tests with GCC 14 with the address and undefined b The CMake preset system suffers from combinitorial explosion. There is a makefile in the root of the repository to aid in running more configurations. ```shell -make -k TOOLCHAIN=clang-18 CONFIG=Tsan VERBOSE=1 +make -k TOOLCHAIN=clang-18 CONFIG=Tsan VERBOSE=1 ``` The makefile will use your system compiler, `c++`, if no toolchain name is provided, otherwise it will use the toolchain in the etc/ directory to perform the build. The Ninja multi config generator is used, with configurations for `RelWithDebugInfo`, `Debug`, `Tsan`, and `Asan` configured by default. @@ -212,7 +210,7 @@ $ cmake -G "Ninja Multi-Config" -DCMAKE_CONFIGURATION_TYPES="RelWithDebInfo;Asan # Build. $ cmake --build .build --config Asan --target all -- -k 0 ... -[30/30] Linking CXX executable ... +[30/30] Linking CXX executable ... # Note: 30 targets here (including tests). # Run tests. $ ctest --build-config Asan --output-on-failure --test-dir .build @@ -238,7 +236,7 @@ $ cmake -G "Ninja Multi-Config" -DCMAKE_CONFIGURATION_TYPES="RelWithDebInfo;Asan # Build. $ cmake --build .build --config Asan --target all -- -k 0 ... -[15/15] Linking CXX executable examples/Asan/sample +[15/15] Linking CXX executable ... # Note: 15 targets here (tests were not built). # Check that tests are not built/installed. $ ctest --build-config Asan --output-on-failure --test-dir .build diff --git a/src/Beman/Optional26/CMakeLists.txt b/src/Beman/Optional26/CMakeLists.txt index 5bc3167f..d19018d8 100644 --- a/src/Beman/Optional26/CMakeLists.txt +++ b/src/Beman/Optional26/CMakeLists.txt @@ -3,10 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # cmake-format: on -add_library(beman_optional26 STATIC - optional.cpp - detail/iterator.cpp -) +add_library(beman_optional26 STATIC optional.cpp detail/iterator.cpp) include(GNUInstallDirs) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) @@ -21,8 +18,7 @@ target_include_directories( install( TARGETS beman_optional26 EXPORT ${TARGETS_EXPORT_NAME} - DESTINATION ${CMAKE_INSTALL_LIBDIR} -) + DESTINATION ${CMAKE_INSTALL_LIBDIR}) string(TOLOWER ${CMAKE_PROJECT_NAME} CMAKE_LOWER_PROJECT_NAME) @@ -30,8 +26,7 @@ install( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_LOWER_PROJECT_NAME} FILES_MATCHING - PATTERN "*.hpp" -) + PATTERN "*.hpp") target_link_libraries(beman_optional26) diff --git a/src/Beman/Optional26/tests/CMakeLists.txt b/src/Beman/Optional26/tests/CMakeLists.txt index 52affaef..43500207 100644 --- a/src/Beman/Optional26/tests/CMakeLists.txt +++ b/src/Beman/Optional26/tests/CMakeLists.txt @@ -6,25 +6,17 @@ include(GoogleTest) # Tests -add_executable(beman_optional26_test - detail/iterator.t.cpp - optional_monadic.t.cpp - optional_range_support.t.cpp - optional_ref_monadic.t.cpp - optional_ref.t.cpp - optional.t.cpp -) +add_executable( + beman_optional26_test + detail/iterator.t.cpp optional_monadic.t.cpp optional_range_support.t.cpp + optional_ref_monadic.t.cpp optional_ref.t.cpp optional.t.cpp) -target_link_libraries(beman_optional26_test - beman_optional26 - GTest::gtest - GTest::gtest_main -) +target_link_libraries(beman_optional26_test beman_optional26 GTest::gtest + GTest::gtest_main) -# Issue #32: Re-enable ASAN run CI/clang-19 -# Note: clang-19 + gtest_discover_tests + Asan setup causes errors on some platforms. -# Temporary switch to gtest_add_tests and skip some Asan checks. Change also applied for CI flows. -gtest_add_tests(TARGET beman_optional26_test - "" - AUTO -) +# Issue #32: Re-enable ASAN run CI/clang-19. +# +# Note: clang-19 + gtest_discover_tests + Asan setup causes errors on some +# platforms. Temporary switch to gtest_add_tests and skip some Asan checks. +# Change also applied for CI flows. +gtest_add_tests(TARGET beman_optional26_test "" AUTO) From 1b45f87d81df807a9dd971149d90e721a1e0ff17 Mon Sep 17 00:00:00 2001 From: Darius Neatu Date: Wed, 17 Jul 2024 15:40:11 +0300 Subject: [PATCH 18/20] Fix make compile --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b27aabc4..90e38881 100755 --- a/Makefile +++ b/Makefile @@ -60,16 +60,17 @@ $(_build_path)/CMakeCache.txt: | $(_build_path) .gitmodules ln -s $(_build_path)/compile_commands.json compile: $(_build_path)/CMakeCache.txt ## Compile the project + cmake $(CMAKE_FLAGS) -DCMAKE_TOOLCHAIN_FILE=etc/$(TOOLCHAIN)-toolchain.cmake -B $(_build_path) -S . cmake --build $(_build_path) --config $(CONFIG) --target all -- -k 0 install: $(_build_path)/CMakeCache.txt ## Install the project DESTDIR=$(abspath $(DEST)) ninja -C $(_build_path) -k 0 install ctest: $(_build_path)/CMakeCache.txt ## Run CTest on current build - cd $(_build_path) && ctest --output-on-failure + ctest --build-config $(CONFIG) --output-on-failure --test-dir $(_build_path) ctest_ : compile - cd $(_build_path) && ctest --output-on-failure + ctest --build-config $(CONFIG) --output-on-failure --test-dir $(_build_path) test: ctest_ ## Rebuild and run tests From 729e2b4a05a3f5714b1b0e52b3ce72de330b7220 Mon Sep 17 00:00:00 2001 From: Darius Neatu Date: Wed, 17 Jul 2024 18:45:57 +0300 Subject: [PATCH 19/20] Tweaks in root Makefile for generic build and run --- Makefile | 61 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index 90e38881..7e639d86 100755 --- a/Makefile +++ b/Makefile @@ -4,12 +4,25 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # cmake-format: on -INSTALL_PREFIX?=.install/ +# This Makefile is a thin wrapper around CMake. It is intended to be used. + +# Default target. PROJECT?=$(shell basename $(CURDIR)) + +# Default install prefix. +INSTALL_PREFIX?=.install/ +# Default build directory. BUILD_DIR?=.build +# Default destination directory. DEST?=$(INSTALL_PREFIX) +# Default toolchain: missing => c++ sytem tool. +TOOLCHAIN?= +# Default configuration: missing => Asan. +BUILD_CONFIG?=Asan +# Default CMake flags. CMAKE_FLAGS?= +# Default targets. TARGETS := test clean all ctest export @@ -20,25 +33,27 @@ export .gitmodules: .update-submodules -CONFIG?=Asan export ifeq ($(strip $(TOOLCHAIN)),) - _build_name?=build-system/ - _build_dir?=.build/ + # Default build configuration. + _build_name?=toolchain/c++-system + _build_dir?=$(BUILD_DIR) _configuration_types?="RelWithDebInfo;Debug;Tsan;Asan" _cmake_args=-DCMAKE_TOOLCHAIN_FILE=$(CURDIR)/etc/toolchain.cmake else - _build_name?=build-$(TOOLCHAIN) - _build_dir?=.build/ + # Custom toolchain. + _build_name?=toolchain/$(TOOLCHAIN) + _build_dir?=$(BUILD_DIR) _configuration_types?="RelWithDebInfo;Debug;Tsan;Asan" _cmake_args=-DCMAKE_TOOLCHAIN_FILE=$(CURDIR)/etc/$(TOOLCHAIN)-toolchain.cmake endif - +# Build path. _build_path?=$(_build_dir)/$(_build_name) +# CMake command wrapper. define run_cmake = cmake \ -G "Ninja Multi-Config" \ @@ -46,10 +61,12 @@ define run_cmake = -DCMAKE_INSTALL_PREFIX=$(abspath $(INSTALL_PREFIX)) \ -DCMAKE_EXPORT_COMPILE_COMMANDS=1 \ $(_cmake_args) \ + $(CMAKE_FLAGS) \ $(CURDIR) endef -default: test +# Default target. +default: build test $(_build_path): mkdir -p $(_build_path) @@ -59,34 +76,34 @@ $(_build_path)/CMakeCache.txt: | $(_build_path) .gitmodules -rm compile_commands.json ln -s $(_build_path)/compile_commands.json -compile: $(_build_path)/CMakeCache.txt ## Compile the project - cmake $(CMAKE_FLAGS) -DCMAKE_TOOLCHAIN_FILE=etc/$(TOOLCHAIN)-toolchain.cmake -B $(_build_path) -S . - cmake --build $(_build_path) --config $(CONFIG) --target all -- -k 0 +build: $(_build_path)/CMakeCache.txt ## Compile the project. + cmake $(CMAKE_FLAGS) -DCMAKE_TOOLCHAIN_FILE=etc/$(TOOLCHAIN)-toolchain.cmake -B $(_build_path) -S . + cmake --build $(_build_path) --config $(BUILD_CONFIG) --target all -- -k 0 -install: $(_build_path)/CMakeCache.txt ## Install the project +install: $(_build_path)/CMakeCache.txt ## Install the project. DESTDIR=$(abspath $(DEST)) ninja -C $(_build_path) -k 0 install -ctest: $(_build_path)/CMakeCache.txt ## Run CTest on current build - ctest --build-config $(CONFIG) --output-on-failure --test-dir $(_build_path) +ctest: $(_build_path)/CMakeCache.txt ## Run CTest on current build. + ctest --build-config $(BUILD_CONFIG) --output-on-failure --test-dir $(_build_path) -ctest_ : compile - ctest --build-config $(CONFIG) --output-on-failure --test-dir $(_build_path) +ctest_ : build + ctest --build-config $(BUILD_CONFIG) --output-on-failure --test-dir $(_build_path) -test: ctest_ ## Rebuild and run tests +test: ctest_ ## Rebuild and run tests. cmake: | $(_build_path) cd $(_build_path) && ${run_cmake} -clean: $(_build_path)/CMakeCache.txt ## Clean the build artifacts - cmake --build $(_build_path) --config $(CONFIG) --target clean +clean: $(_build_path)/CMakeCache.txt ## Clean the build artifacts, but don't delete the build directory. + cmake --build $(_build_path) --config $(BUILD_CONFIG) --target clean -realclean: ## Delete the build directory +realclean: ## Delete the entire build directory. rm -rf $(_build_path) env: $(foreach v, $(.VARIABLES), $(info $(v) = $($(v)))) -.PHONY : compile install ctest ctest_ test cmake clean realclean env +.PHONY : build install ctest ctest_ test cmake clean realclean env .PHONY: papers papers: @@ -95,4 +112,4 @@ papers: # Help target .PHONY: help help: ## Show this help. - @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) targets.mk | sort + @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort From e167523ba02990b0460dad3c8d0f805935c27b86 Mon Sep 17 00:00:00 2001 From: Darius Neatu Date: Wed, 17 Jul 2024 18:48:17 +0300 Subject: [PATCH 20/20] Temporary remove make build support --- Makefile | 115 ------------------------------------------------------ README.md | 28 +++++-------- 2 files changed, 10 insertions(+), 133 deletions(-) delete mode 100755 Makefile diff --git a/Makefile b/Makefile deleted file mode 100755 index 7e639d86..00000000 --- a/Makefile +++ /dev/null @@ -1,115 +0,0 @@ -#! /usr/bin/make -f -# cmake-format: off -# /Makefile -*-makefile-*- -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# cmake-format: on - -# This Makefile is a thin wrapper around CMake. It is intended to be used. - -# Default target. -PROJECT?=$(shell basename $(CURDIR)) - -# Default install prefix. -INSTALL_PREFIX?=.install/ -# Default build directory. -BUILD_DIR?=.build -# Default destination directory. -DEST?=$(INSTALL_PREFIX) -# Default toolchain: missing => c++ sytem tool. -TOOLCHAIN?= -# Default configuration: missing => Asan. -BUILD_CONFIG?=Asan -# Default CMake flags. -CMAKE_FLAGS?= - -# Default targets. -TARGETS := test clean all ctest - -export - -.update-submodules: - git submodule update --init --recursive - touch .update-submodules - -.gitmodules: .update-submodules - - -export - -ifeq ($(strip $(TOOLCHAIN)),) - # Default build configuration. - _build_name?=toolchain/c++-system - _build_dir?=$(BUILD_DIR) - _configuration_types?="RelWithDebInfo;Debug;Tsan;Asan" - _cmake_args=-DCMAKE_TOOLCHAIN_FILE=$(CURDIR)/etc/toolchain.cmake -else - # Custom toolchain. - _build_name?=toolchain/$(TOOLCHAIN) - _build_dir?=$(BUILD_DIR) - _configuration_types?="RelWithDebInfo;Debug;Tsan;Asan" - _cmake_args=-DCMAKE_TOOLCHAIN_FILE=$(CURDIR)/etc/$(TOOLCHAIN)-toolchain.cmake -endif - -# Build path. -_build_path?=$(_build_dir)/$(_build_name) - -# CMake command wrapper. -define run_cmake = - cmake \ - -G "Ninja Multi-Config" \ - -DCMAKE_CONFIGURATION_TYPES=$(_configuration_types) \ - -DCMAKE_INSTALL_PREFIX=$(abspath $(INSTALL_PREFIX)) \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=1 \ - $(_cmake_args) \ - $(CMAKE_FLAGS) \ - $(CURDIR) -endef - -# Default target. -default: build test - -$(_build_path): - mkdir -p $(_build_path) - -$(_build_path)/CMakeCache.txt: | $(_build_path) .gitmodules - cd $(_build_path) && $(run_cmake) - -rm compile_commands.json - ln -s $(_build_path)/compile_commands.json - -build: $(_build_path)/CMakeCache.txt ## Compile the project. - cmake $(CMAKE_FLAGS) -DCMAKE_TOOLCHAIN_FILE=etc/$(TOOLCHAIN)-toolchain.cmake -B $(_build_path) -S . - cmake --build $(_build_path) --config $(BUILD_CONFIG) --target all -- -k 0 - -install: $(_build_path)/CMakeCache.txt ## Install the project. - DESTDIR=$(abspath $(DEST)) ninja -C $(_build_path) -k 0 install - -ctest: $(_build_path)/CMakeCache.txt ## Run CTest on current build. - ctest --build-config $(BUILD_CONFIG) --output-on-failure --test-dir $(_build_path) - -ctest_ : build - ctest --build-config $(BUILD_CONFIG) --output-on-failure --test-dir $(_build_path) - -test: ctest_ ## Rebuild and run tests. - -cmake: | $(_build_path) - cd $(_build_path) && ${run_cmake} - -clean: $(_build_path)/CMakeCache.txt ## Clean the build artifacts, but don't delete the build directory. - cmake --build $(_build_path) --config $(BUILD_CONFIG) --target clean - -realclean: ## Delete the entire build directory. - rm -rf $(_build_path) - -env: - $(foreach v, $(.VARIABLES), $(info $(v) = $($(v)))) - -.PHONY : build install ctest ctest_ test cmake clean realclean env - -.PHONY: papers -papers: - $(MAKE) -C papers papers - -# Help target -.PHONY: help -help: ## Show this help. - @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort diff --git a/README.md b/README.md index ca7050cc..8d3a3722 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,10 @@ This repository implements `std::optional` extensions targeting C++26. The `Bema * [Compiler Support](#compiler-support) * [Dependencies](#dependencies) * [Instructions](#instructions) - * [Default Build and Test Flow](#default-build-and-test-flow) - * [More Complex Cases](#more-complex-cases) - * [Step by Step Build: Build and Run Tests](#step-by-step-build-build-and-run-tests) - * [Step by Step Build: Build Production and Skip Tests](#step-by-step-build-build-production-and-skip-tests) + * [Preset CMake Flows](#preset-cmake-flows) + * [Custom CMake Flows](#custom-cmake-flows) + * [Build and Run Tests](#build-and-run-tests) + * [Build Production, but Skip Tests](#build-production-but-skip-tests) * [Papers](#papers) ## License @@ -141,7 +141,7 @@ apt-get install \ Full set of supported toolchains can be found in [.github/workflows/ci.yml](.github/workflows/ci.yml). -#### Default Build and Test Flow +#### Preset CMake Flows This project strives to be as normal and simple a CMake project as possible. This build workflow in particular will work, producing a static `beman_optional26` library, ready to package: @@ -186,17 +186,9 @@ Total Test time (real) = 0.09 sec This should build and run the tests with GCC 14 with the address and undefined behavior sanitizers enabled. -#### More Complex Cases +#### Custom CMake Flows -The CMake preset system suffers from combinitorial explosion. There is a makefile in the root of the repository to aid in running more configurations. - -```shell -make -k TOOLCHAIN=clang-18 CONFIG=Tsan VERBOSE=1 -``` - -The makefile will use your system compiler, `c++`, if no toolchain name is provided, otherwise it will use the toolchain in the etc/ directory to perform the build. The Ninja multi config generator is used, with configurations for `RelWithDebugInfo`, `Debug`, `Tsan`, and `Asan` configured by default. - -#### Step by Step Build: Build and Run Tests +##### Build and Run Tests CI current build and test flows: @@ -222,7 +214,7 @@ Test project /path/to/Optional26/.build Total Test time (real) = 0.67 sec ``` -#### Step by Step Build: Build Production and Skip Tests +##### Build Production, but Skip Tests By default, we build and run tests. You can provide `-DBUILD_TESTING=OFF` and completely disable building tests: @@ -240,8 +232,8 @@ $ cmake --build .build --config Asan --target all -- -k 0 # Check that tests are not built/installed. $ ctest --build-config Asan --output-on-failure --test-dir .build -Internal ctest changing into directory: /home/dariusn/git/Beman/Beman.Optional26/.build -Test project /home/dariusn/git/Beman/Beman.Optional26/.build +Internal ctest changing into directory: /path/to/Beman.Optional26/.build +Test project /path/to/Beman.Optional26/.build No tests were found!!! ```