Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/bazel-project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bazel-*
8 changes: 8 additions & 0 deletions examples/bazel-project/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cc_binary(
name = "bazel-project",
srcs = ["src/main.cpp"],
deps = [
"@msd.channel",
],
copts = ["--std=c++17"],
)
26 changes: 26 additions & 0 deletions examples/bazel-project/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
bazel_dep(name = "msd.channel")

msd_channel_module = """module(
name = "msd.channel",

)"""

msd_channel_build = """package(default_visibility = ["//visibility:public"])

cc_library(
name = "msd.channel",
includes = ["include"],
hdrs = glob(["include/**/*.*"]),
)
"""

archive_override(
module_name = "msd.channel",
patch_cmds = [
"echo '" + msd_channel_module + "' > MODULE.bazel",
"echo '" + msd_channel_build + "' > BUILD.bazel",
],
urls = ["https://github.com/andreiavrammsd/cpp-channel/archive/refs/tags/v0.8.3.zip"],
strip_prefix = "cpp-channel-0.8.3",
integrity = "sha256-CVEC3XvmoghyBvwi7C4ytOtofyX41X02NVKQ/7ID5Nc=",
)
15 changes: 15 additions & 0 deletions examples/bazel-project/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# CMake project

Example of using C++ Channel in a project with Bazel.

## Requirements
* C++11 compiler
* Bazel

## Build and run

```shell script
bazel run //:bazel-project

docker run --rm -ti -v $PWD:/app -w /app --name bazel-project gcr.io/bazel-public/bazel:8.0.1 run //:bazel-project
```
35 changes: 35 additions & 0 deletions examples/bazel-project/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <cstddef>
#include <iostream>

#include "msd/channel.hpp"

int main()
{
constexpr std::size_t kChannelSize = 10;
msd::channel<int> chan{kChannelSize};

int input{};

try {
input = 1;
chan << input;

input = 2;
chan << input;

input = 3;
chan << input;
}
catch (const msd::closed_channel& ex) {
std::cout << ex.what() << '\n';
return 1;
}

for (auto out : chan) {
std::cout << out << '\n';

if (chan.empty()) {
break;
}
}
}