Skip to content

Commit 73d24a4

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

File tree

32 files changed

+800
-9
lines changed

32 files changed

+800
-9
lines changed

.bazelrc

Lines changed: 14 additions & 0 deletions
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

Lines changed: 14 additions & 0 deletions
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

Lines changed: 8 additions & 0 deletions
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

Lines changed: 31 additions & 0 deletions
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

Lines changed: 31 additions & 0 deletions
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

Lines changed: 18 additions & 0 deletions
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

Lines changed: 65 additions & 0 deletions
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

Lines changed: 16 additions & 0 deletions
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

Lines changed: 23 additions & 0 deletions
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+
)

0 commit comments

Comments
 (0)