Skip to content

Commit

Permalink
tooling: Add Bazel support
Browse files Browse the repository at this point in the history
  • Loading branch information
cassava committed Jul 12, 2024
1 parent 6396945 commit 2cdac8c
Show file tree
Hide file tree
Showing 32 changed files with 800 additions and 9 deletions.
14 changes: 14 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
common --enable_bzlmod
common --registry=https://bcr.bazel.build
try-import %workspace%/.bazelrc.user

# bazel from apt needs access to this cacerts location
startup --host_jvm_args=-Djavax.net.ssl.trustStore=/etc/ssl/certs/java/cacerts

# So we can support private dependencies
build --experimental_cc_implementation_deps

build --action_env=BAZEL_CXXOPTS="-std=c++17"
build --strip=never
build --copt='-O2'
build --conlyopt='-std=c11'
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,17 @@ callgrind.out.*
# Miscellaneous
*.log
/.gtm/

# Ignore all bazel-* symlinks. There is no full list since this can change
# based on the name of the directory bazel is cloned into.
/bazel-*
MODULE.bazel.lock
.bazelrc.user
external/

# Directories for the Bazel IntelliJ plugin containing the generated
# IntelliJ project files and plugin configuration. Seperate directories are
# for the IntelliJ, Android Studio and CLion versions of the plugin.
/.ijwb/
/.aswb/
/.clwb/
8 changes: 8 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("//:plugin.bzl", "CLOE_PLUGINS")

sh_binary(
name = "cloe_shell",
srcs = ["cloe_shell.sh"],
args = ["$(location //engine:cloe-engine)"] + ["$(location {})".format(p) for p in CLOE_PLUGINS],
data = ["//engine:cloe-engine"] + CLOE_PLUGINS + glob(["tests/*"]),
)
31 changes: 31 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module(name = "cloe", version = "0.25.0")

# Build dependencies:
bazel_dep(name = "cmake_configure_file", version = "0.1.0")
bazel_dep(name = "rules_cc", version = "0.0.9")

# Test dependencies:
bazel_dep(name = "googletest", version = "1.14.0", repo_name = "gtest")

# Library dependencies:
bazel_dep(name = "boost", version = "1.83.0.bcr.1")
bazel_dep(name = "cli11", version = "2.3.2")
bazel_dep(name = "eigen", version = "3.4.0.bcr.1")
bazel_dep(name = "fmt", version = "10.2.1")
bazel_dep(name = "incbin", version = "20211106.0")
bazel_dep(name = "inja", version = "3.4.0")
bazel_dep(name = "lua", version = "5.4.6")
bazel_dep(name = "nlohmann_json", version = "3.11.3")
bazel_dep(name = "oatpp", version = "1.3.0")
bazel_dep(name = "sol", version = "3.3.1")
bazel_dep(name = "spdlog", version = "1.13.0")
bazel_dep(name = "open-simulation-interface", version = "3.5.0")
bazel_dep(name = "protobuf", version = "26.0")

# Tooling dependencies:
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
git_override(
module_name = "hedron_compile_commands",
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
commit = "1e08f8e0507b6b6b1f4416a9a22cf5c28beaba93", # 2024-07-04
)
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,37 @@ When using `make` to build the project, add this to the command line:
CONAN_OPTIONS="-c tools.build:skip_test=1"
## Building with Bazel
Bazel tooling is currently experimental, and is meant to support users
who already are using Bazel in their projects and are not afraid of
providing their own registries and modules for Cloe's dependencies.
(That allows us to not have to vendor massive amounts of Bazel modules
in this repository, of which Boost is the main problematic point.
Once Boost makes it into the Bazel Central Registry, it may be worthwhile
to vendor the remaining libraries in this repository.)
You will need to create a `.bazelrc.user` file in the repository root
with the following contents:
common --registry=file:///path/to/your/bazel/registry
This file is ignored by Git to prevent you from exposing your secrets.
The registry should contain the following modules:
boost
cli11
esmini
incbin
inja
luajit (optional)
oatpp
open-simulation-interface
sol
The rest of the dependencies are taken from the Bazel Central Registry.
See `MODULE.bazel` for the full list.
### Building Docker Images
Expand Down
Empty file added WORKSPACE.bazel
Empty file.
18 changes: 18 additions & 0 deletions cloe_shell.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

