Skip to content

Commit 87181a2

Browse files
committed
Add Bazel build support.
1 parent ffb8830 commit 87181a2

10 files changed

+126
-17
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
.ycm_extra_conf.py
22
build/
33
Testing/
4+
bazel-bin
5+
bazel-out
6+
bazel-task_graph
7+
bazel-testlogs

BUILD.bazel

Whitespace-only changes.

WORKSPACE

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
workspace(name = "ofats_task_graph")
2+
3+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
5+
http_archive(
6+
name = "catch2",
7+
sha256 = "ff0857d50f75719c1ea309f8690f448d26fe5ed209c6f84020bd6a808a0eac7a",
8+
strip_prefix = "Catch2-b9853b4b356b83bb580c746c3a1f11101f9af54f",
9+
# v3.0.0-preview3
10+
url = "https://github.com/catchorg/catch2/archive/b9853b4b356b83bb580c746c3a1f11101f9af54f.zip",
11+
)

future/BUILD.bazel

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
cc_library(
4+
name = "future",
5+
hdrs = ["future.h"],
6+
copts = ["-std=c++17"],
7+
# TODO(ofats): pthread linking should be conditional on platform
8+
linkopts = ["-pthread"],
9+
linkstatic = True,
10+
)
11+
12+
cc_test(
13+
name = "future_test",
14+
srcs = ["ut/future_ut.cpp"],
15+
copts = ["-std=c++17"],
16+
deps = [
17+
":future",
18+
"@catch2//:catch2_main",
19+
],
20+
)

future/ut/future_ut.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#include "future/future.h"
2-
#include "catch/catch.h"
3-
41
#include <iostream>
52
#include <sstream>
63

4+
#include "catch2/catch_all.hpp"
5+
#include "future/future.h"
6+
77
TEST_CASE("test_then", "[advanced_future]") {
88
auto future = my_async([](int a, int b) { return a + b; }, 3, 4)
99
.then([](int c, int d) { return c * d; }, 5);

meta/BUILD.bazel

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
cc_library(
4+
name = "meta",
5+
hdrs = ["type_pack.h"],
6+
copts = ["-std=c++17"],
7+
linkstatic = True,
8+
)

task_runner/BUILD.bazel

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
cc_library(
4+
name = "event",
5+
hdrs = ["event.h"],
6+
copts = ["-std=c++17"],
7+
# TODO(ofats): pthread linking should be conditional on platform
8+
linkopts = ["-pthread"],
9+
linkstatic = True,
10+
)
11+
12+
cc_library(
13+
name = "task_runner",
14+
srcs = ["task_system.cpp"],
15+
hdrs = [
16+
"task_runner.h",
17+
"task_system.h",
18+
],
19+
copts = ["-std=c++17"],
20+
# TODO(ofats): pthread linking should be conditional on platform
21+
linkopts = ["-pthread"],
22+
linkstatic = True,
23+
)
24+
25+
cc_library(
26+
name = "task_graph",
27+
hdrs = ["task_graph.h"],
28+
copts = ["-std=c++17"],
29+
linkstatic = True,
30+
deps = [
31+
":event",
32+
],
33+
)
34+
35+
cc_test(
36+
name = "task_system_test",
37+
srcs = ["ut/task_system_ut.cpp"],
38+
copts = ["-std=c++17"],
39+
deps = [
40+
":event",
41+
":task_runner",
42+
"@catch2//:catch2_main",
43+
],
44+
)
45+
46+
cc_test(
47+
name = "task_runner_test",
48+
srcs = ["ut/task_runner_ut.cpp"],
49+
copts = ["-std=c++17"],
50+
deps = [
51+
":event",
52+
":task_runner",
53+
"@catch2//:catch2_main",
54+
],
55+
)
56+
57+
cc_test(
58+
name = "task_graph_test",
59+
srcs = ["ut/task_runner_ut.cpp"],
60+
copts = ["-std=c++17"],
61+
deps = [
62+
":event",
63+
":task_graph",
64+
":task_runner",
65+
"@catch2//:catch2_main",
66+
],
67+
)

task_runner/ut/task_graph_ut.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
#include "task_runner/task_graph.h"
2-
#include "task_runner/task_runner.h"
3-
41
#include <numeric>
52
#include <set>
63

7-
#include "catch/catch.h"
4+
#include "catch2/catch_all.hpp"
85
#include "task_runner/event.h"
6+
#include "task_runner/task_graph.h"
7+
#include "task_runner/task_runner.h"
98

109
namespace tg = base::task_graph;
1110

task_runner/ut/task_runner_ut.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
#include "task_runner/task_runner.h"
2-
31
#include <iostream>
42

5-
#include "catch/catch.h"
3+
#include "catch2/catch_all.hpp"
64
#include "task_runner/event.h"
5+
#include "task_runner/task_runner.h"
76

87
namespace {
98

@@ -60,10 +59,12 @@ TEMPLATE_PRODUCT_TEST_CASE("task_runner_test", "[task_runner]",
6059
SECTION("Task can be lambda with args") {
6160
int result = 0;
6261
base::manual_event event;
63-
task_runner.run([&](int a, int b, int c) {
64-
result = a + b + c;
65-
event.notify();
66-
}, 1, 2, 3);
62+
task_runner.run(
63+
[&](int a, int b, int c) {
64+
result = a + b + c;
65+
event.notify();
66+
},
67+
1, 2, 3);
6768
event.wait();
6869
REQUIRE(result == 1 + 2 + 3);
6970
}

task_runner/ut/task_system_ut.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
#include "task_runner/task_system.h"
2-
31
#include <iostream>
42

5-
#include "catch/catch.h"
3+
#include "catch2/catch_all.hpp"
64
#include "task_runner/event.h"
5+
#include "task_runner/task_system.h"
76

87
namespace {
98

0 commit comments

Comments
 (0)