Skip to content

Commit

Permalink
Merge branch 'merge-main-2' into normalize
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-downey committed Nov 4, 2024
2 parents 5491d8d + 9b6989c commit 8937387
Show file tree
Hide file tree
Showing 22 changed files with 345 additions and 230 deletions.
4 changes: 0 additions & 4 deletions .markdownlint.json

This file was deleted.

14 changes: 14 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# MD033/no-inline-html : Inline HTML : https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md033.md
# Disable inline html linter is needed for <details> <summary>
MD033: false

# MD013/line-length : Line length : https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md013.md
# Conforms to .clang-format ColumnLimit
# Update the comment in .clang-format if we no-longer tie these two column limits.
MD013:
line_length: 119

# MD024/no-duplicate-heading : https://github.com/DavidAnson/markdownlint/blob/main/doc/md024.md
# Supress warning about the same heading twice unless they are in the same block
MD024:
siblings_only: true
98 changes: 24 additions & 74 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,83 +2,33 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-json
- id: check-merge-conflict
- id: check-symlinks
- id: check-toml
- id: check-xml
- id: check-yaml
- id: detect-private-key
- id: end-of-file-fixer
exclude: '^(.*\.svg)$'
- id: mixed-line-ending
args: ['--fix=lf']
exclude: '^(.*\.svg)$'
- id: trailing-whitespace
exclude: '^(|.*\.svg)$'
- id: fix-byte-order-marker
- id: no-commit-to-branch
- id: requirements-txt-fixer

- repo: local
hooks:
- id: clang-format-fix
name: clang-format-fix
entry: clang-format-18
files: ^(src/|include/)
types_or: [c++, c]
language: system
args: ['-i']
stages: [manual]

- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

# Clang-format for C++
# This brings in a portable version of clang-format.
# See also: https://github.com/ssciwr/clang-format-wheel
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.8
hooks:
- id: clang-format
additional_dependencies: ['clang-format==18.1.8']
# - id: oclint
# - id: cppcheck
# - id: cpplint
- id: clang-format
types_or: [c++, c]

- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
# CMake linting and formatting
- repo: https://github.com/BlankSpruce/gersemi
rev: 0.15.1
hooks:
- id: clang-tidy
stages: [manual]
additional_dependencies: ['clang-tidy==18.1.8']
- id: gersemi
name: CMake linting

- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
# Markdown linting
# Config file: .markdownlint.yaml
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.41.0
hooks:
- id: codespell
args: ['-I', '.codespell_ignore', '--uri-ignore-words-list']
exclude: |
(?x)^(
papers/.*
)$
# # CMake formatting
# - repo: https://github.com/cheshirekow/cmake-format-precommit
# rev: "v0.6.13"
# hooks:
# - id: cmake-format
# additional_dependencies: [pyyaml]
# - id: cmake-lint

- repo: https://github.com/jorisroovers/gitlint
rev: v0.19.1
hooks:
- id: gitlint
- id: gitlint-ci

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.10.0.1
hooks:
- id: shellcheck

exclude: 'vendor'
- id: markdownlint
exclude: ^papers/
58 changes: 31 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

cmake_minimum_required(VERSION 3.27)

project(
beman_optional26
VERSION 0.0.0
LANGUAGES CXX)
project(beman_optional26 VERSION 0.0.0 LANGUAGES CXX)

# Includes
include(CTest)
Expand All @@ -17,13 +14,14 @@ 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
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG e39786088138f2749d64e9e90e0f9902daa77c40 # release-1.15.0
)
FetchContent_MakeAvailable(googletest)
# Fetch GoogleTest
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG
e39786088138f2749d64e9e90e0f9902daa77c40 # release-1.15.0
)
FetchContent_MakeAvailable(googletest)
endif()

add_subdirectory(src/beman/optional26)
Expand All @@ -34,33 +32,39 @@ include(GNUInstallDirs)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake)

