Skip to content

Commit 73d24a4

Browse files
committed
tooling: Add Bazel support
1 parent 3b7bf9d commit 73d24a4

32 files changed

+800
-9
lines changed

.bazelrc

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
common --enable_bzlmod
2+
common --registry=https://bcr.bazel.build
3+
try-import %workspace%/.bazelrc.user
4+
5+
# bazel from apt needs access to this cacerts location
6+
startup --host_jvm_args=-Djavax.net.ssl.trustStore=/etc/ssl/certs/java/cacerts
7+
8+
# So we can support private dependencies
9+
build --experimental_cc_implementation_deps
10+
11+
build --action_env=BAZEL_CXXOPTS="-std=c++17"
12+
build --strip=never
13+
build --copt='-O2'
14+
build --conlyopt='-std=c11'

.gitignore

+14
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,17 @@ callgrind.out.*
5858
# Miscellaneous
5959
*.log
6060
/.gtm/
61+
62+
# Ignore all bazel-* symlinks. There is no full list since this can change
63+
# based on the name of the directory bazel is cloned into.
64+
/bazel-*
65+
MODULE.bazel.lock
66+
.bazelrc.user
67+
external/
68+
69+
# Directories for the Bazel IntelliJ plugin containing the generated
70+
# IntelliJ project files and plugin configuration. Seperate directories are
71+
# for the IntelliJ, Android Studio and CLion versions of the plugin.
72+
/.ijwb/
73+
/.aswb/
74+
/.clwb/

BUILD.bazel

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
load("//:plugin.bzl", "CLOE_PLUGINS")
2+
3+
sh_binary(
4+
name = "cloe_shell",
5+
srcs = ["cloe_shell.sh"],
6+
args = ["$(location //engine:cloe-engine)"] + ["$(location {})".format(p) for p in CLOE_PLUGINS],
7+
data = ["//engine:cloe-engine"] + CLOE_PLUGINS + glob(["tests/*"]),
8+
)

MODULE.bazel

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module(name = "cloe", version = "0.25.0")
2+
3+
# Build dependencies:
4+
bazel_dep(name = "cmake_configure_file", version = "0.1.0")
5+
bazel_dep(name = "rules_cc", version = "0.0.9")
6+
7+
# Test dependencies:
8+
bazel_dep(name = "googletest", version = "1.14.0", repo_name = "gtest")
9+
10+
# Library dependencies:
11+
bazel_dep(name = "boost", version = "1.83.0.bcr.1")
12+
bazel_dep(name = "cli11", version = "2.3.2")
13+
bazel_dep(name = "eigen", version = "3.4.0.bcr.1")
14+
bazel_dep(name = "fmt", version = "10.2.1")
15+
bazel_dep(name = "incbin", version = "20211106.0")
16+
bazel_dep(name = "inja", version = "3.4.0")
17+
bazel_dep(name = "lua", version = "5.4.6")
18+
bazel_dep(name = "nlohmann_json", version = "3.11.3")
19+
bazel_dep(name = "oatpp", version = "1.3.0")
20+
bazel_dep(name = "sol", version = "3.3.1")
21+
bazel_dep(name = "spdlog", version = "1.13.0")
22+
bazel_dep(name = "open-simulation-interface", version = "3.5.0")
23+
bazel_dep(name = "protobuf", version = "26.0")
24+
25+
# Tooling dependencies:
26+
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
27+
git_override(
28+
module_name = "hedron_compile_commands",
29+
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
30+
commit = "1e08f8e0507b6b6b1f4416a9a22cf5c28beaba93", # 2024-07-04
31+
)

README.md

+31
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,37 @@ When using `make` to build the project, add this to the command line:
194194
195195
CONAN_OPTIONS="-c tools.build:skip_test=1"
196196
197+
## Building with Bazel
198+
199+
Bazel tooling is currently experimental, and is meant to support users
200+
who already are using Bazel in their projects and are not afraid of
201+
providing their own registries and modules for Cloe's dependencies.
202+
203+
(That allows us to not have to vendor massive amounts of Bazel modules
204+
in this repository, of which Boost is the main problematic point.
205+
Once Boost makes it into the Bazel Central Registry, it may be worthwhile
206+
to vendor the remaining libraries in this repository.)
207+
208+
You will need to create a `.bazelrc.user` file in the repository root
209+
with the following contents:
210+
211+
common --registry=file:///path/to/your/bazel/registry
212+
213+
This file is ignored by Git to prevent you from exposing your secrets.
214+
The registry should contain the following modules:
215+
216+
boost
217+
cli11
218+
esmini
219+
incbin
220+
inja
221+
luajit (optional)
222+
oatpp
223+
open-simulation-interface
224+
sol
225+
226+
The rest of the dependencies are taken from the Bazel Central Registry.
227+
See `MODULE.bazel` for the full list.
197228
198229
### Building Docker Images
199230