export CLOE_LOG_LEVEL=debug
export CLOE_STRICT_MODE=1
export CLOE_ROOT="$(pwd)"
export CLOE_ENGINE="${CLOE_ROOT}/$1"
export CLOE_LUA_PATH="${CLOE_ROOT}/engine/lua"
export PATH="$(dirname "$CLOE_ENGINE"):$PATH"

# Set plugin paths
shift 1
while [[ $# -ne 0 ]]; do
CLOE_PLUGIN_PATH="${CLOE_ROOT}/$(dirname "$1"):$CLOE_PLUGIN_PATH"
shift 1
done
export CLOE_PLUGIN_PATH

exec $SHELL
65 changes: 65 additions & 0 deletions engine/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
load("//:version.bzl", "PROJECT_VERSION")

cc_library(
name = "enginelib",
hdrs = glob(["src/**/*.hpp"], exclude=["src/main*.hpp"]),
srcs = glob(
["src/**/*.cpp"],
exclude=[
"src/main*.cpp",
"src/**/*_test.cpp",
"src/server_mock.cpp",
]
),
data = glob(["lua/**"]),
includes = ["src"],
additional_compiler_inputs = glob(["webui/**"]),
deps = [
"//engine/vendor/lrdb",
"//engine/vendor/linenoise",
"//stack",
"//fable",
"//runtime",
"//models",
"//oak",
"@boost//:algorithm",
"@boost//:conversion",
"@boost//:optional",
"@boost//:process",
"@boost//:uuid",
"@sol",
],
defines = [
"CLOE_ENGINE_VERSION=\\\"{}\\\"".format(PROJECT_VERSION),
"CLOE_ENGINE_TIMESTAMP=\\\"unknown\\\"",
"CLOE_ENGINE_WITH_SERVER=1",
"CLOE_ENGINE_WITH_LRDB=1",
"PROJECT_SOURCE_DIR=\\\"engine\\\"",
],
linkopts = [
"-lpthread",
],
)

cc_test(
name = "engine_test",
srcs = glob(["src/**/*_test.cpp"]),
defines = [
"CLOE_LUA_PATH=\\\"" + package_name() + "/lua\\\"",
],
deps = [
":enginelib",
"@gtest//:gtest_main",
],
)

cc_binary(
name = "cloe-engine",
srcs = glob(["src/main*.hpp", "src/main*.cpp"]),
includes = ["src"],
deps = [
":enginelib",
"@cli11",
],
visibility = ["//visibility:public"],
)
16 changes: 16 additions & 0 deletions engine/vendor/linenoise/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cc_library(
name = "linenoise",
hdrs = ["linenoise.h"],
srcs = ["linenoise.c"],
includes = ["."],
local_defines = [
"__STDC_WANT_LIB_EXT2__=1",
],
visibility = ["//visibility:public"],
)

cc_test(
name = "linenoise_example",
srcs = ["example.c"],
deps = [":linenoise"],
)
23 changes: 23 additions & 0 deletions engine/vendor/lrdb/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cc_library(
name = "lrdb",
hdrs = glob(["include/**/*.hpp"]),
includes = ["include"],
defines = [
"LRDB_USE_BOOST_ASIO=1",
],
deps = [
":picojson",
"@lua",
"@boost//:asio",
],
linkopts = [
"-lpthread",
],
visibility = ["//visibility:public"],
)

cc_library(
name = "picojson",
hdrs = ["third_party/picojson/picojson.h"],
includes = ["third_party/picojson"],
)
38 changes: 38 additions & 0 deletions fable/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
load(
"@cmake_configure_file//:cmake_configure_file.bzl",
"cmake_configure_file",
)
load("//:version.bzl", "PROJECT_VERSION", "PROJECT_VERSION_U32")

cmake_configure_file(
name = "fable_version_hpp",
src = "src/fable/version.hpp.in",
out = "include/fable/version.hpp",
defines = [
"FABLE_VERSION={}".format(PROJECT_VERSION),
"FABLE_VERSION_U32={}".format(PROJECT_VERSION_U32),
]
)

cc_library(
name = "fable",
srcs = glob(["src/**/*.cpp"], exclude=["src/**/*_test.cpp"]),
hdrs = glob(["include/**/*.hpp"]) + [":fable_version_hpp"],
includes = [ "include" ],
deps = [
"@fmt",
"@nlohmann_json//:json",
],
visibility = ["//visibility:public"],
)

cc_test(
name = "fable_test",
srcs = glob(["src/**/*_test.cpp"]),
deps = [
":fable",
"@sol",
"@boost//:optional",
"@gtest//:gtest_main",
],
)
21 changes: 21 additions & 0 deletions fable/examples/contacts/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
filegroup(
name = "inputs",
srcs = [
"example_addressbook.json",
"invalid_addressbook.json",
]
)

cc_binary(
name = "contacts",
srcs = [
"src/main.cpp",
],
deps = [
"//fable",
"@cli11",
],
data = [
":inputs",
]
)
20 changes: 20 additions & 0 deletions fable/examples/simple_config/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
filegroup(
name = "inputs",
srcs = [
"example_input.json",
]
)

cc_binary(
name = "simple_config",
srcs = [
"src/main.cpp",
],
deps = [
"//fable",
"@cli11",
],
data = [
":inputs",
]
)
21 changes: 21 additions & 0 deletions models/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cc_library(
name = "models",
hdrs = glob(["include/**/*.hpp"]),
srcs = glob(["src/**/*.cpp"], exclude=["src/**/*_test.cpp"]),
includes = [ "include" ],
deps = [
"//runtime",
"@boost//:optional",
"@eigen",
],
visibility = ["//visibility:public"],
)

cc_test(
name = "models_test",
srcs = glob(["src/**/*_test.cpp"]),
deps = [
":models",
"@gtest//:gtest_main",
],
)
20 changes: 20 additions & 0 deletions oak/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cc_library(
name = "oak",
hdrs = glob(["include/**/*.hpp"]),
srcs = glob(["src/**"], exclude=["src/**/*_test.cpp"]),
includes = [ "include" ],
deps = [
"//runtime",
"@oatpp",
],
visibility = ["//visibility:public"],
)

cc_test(
name = "models_test",
srcs = glob(["src/**/*_test.cpp", "src/**/*.hpp"]),
deps = [
":oak",
"@gtest//:gtest_main",
],
)
7 changes: 4 additions & 3 deletions oak/src/oak/registrar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* \see oak/registrar.hpp
*/

#include "oak/registrar.hpp"
#include <oak/registrar.hpp>

#include <map>
#include <memory>
Expand All @@ -30,8 +30,9 @@

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

#include "oak/request_stub.hpp" // for RequestStub
#include "oak/server.hpp" // for Server
#include <oak/server.hpp> // for Server

#include "request_stub.hpp" // for RequestStub

namespace oak {

Expand Down
2 changes: 1 addition & 1 deletion oak/src/oak/route_muxer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <vector> // for vector<>
using namespace std; // NOLINT(build/namespaces)

#include "oak/route_muxer.hpp" // for Muxer<>
#include <oak/route_muxer.hpp> // for Muxer<>
using oak::Muxer;
using oak::Parameters;

Expand Down
Loading

0 comments on commit 2cdac8c

Please sign in to comment.