install(
EXPORT ${TARGETS_EXPORT_NAME}
NAMESPACE ${CMAKE_PROJECT_NAME}
DESTINATION ${INSTALL_CONFIGDIR})
EXPORT ${TARGETS_EXPORT_NAME}
NAMESPACE ${CMAKE_PROJECT_NAME}
DESTINATION ${INSTALL_CONFIGDIR}
)

include(CMakePackageConfigHelpers)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion)
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)

configure_package_config_file(
"cmake/Config.cmake.in"
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR})
"cmake/Config.cmake.in"
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)

install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake
FILES
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${INSTALL_CONFIGDIR})
DESTINATION ${INSTALL_CONFIGDIR}
)

# Coverage
configure_file("cmake/gcovr.cfg.in" gcovr.cfg @ONLY)

add_custom_target(
process_coverage
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Running gcovr to process coverage results"
COMMAND mkdir -p coverage
COMMAND gcovr --config gcovr.cfg .)
process_coverage
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Running gcovr to process coverage results"
COMMAND mkdir -p coverage
COMMAND gcovr --config gcovr.cfg .
)
54 changes: 40 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ SPDX-License-Identifier: 2.0 license with LLVM exceptions

![CI Tests](https://github.com/beman-project/Optional26/actions/workflows/ci.yml/badge.svg)

This repository implements `std::optional` extensions targeting C++26. The `beman.optional26` library aims to evaluate the stability, the usability, and the performance of these proposed changes before they are officially adopted by WG21 into the C++ Working Draft. Additionally, it allows developers to use these new features before they are implemented in major standard library compilers.
This repository implements `std::optional` extensions targeting C++26. The `beman.optional26` library aims to evaluate
the stability, the usability, and the performance of these proposed changes before they are officially adopted by WG21
into the C++ Working Draft. Additionally, it allows developers to use these new features before they are implemented in
major standard library compilers.

**Implements**:

Expand Down Expand Up @@ -41,9 +44,11 @@ Documentation and associated papers are licensed with the Creative Commons Attri

// SPDX-License-Identifier: CC-BY-4.0

The intent is that the source and documentation are available for use by people implementing their own optional types as well as people using the optional presented here as-is.
The intent is that the source and documentation are available for use by people implementing their own optional types
as well as people using the optional presented here as-is.

The README itself is licensed with CC0 1.0 Universal. Copy the contents and incorporate in your own work as you see fit.
The README itself is licensed with CC0 1.0 Universal. Copy the contents and incorporate in your own work as you see
fit.

// SPDX-License-Identifier: CC0-1.0

Expand All @@ -53,7 +58,7 @@ Full runable examples can be found in `examples/` - please check [./examples/REA

### range_loop

The next code snippet shows optional range support added in [Give *std::optional* Range Support (P3168R2)](https://wg21.link/P3168R2):
The next code snippet shows optional range support added in [Give *std::optional* Range Support(P3168R2)](https://wg21.link/P3168R2):

```cpp
#include <Beman/Optional26/optional.hpp>
Expand All @@ -74,11 +79,13 @@ for (const auto& i : opt) {
}
```

Full code can be found in [./examples/range_loop.cpp](./examples/range_loop.cpp). Build and run instructions in [./examples/README.md](./examples/README.md). Or [try it on Compiler Explorer](https://godbolt.org/z/b5ThEqqhf).
Full code can be found in [./examples/range_loop.cpp](./examples/range_loop.cpp). Build and run instructions in
[./examples/README.md](./examples/README.md). Or [try it on Compiler Explorer](https://godbolt.org/z/b5ThEqqhf).

### optional_ref

The next code snippet shows optional reference support added in [`std::optional<T&>` (P2988R5)](https://wg21.link/P2988R5):
The next code snippet shows optional reference support added in [`std::optional<T&>`
(P2988R5)](https://wg21.link/P2988R5):

```cpp
#include <Beman/Optional26/optional.hpp>
Expand Down Expand Up @@ -117,7 +124,8 @@ Default build: `C++23`. Please check `etc/${compiler}-flags.cmake`.

### Dependencies

This project is mainly tested on `Ubuntu 22.04` and `Ubuntu 24.04`, but it should be as portable as CMake is. This project has no C or C++ dependencies.
This project is mainly tested on `Ubuntu 22.04` and `Ubuntu 24.04`, but it should be as portable as CMake is. This
project has no C or C++ dependencies.

Build-time dependencies:

Expand All @@ -143,7 +151,8 @@ Full set of supported toolchains can be found in [.github/workflows/ci.yml](.git

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

```shell
# List available preset configurations:
Expand Down Expand Up @@ -194,7 +203,10 @@ CI current build and test flows:

```shell
# 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 .
$ 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
Expand All @@ -220,7 +232,11 @@ 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).
$ cmake -G "Ninja Multi-Config" -DCMAKE_CONFIGURATION_TYPES="RelWithDebInfo;Asan" -DCMAKE_TOOLCHAIN_FILE=etc/clang-19-toolchain.cmake -DBUILD_TESTING=OFF -B .build -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: /path/to/Optional26/.build
Expand All @@ -238,11 +254,18 @@ No tests were found!!!
```

#### Pre-Commit for Linting
Various linting tools are configured and installed via the [pre-commit](https://pre-commit.com/) framework. This requires a working python environment, but also allows the tools, such as clang-format and cmake-lint, to be versioned on a per project basis rather than being installed globally. Version changes in lint checks often means differences in success or failure between the versions in CI and the versions used by a developer. By using the same configurations, this problem is avoided.

In order to set up a python environment, using a python virtual environment can simplify maintaining different configurations between projects. There is no particular dependency on a particular python3 version.
Various linting tools are configured and installed via the [pre-commit](https://pre-commit.com/) framework. This
requires a working python environment, but also allows the tools, such as clang-format and cmake-lint, to be versioned
on a per project basis rather than being installed globally. Version changes in lint checks often means differences in
success or failure between the versions in CI and the versions used by a developer. By using the same configurations,
this problem is avoided.

In order to set up a python environment, using a python virtual environment can simplify maintaining different
configurations between projects. There is no particular dependency on a particular python3 version.

##### Creating and configuring a venv

```shell
python3 -m venv .venv
. .venv/bin/activate && python3 -m pip install --upgrade pip setuptools wheel
Expand All @@ -252,9 +275,11 @@ python3 -m venv .venv
. .venv/bin/activate && exec bash
```

This will create the venv, install the python and python development tools, and run bash with the PATH and other environment variables set to use the venv preferentially.
This will create the venv, install the python and python development tools, and run bash with the PATH and other
environment variables set to use the venv preferentially.

##### Running the linting tools

```shell
pre-commit run -a
```
Expand All @@ -271,7 +296,8 @@ make lint

Latest revision(s) of the papers can be built / found at:

* [give-std-optional-range-support](https://github.com/neatudarius/give-std-optional-range-support/) for `Give *std::optional* Range Support (P3168)`
* [give-std-optional-range-support](https://github.com/neatudarius/give-std-optional-range-support/) for
`Give *std::optional* Range Support (P3168)`
* issue: [#1831](https://github.com/cplusplus/papers/issues/1831)
* LEWG:
* Reviewed in Tokyo 2024.
Expand Down
3 changes: 2 additions & 1 deletion docs/debug-ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ SPDX-License-Identifier: 2.0 license with LLVM exceptions

## CI flows

CI flows are found in [.github/workflows/](.github/workflows/). Usually, they are run when generating a Git Action (e.g. at `push`).
CI flows are found in [.github/workflows/](.github/workflows/). Usually, they
are run when generating a Git Action (e.g. at `push`).

WIP to add flows for tests, linting etc.

Expand Down
Loading

0 comments on commit 8937387

Please sign in to comment.