WORKSPACE.bazel

Whitespace-only changes.

cloe_shell.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
export CLOE_LOG_LEVEL=debug
4+
export CLOE_STRICT_MODE=1
5+
export CLOE_ROOT="$(pwd)"
6+
export CLOE_ENGINE="${CLOE_ROOT}/$1"
7+
export CLOE_LUA_PATH="${CLOE_ROOT}/engine/lua"
8+
export PATH="$(dirname "$CLOE_ENGINE"):$PATH"
9+
10+
# Set plugin paths
11+
shift 1
12+
while [[ $# -ne 0 ]]; do
13+
CLOE_PLUGIN_PATH="${CLOE_ROOT}/$(dirname "$1"):$CLOE_PLUGIN_PATH"
14+
shift 1
15+
done
16+
export CLOE_PLUGIN_PATH
17+
18+
exec $SHELL

engine/BUILD.bazel

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
load("//:version.bzl", "PROJECT_VERSION")
2+
3+
cc_library(
4+
name = "enginelib",
5+
hdrs = glob(["src/**/*.hpp"], exclude=["src/main*.hpp"]),
6+
srcs = glob(
7+
["src/**/*.cpp"],
8+
exclude=[
9+
"src/main*.cpp",
10+
"src/**/*_test.cpp",
11+
"src/server_mock.cpp",
12+
]
13+
),
14+
data = glob(["lua/**"]),
15+
includes = ["src"],
16+
additional_compiler_inputs = glob(["webui/**"]),
17+
deps = [
18+
"//engine/vendor/lrdb",
19+
"//engine/vendor/linenoise",
20+
"//stack",
21+
"//fable",
22+
"//runtime",
23+
"//models",
24+
"//oak",
25+
"@boost//:algorithm",
26+
"@boost//:conversion",
27+
"@boost//:optional",
28+
"@boost//:process",
29+
"@boost//:uuid",
30+
"@sol",
31+
],
32+
defines = [
33+
"CLOE_ENGINE_VERSION=\\\"{}\\\"".format(PROJECT_VERSION),
34+
"CLOE_ENGINE_TIMESTAMP=\\\"unknown\\\"",
35+
"CLOE_ENGINE_WITH_SERVER=1",
36+
"CLOE_ENGINE_WITH_LRDB=1",
37+
"PROJECT_SOURCE_DIR=\\\"engine\\\"",
38+
],
39+
linkopts = [
40+
"-lpthread",
41+
],
42+
)
43+
44+
cc_test(
45+
name = "engine_test",
46+
srcs = glob(["src/**/*_test.cpp"]),
47+
defines = [
48+
"CLOE_LUA_PATH=\\\"" + package_name() + "/lua\\\"",
49+
],
50+
deps = [
51+
":enginelib",
52+
"@gtest//:gtest_main",
53+
],
54+
)
55+
56+
cc_binary(
57+
name = "cloe-engine",
58+
srcs = glob(["src/main*.hpp", "src/main*.cpp"]),
59+
includes = ["src"],
60+
deps = [
61+
":enginelib",
62+
"@cli11",
63+
],
64+
visibility = ["//visibility:public"],
65+
)

engine/vendor/linenoise/BUILD.bazel

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
cc_library(
2+
name = "linenoise",
3+
hdrs = ["linenoise.h"],
4+
srcs = ["linenoise.c"],
5+
includes = ["."],
6+
local_defines = [
7+
"__STDC_WANT_LIB_EXT2__=1",
8+
],
9+
visibility = ["//visibility:public"],
10+
)
11+
12+
cc_test(
13+
name = "linenoise_example",
14+
srcs = ["example.c"],
15+
deps = [":linenoise"],
16+
)

engine/vendor/lrdb/BUILD.bazel

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
cc_library(
2+
name = "lrdb",
3+
hdrs = glob(["include/**/*.hpp"]),
4+
includes = ["include"],
5+
defines = [
6+
"LRDB_USE_BOOST_ASIO=1",
7+
],
8+
deps = [
9+
":picojson",
10+
"@lua",
11+
"@boost//:asio",
12+
],
13+
linkopts = [
14+
"-lpthread",
15+
],
16+
visibility = ["//visibility:public"],
17+
)
18+
19+
cc_library(
20+
name = "picojson",
21+
hdrs = ["third_party/picojson/picojson.h"],
22+
includes = ["third_party/picojson"],
23+
)

fable/BUILD.bazel

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
load(
2+
"@cmake_configure_file//:cmake_configure_file.bzl",
3+
"cmake_configure_file",
4+
)
5+
load("//:version.bzl", "PROJECT_VERSION", "PROJECT_VERSION_U32")
6+
7+
cmake_configure_file(
8+
name = "fable_version_hpp",
9+
src = "src/fable/version.hpp.in",
10+
out = "include/fable/version.hpp",
11+
defines = [
12+
"FABLE_VERSION={}".format(PROJECT_VERSION),
13+
"FABLE_VERSION_U32={}".format(PROJECT_VERSION_U32),
14+
]
15+
)
16+
17+
cc_library(
18+
name = "fable",
19+
srcs = glob(["src/**/*.cpp"], exclude=["src/**/*_test.cpp"]),
20+
hdrs = glob(["include/**/*.hpp"]) + [":fable_version_hpp"],
21+
includes = [ "include" ],
22+
deps = [
23+
"@fmt",
24+
"@nlohmann_json//:json",
25+
],
26+
visibility = ["//visibility:public"],
27+
)
28+
29+
cc_test(
30+
name = "fable_test",
31+
srcs = glob(["src/**/*_test.cpp"]),
32+
deps = [
33+
":fable",
34+
"@sol",
35+
"@boost//:optional",
36+
"@gtest//:gtest_main",
37+
],
38+
)

fable/examples/contacts/BUILD.bazel

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
filegroup(
2+
name = "inputs",
3+
srcs = [
4+
"example_addressbook.json",
5+
"invalid_addressbook.json",
6+
]
7+
)
8+
9+
cc_binary(
10+
name = "contacts",
11+
srcs = [
12+
"src/main.cpp",
13+
],
14+
deps = [
15+
"//fable",
16+
"@cli11",
17+
],
18+
data = [
19+
":inputs",
20+
]
21+
)
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
filegroup(
2+
name = "inputs",
3+
srcs = [
4+
"example_input.json",
5+
]
6+
)
7+
8+
cc_binary(
9+
name = "simple_config",
10+
srcs = [
11+
"src/main.cpp",
12+
],
13+
deps = [
14+
"//fable",
15+
"@cli11",
16+
],
17+
data = [
18+
":inputs",
19+
]
20+
)

models/BUILD.bazel

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
cc_library(
2+
name = "models",
3+
hdrs = glob(["include/**/*.hpp"]),
4+
srcs = glob(["src/**/*.cpp"], exclude=["src/**/*_test.cpp"]),
5+
includes = [ "include" ],
6+
deps = [
7+
"//runtime",
8+
"@boost//:optional",
9+
"@eigen",
10+
],
11+
visibility = ["//visibility:public"],
12+
)
13+
14+
cc_test(
15+
name = "models_test",
16+
srcs = glob(["src/**/*_test.cpp"]),
17+
deps = [
18+
":models",
19+
"@gtest//:gtest_main",
20+
],
21+
)

oak/BUILD.bazel

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
cc_library(
2+
name = "oak",
3+
hdrs = glob(["include/**/*.hpp"]),
4+
srcs = glob(["src/**"], exclude=["src/**/*_test.cpp"]),
5+
includes = [ "include" ],
6+
deps = [
7+
"//runtime",
8+
"@oatpp",
9+
],
10+
visibility = ["//visibility:public"],
11+
)
12+
13+
cc_test(
14+
name = "models_test",
15+
srcs = glob(["src/**/*_test.cpp", "src/**/*.hpp"]),
16+
deps = [
17+
":oak",
18+
"@gtest//:gtest_main",
19+
],
20+
)

oak/src/oak/registrar.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* \see oak/registrar.hpp
2121
*/
2222

23-
#include "oak/registrar.hpp"
23+
#include <oak/registrar.hpp>
2424

2525
#include <map>
2626
#include <memory>
@@ -30,8 +30,9 @@
3030

3131
#include <cloe/handler.hpp> // for Request, Response, Handler
3232

33-
#include "oak/request_stub.hpp" // for RequestStub
34-
#include "oak/server.hpp" // for Server
33+
#include <oak/server.hpp> // for Server
34+
35+
#include "request_stub.hpp" // for RequestStub
3536

3637
namespace oak {
3738

oak/src/oak/route_muxer_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include <vector> // for vector<>
2929
using namespace std; // NOLINT(build/namespaces)
3030

31-
#include "oak/route_muxer.hpp" // for Muxer<>
31+
#include <oak/route_muxer.hpp> // for Muxer<>
3232
using oak::Muxer;
3333
using oak::Parameters;
3434

0 commit comments

Comments
 (0)