Skip to content

Commit

Permalink
Merge pull request bemanproject#29 from neatudarius/tweaks-in-cmakeli…
Browse files Browse the repository at this point in the history
…sts-for-packaging

Split build production vs testing
  • Loading branch information
neatudarius authored Jul 17, 2024
2 parents 8f4a5f4 + e167523 commit bfeb908
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 180 deletions.
63 changes: 38 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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", 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: 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", 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:
Expand All @@ -26,13 +26,14 @@ 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
sudo apt-get remove clang-${{matrix.config.installed_clang_version}} \
lldb-${{matrix.config.installed_clang_version}} \
lld-${{matrix.config.installed_clang_version}} \
# Remove existing Clang installations.
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}} \
Expand All @@ -41,39 +42,51 @@ 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
- name: Install GCC 14
if: matrix.config.name == 'Ubuntu GCC 14'
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: |
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/x86_64-linux-gnu/ -name libstdc++.so*
g++-${GCC_VERSION} --version
- 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 }} -B . -S ..
- name: Build
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
cmake --build .build --config Asan --target all -- -k 0
- name: Test
- 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
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
20 changes: 16 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,31 @@
# 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()
# Includes
include(CTest)
include(FetchContent)

set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}Targets)

add_subdirectory(extern)
add_subdirectory(src)
# Build the tests only if enabled via the CLI flag: BUILD_TESTING.
if(BUILD_TESTING)
# Fetch GoogleTest
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/Beman/Optional26)
add_subdirectory(examples)

include(GNUInstallDirs)
Expand Down
7 changes: 7 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,33 +68,40 @@
},
{
"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"
}
],
"testPresets": [
{
"name": "common",
"hidden": true,
"configuration": "Asan",
"output": {
"outputOnFailure": true
},
Expand Down
97 changes: 0 additions & 97 deletions Makefile

This file was deleted.

69 changes: 64 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ This repository implements `std::optional` extensions targeting C++26. The `Bema
* [Give *std::optional* Range Support (P3168R2)](https://wg21.link/P3168R2)
* [`std::optional<T&>` (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)
* [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

Source is licensed with the Apache 2.0 license with LLVM exceptions
Expand Down Expand Up @@ -123,7 +141,7 @@ apt-get install \

Full set of supported toolchains can be found in [.github/workflows/ci.yml](.github/workflows/ci.yml).

#### Basic Build
#### 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:

Expand Down Expand Up @@ -168,15 +186,56 @@ 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

##### Build and Run Tests

The CMake preset system suffers from combinitorial explosion. There is a makefile in the root of the repository to aid in running more configurations.
CI current build and test flows:

```shell
make -k TOOLCHAIN=clang-18 CONFIG=Tsan VERBOSE=1
# Configure build: default build production code + tests (BUILD_TESTING=ON by default).
$ 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: /path/to/Optional26/.build

# Build.
$ cmake --build .build --config Asan --target all -- -k 0
...
[30/30] Linking CXX executable ... # Note: 30 targets here (including tests).

# Run tests.
$ 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

Total Test time (real) = 0.67 sec
```

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.
##### Build Production, but 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).
$ 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: /path/to/Optional26/.build

# Build.
$ cmake --build .build --config Asan --target all -- -k 0
...
[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
Internal ctest changing into directory: /path/to/Beman.Optional26/.build
Test project /path/to/Beman.Optional26/.build
No tests were found!!!
```

## Papers

Expand Down
6 changes: 0 additions & 6 deletions extern/CMakeLists.txt

This file was deleted.

1 change: 0 additions & 1 deletion extern/googletest
Submodule googletest deleted from 305e5a
6 changes: 0 additions & 6 deletions src/Beman/CMakeLists.txt

This file was deleted.

Loading

0 comments on commit bfeb908

Please sign in to comment.