Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bazel: Support bazel build for essential modules #559

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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
workspace.yaml
.vscode/
/bazel-*
/modules/target
35 changes: 27 additions & 8 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
load("@bazel_skylib//rules:write_file.bzl", "write_file")

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

filegroup(
name = "types",
srcs = glob(["types/**/*.yaml"]),
name = "errors",
srcs = glob(["errors/**/*.yaml"]),
)

filegroup(
name = "interfaces",
srcs = glob(["interfaces/**/*.yaml"]),
exports_files(["dependencies.yaml"])

_GENERATED = {
"third-party/bazel/deps_versions.bzl": "//third-party/bazel:deps_versions.bzl.new",
}

write_file(
name = "gen_update",
out = "update.sh",
content = [
"#!/bin/sh",
"set -xe",
"cd $BUILD_WORKSPACE_DIRECTORY",
] + [
"cp -fv bazel-bin/{1} {0} && chmod u+w {0}".format(
k, v[2:].replace(":", "/")
)
for k, v in _GENERATED.items()
]
)

filegroup(
name = "errors",
srcs = glob(["errors/**/*.yaml"]),
sh_binary(
name = "update",
srcs = [":gen_update"],
data = _GENERATED.values(),
)
45 changes: 45 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@ workspace(name = "everest-core")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

RULES_PYTHON_SHA = "c68bdc4fbec25de5b5493b8819cfc877c4ea299c0dcb15c244c5a00208cde311"
RULES_PYTHON_VERSION = "0.31.0"

http_archive(
name = "rules_python",
sha256 = RULES_PYTHON_SHA,
strip_prefix = "rules_python-{}".format(RULES_PYTHON_VERSION),
url = "https://github.com/bazelbuild/rules_python/releases/download/{}/rules_python-{}.tar.gz".format(
RULES_PYTHON_VERSION, RULES_PYTHON_VERSION),
)
load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")

py_repositories()

python_register_toolchains(
name = "python3_10",
python_version = "3.10",
)

http_archive(
name = "rules_rust",
sha256 = "36ab8f9facae745c9c9c1b33d225623d976e78f2cc3f729b7973d8c20934ab95",
Expand All @@ -14,8 +33,29 @@ rules_rust_dependencies()

rust_register_toolchains(
versions = ["1.74.0"],
edition="2021",
)

load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies")

crate_universe_dependencies()

load("@rules_rust//crate_universe:defs.bzl", "crates_repository")

crates_repository(
name = "dep_tool_crate_index",
cargo_lockfile = "//third-party/bazel/dep_tool:Cargo.lock",
isolated = False,
manifests = [
"//third-party/bazel/dep_tool:Cargo.toml",
],
)

load("@dep_tool_crate_index//:defs.bzl", dep_tool_crate_repositories = "crate_repositories")

dep_tool_crate_repositories()


load("//third-party/bazel:repos.bzl", "everest_core_repos")

everest_core_repos()
Expand All @@ -24,10 +64,15 @@ load("//third-party/bazel:defs.bzl", "everest_core_defs")

everest_core_defs()


load("@everest-framework//third-party/bazel:repos.bzl", "everest_framework_repos")

everest_framework_repos()

load("@everest-framework//third-party/bazel:defs.bzl", "everest_framework_deps")

everest_framework_deps()

load("@everest-utils//third-party/bazel:defs.bzl", "everest_utils_defs")

everest_utils_defs()
4 changes: 2 additions & 2 deletions dependencies.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
everest-framework:
git: https://github.com/EVerest/everest-framework.git
git_tag: v0.12.0
git_tag: 3e767e2a5652d3acb97d01fc88aae2f04f3f5282
options: ["BUILD_TESTING OFF"]
sigslot:
git: https://github.com/palacaze/sigslot
Expand Down Expand Up @@ -77,7 +77,7 @@ ext-mbedtls:
# everest-testing
everest-utils:
git: https://github.com/EVerest/everest-utils.git
git_tag: v0.2.1
git_tag: 2d7ea3e4742114cb7e3b1e71b3d1e7da566e2146
cmake_condition: "EVEREST_CORE_BUILD_TESTING"

# unit testing
Expand Down
52 changes: 52 additions & 0 deletions interfaces/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
interface_srcs = glob(["*.yaml"])
interface_names = [name[:-5] for name in interface_srcs]
cpp_headers = [
"generated/interfaces/{}/Implementation.hpp".format(name) for name in interface_names
] + [
"generated/interfaces/{}/Interface.hpp".format(name) for name in interface_names
] + [
"generated/interfaces/{}/Types.hpp".format(name) for name in interface_names
]

# This separate label we need to resolve path to
# the directory later in the genrule
some_output = cpp_headers[0]

filegroup(
name = "interfaces",
srcs = interface_srcs,
visibility = ["//visibility:public"],
)

genrule(
name = "cpp-headers",
outs = cpp_headers,
srcs = interface_srcs + [
"@everest-framework//schemas:schemas",
"//types:types",
"//:errors",
],
tools = [
"@everest-utils//ev-dev-tools:ev-cli",
],
cmd = """
$(location @everest-utils//ev-dev-tools:ev-cli) interface generate-headers \
--everest-dir . \
--schemas-dir external/everest-framework/schemas \
--disable-clang-format \
--output-dir `dirname $(location {some_output})`/..
""".format(
some_output = some_output
)
)

cc_library(
name = "interfaces_lib",
hdrs = [":cpp-headers"],
visibility = ["//visibility:public"],
includes = ["."],
deps = [
"//types:types_lib",
],
copts = ["-std=c++17"],
)
8 changes: 8 additions & 0 deletions lib/3rd_party/nanopb/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cc_library(
name = "nanopb",
srcs = glob(["nanopb/*.c"]),
hdrs = glob(["nanopb/*.h"]),
includes = ["."],
include_prefix = "everest/3rd_party",
visibility = ["//visibility:public"],
)
7 changes: 7 additions & 0 deletions lib/staging/gpio/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cc_library(
name = "gpio",
srcs = ["gpio.cpp"],
hdrs = ["gpio.hpp"],
visibility = ["//visibility:public"],
includes = ["."],
)
30 changes: 30 additions & 0 deletions modules/Auth/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
load("//modules:module.bzl", "cc_everest_module")

cc_library(
name = "auth_handler",
srcs = glob(["lib/*.cpp"]),
hdrs = glob(["include/*.hpp"]),
strip_include_prefix = "include",
deps = [
"@libtimer//:libtimer",
"//third-party/bazel:boost_asio",
"@everest-framework//:framework",
"@com_github_HowardHinnant_date//:date",
"//types:types_lib",
],
copts = ["-std=c++17"],
)

IMPLS = [
"main",
"reservation",
]

cc_everest_module(
name = "Auth",
deps = [
"@libtimer//:libtimer",
":auth_handler",
],
impls = IMPLS,
)
18 changes: 18 additions & 0 deletions modules/EnergyManager/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
load("//modules:module.bzl", "cc_everest_module")

IMPLS = [
"main",
]

cc_everest_module(
name = "EnergyManager",
deps = [
],
impls = IMPLS,
srcs = glob(
[
"*.cpp",
"*.hpp",
],
),
)
23 changes: 23 additions & 0 deletions modules/EvseManager/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
load("//modules:module.bzl", "cc_everest_module")

IMPLS = [
"energy_grid",
"evse",
"token_provider",
"random_delay",
]

cc_everest_module(
name = "EvseManager",
deps = [
"@pugixml//:libpugixml",
"@sigslot//:sigslot",
],
impls = IMPLS,
srcs = glob(
[
"*.cpp",
"*.hpp",
],
),
)
11 changes: 11 additions & 0 deletions modules/GenericPowermeter/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load("//modules:module.bzl", "cc_everest_module")

IMPLS = [
"main",
]

cc_everest_module(
name = "GenericPowermeter",
deps = [],
impls = IMPLS,
)
18 changes: 18 additions & 0 deletions modules/PersistentStore/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
load("//modules:module.bzl", "cc_everest_module")

IMPLS = [
"main",
]

cc_library(
name = "libsqlite3_stub",
linkopts = ["-lsqlite3"],
)

cc_everest_module(
name = "PersistentStore",
deps = [
":libsqlite3_stub",
],
impls = IMPLS,
)
4 changes: 2 additions & 2 deletions modules/RsIskraMeter/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ cargo_build_script(
},
data = [
"manifest.yaml",
"@everest-core//:interfaces",
"@everest-core//:types",
"@everest-core//interfaces",
"@everest-core//types",
],
deps = all_crate_deps(build = True),
)
Expand Down
4 changes: 2 additions & 2 deletions modules/RsPaymentTerminal/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ cargo_build_script(
},
data = [
"manifest.yaml",
"@everest-core//:interfaces",
"@everest-core//:types",
"@everest-core//interfaces",
"@everest-core//types",
],
deps = all_crate_deps(build = True),
)
Expand Down
14 changes: 14 additions & 0 deletions modules/SerialCommHub/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
load("//modules:module.bzl", "cc_everest_module")

IMPLS = [
"main",
]

cc_everest_module(
name = "SerialCommHub",
deps = [
"//lib/staging/gpio",
],
impls = IMPLS,
srcs = glob(["*.cpp", "*.hpp"]),
)
Loading
Loading