Skip to content

Commit cc43d2c

Browse files
Create dev environment (#75)
* Create dev environment * Add chain example * Format and tidy files
1 parent 4b8a5d9 commit cc43d2c

31 files changed

+325
-194
lines changed

.clang-format

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
1+
Standard: c++11
12
BasedOnStyle: Google
23
IndentWidth: 4
34
Language: Cpp
45
PointerAlignment: Left
56
BreakBeforeBraces: Stroustrup
67
ColumnLimit: 120
8+
IncludeCategories:
9+
# Header file associated with cpp file (default)
10+
11+
# gtest/gmock headers
12+
- Regex: "^<gtest/.*>"
13+
Priority: 1
14+
- Regex: "^<gmock/.*>"
15+
Priority: 1
16+
17+
# Local/private headers included with ""
18+
- Regex: '^"([^/]+/)*[^/]+\.hpp"$'
19+
Priority: 2
20+
- Regex: '^"([^/]+/)*[^/]+\.h"$'
21+
Priority: 2
22+
23+
# External headers included with <>
24+
- Regex: '^<.*\.hpp>$'
25+
Priority: 3
26+
- Regex: '^<.*\.h>$'
27+
Priority: 3
28+
29+
# Standard library headers
30+
- Regex: "^<.*>$"
31+
Priority: 4

.devcontainer/Dockerfile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
FROM ubuntu:24.04
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
5+
RUN apt-get update && apt-get install -y \
6+
bash-completion \
7+
build-essential \
8+
cmake \
9+
clang \
10+
clangd \
11+
clang-format \
12+
clang-tidy \
13+
curl \
14+
doxygen \
15+
gdb \
16+
git \
17+
graphviz \
18+
lcov \
19+
lldb \
20+
llvm \
21+
nano \
22+
software-properties-common \
23+
sudo \
24+
unzip \
25+
wget \
26+
&& apt-get clean \
27+
&& rm -rf /var/lib/apt/lists/*
28+
29+
ARG USERNAME=ubuntu
30+
RUN passwd -d ${USERNAME} \
31+
&& mkdir -p /home/${USERNAME}/.cache && chown -R ${USERNAME}:${USERNAME} /home/${USERNAME}/.cache \
32+
&& SNIPPET="export PROMPT_COMMAND='history -a' && export HISTFILE=/home/${USERNAME}/.cache/.bash_history" \
33+
&& echo "$SNIPPET" >> "/home/${USERNAME}/.bashrc"
34+
35+
USER $USERNAME
36+
37+
WORKDIR /workspace

.devcontainer/devcontainer.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "C++ Channel",
3+
"dockerFile": "Dockerfile",
4+
"customizations": {
5+
"vscode": {
6+
"extensions": [
7+
"ms-vscode.cmake-tools",
8+
"streetsidesoftware.code-spell-checker",
9+
"DavidAnson.vscode-markdownlint",
10+
"xaver.clang-format",
11+
"twxs.cmake",
12+
"fredericbonnet.cmake-test-adapter",
13+
"llvm-vs-code-extensions.vscode-clangd",
14+
"vadimcn.vscode-lldb"
15+
]
16+
}
17+
},
18+
"mounts": [
19+
"source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=cached",
20+
"source=${env:HOME}/.ssh,target=/home/ubuntu/.ssh,type=bind,consistency=cached",
21+
"source=cache,target=/home/ubuntu/.cache,type=volume"
22+
],
23+
"workspaceFolder": "/workspace",
24+
"remoteUser": "ubuntu"
25+
}

.github/workflows/cmake.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ on:
55
branches:
66
- master
77
paths-ignore:
8+
- '.devcontainer/**'
89
- '.vscode/**'
910
- 'LICENSE'
11+
- 'Makefile'
1012
- '**/README.md'
1113
pull_request:
1214
paths-ignore:
15+
- '.devcontainer/**'
1316
- '.vscode/**'
1417
- 'LICENSE'
18+
- 'Makefile'
1519
- '**/README.md'
1620
workflow_dispatch:
1721

@@ -129,7 +133,7 @@ jobs:
129133
- uses: actions/checkout@v4
130134

131135
- name: Run Clang Format
132-
run: clang-format --dry-run --Werror $(find include -type f)
136+
run: clang-format --dry-run --Werror $(find include tests examples -type f -name *.*pp)
133137

134138
clang-tidy:
135139
name: Clang Tidy

.vscode/extensions.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
{
22
"recommendations": [
3-
"ms-vscode.cpptools",
4-
"ms-vscode.cpptools-extension-pack",
5-
"xaver.clang-format",
6-
"twxs.cmake",
7-
"fredericbonnet.cmake-test-adapter",
8-
"ms-vscode.cmake-tools",
9-
"notskm.clang-tidy",
3+
"ms-vscode-remote.remote-containers",
104
]
115
}

.vscode/launch.json

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,15 @@
22
"version": "0.2.0",
33
"configurations": [
44
{
5-
"name": "(gdb) Launch",
6-
"type": "cppdbg",
5+
"name": "Launch (LLDB)",
6+
"type": "lldb",
77
"request": "launch",
88
"program": "${command:cmake.launchTargetPath}",
9-
"args": [],
10-
"stopAtEntry": false,
11-
"cwd": "${workspaceFolder}",
12-
"environment": [
13-
{
14-
"name": "PATH",
15-
"value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}"
16-
}
9+
"args": [
10+
"--gtest_color=yes"
1711
],
18-
"MIMode": "gdb",
19-
"setupCommands": [
20-
{
21-
"description": "Enable pretty-printing for gdb",
22-
"text": "-enable-pretty-printing",
23-
"ignoreFailures": true
24-
}
25-
]
12+
"cwd": "${workspaceFolder}",
13+
"terminal": "integrated"
2614
}
2715
]
2816
}

.vscode/settings.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@
66
"-DCPP_CHANNEL_SANITIZERS=ON",
77
"-DCPP_CHANNEL_SANITIZE_THREADS=OFF",
88
"-DCMAKE_CXX_STANDARD=11",
9-
"-DCMAKE_INSTALL_PREFIX=${workspaceFolder}/install",
9+
"-DCMAKE_INSTALL_PREFIX=${workspaceFolder}/install"
1010
],
11-
"clang-tidy.fixOnSave": false,
12-
"clang-tidy.lintOnSave": false,
1311
"editor.formatOnSave": true,
1412
"clang-format.executable": "clang-format",
1513
"clang-format.style": "file",
1614
"editor.defaultFormatter": "xaver.clang-format",
1715
"files.insertFinalNewline": true,
18-
"files.trimFinalNewlines": true
16+
"files.trimFinalNewlines": true,
17+
"[jsonc]": {
18+
"editor.defaultFormatter": "vscode.json-language-features"
19+
},
20+
"clangd.arguments": [
21+
"--compile-commands-dir=${workspaceFolder}/build",
22+
"--background-index",
23+
"--clang-tidy"
24+
]
1925
}

Makefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
all:
2+
3+
bench:
4+
- sudo cpupower frequency-set --governor performance
5+
6+
mkdir -p build/bench && cd build/bench \
7+
&& cmake ../.. -DCMAKE_BUILD_TYPE=Release -DCPP_CHANNEL_BUILD_TESTS=ON \
8+
&& cmake --build . --config Release --target channel_benchmark -j \
9+
&& ./tests/channel_benchmark
10+
11+
- sudo cpupower frequency-set --governor powersave
12+
13+
coverage:
14+
mkdir -p build/coverage && cd build/coverage \
15+
&& cmake ../.. -DCMAKE_BUILD_TYPE=Debug -DCPP_CHANNEL_BUILD_TESTS=ON -DCPP_CHANNEL_COVERAGE=ON \
16+
&& cmake --build . --config Debug --target channel_tests -j \
17+
&& ctest -C Debug --verbose -L channel_tests --output-on-failure -j \
18+
&& lcov --capture --directory . --output-file coverage.info --ignore-errors mismatch \
19+
&& lcov --remove coverage.info "*/usr/*" -o coverage.info \
20+
&& lcov --remove coverage.info "*/gtest/*" -o coverage.info \
21+
&& genhtml coverage.info --output-directory coverage-report \
22+
&& cd coverage-report \
23+
&& python3 -m http.server 8000
24+
25+
doc:
26+
doxygen
27+
cd docs && python3 -m http.server 8000

README.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ Exceptions:
5252
* Range-based for loop supported.
5353
* Close to prevent pushing and stop waiting to fetch.
5454
* Integrates with some of the STL algorithms. Eg:
55-
* `std::move(ch.begin(), ch.end(), ...)`
56-
* `std::transform(input_chan.begin(), input_chan.end(), msd::back_inserter(output_chan))`.
57-
* `std::copy_if(chan.begin(), chan.end(), ...);`
55+
* `std::move(ch.begin(), ch.end(), ...)`
56+
* `std::transform(input_chan.begin(), input_chan.end(), msd::back_inserter(output_chan))`.
57+
* `std::copy_if(chan.begin(), chan.end(), ...);`
5858

5959
## Installation
6060

@@ -63,6 +63,7 @@ Choose one of the methods:
6363
* Copy the [include](https://github.com/andreiavrammsd/cpp-channel/tree/master/include) directory into your project and add it to your include path.
6464
* [CMake FetchContent](https://github.com/andreiavrammsd/cpp-channel/tree/master/examples/cmake-project)
6565
* [CMake install](https://cmake.org/cmake/help/latest/command/install.html) - choose a [version](https://github.com/andreiavrammsd/cpp-channel/releases), then run:
66+
6667
```shell
6768
VERSION=X.Y.Z \
6869
&& wget https://github.com/andreiavrammsd/cpp-channel/archive/refs/tags/v$VERSION.zip \
@@ -72,6 +73,7 @@ VERSION=X.Y.Z \
7273
&& cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local \
7374
&& sudo cmake --install .
7475
```
76+
7577
* [Bazel](https://github.com/andreiavrammsd/cpp-channel/tree/master/examples/bazel-project)
7678

7779
## Usage
@@ -84,16 +86,17 @@ VERSION=X.Y.Z \
8486
int main() {
8587
msd::channel<int> chan; // Unbuffered
8688

87-
int in = 1;
88-
int out = 0;
89-
9089
// Send to channel
91-
chan << in;
90+
chan << 1 << 2;
9291

9392
// Read from channel
94-
chan >> out;
93+
int first{};
94+
int second{};
95+
96+
chan >> first >> second;
9597

96-
assert(out == 1);
98+
assert(first == 1);
99+
assert(second == 2);
97100
}
98101
```
99102

@@ -178,6 +181,6 @@ See [examples](https://github.com/andreiavrammsd/cpp-channel/tree/master/example
178181

179182
* In some cases, the integration with some STL algorithms does not compile with MSVC. See the [Transform test](https://github.com/andreiavrammsd/cpp-channel/blob/master/tests/channel_test.cpp).
180183

181-
<br>
184+
---
182185

183186
Developed with [CLion](https://www.jetbrains.com/?from=serializer) and [Visual Studio Code](https://code.visualstudio.com/).

examples/.clang-tidy

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
InheritParentConfig: true
2+
3+
Checks: >
4+
-cppcoreguidelines-avoid-magic-numbers,
5+
-readability-magic-numbers,
6+
-fuchsia-default-arguments-calls
7+
8+
CheckOptions:
9+
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
10+
- { key: readability-identifier-length.MinimumVariableNameLength, value: '1' }

0 commit comments

Comments
 (0)