From dfcd07722f41181e92a3c688fb681c89da7eedc3 Mon Sep 17 00:00:00 2001 From: Evgeny Petrov Date: Tue, 23 Apr 2024 10:59:08 +0200 Subject: [PATCH] Bazel: Support bazel build for essential modules (#559) * Bazel build for essential modules --------- Signed-off-by: Evgeny Petrov --- .gitignore | 1 + BUILD.bazel | 35 +++- WORKSPACE.bazel | 45 ++++++ dependencies.yaml | 4 +- interfaces/BUILD.bazel | 52 ++++++ lib/3rd_party/nanopb/BUILD.bazel | 8 + lib/staging/gpio/BUILD.bazel | 7 + modules/Auth/BUILD.bazel | 30 ++++ modules/EnergyManager/BUILD.bazel | 18 +++ modules/EvseManager/BUILD.bazel | 23 +++ modules/GenericPowermeter/BUILD.bazel | 11 ++ modules/PersistentStore/BUILD.bazel | 18 +++ modules/RsIskraMeter/BUILD.bazel | 4 +- modules/RsPaymentTerminal/BUILD.bazel | 4 +- modules/SerialCommHub/BUILD.bazel | 14 ++ modules/module.bzl | 72 +++++++++ modules/rust_examples/RsExample/BUILD.bazel | 7 +- .../rust_examples/RsExampleUser/BUILD.bazel | 4 +- third-party/bazel/BUILD.bazel | 19 +++ third-party/bazel/defs.bzl | 4 +- third-party/bazel/dep_tool/BUILD.bazel | 10 ++ third-party/bazel/dep_tool/Cargo.lock | 152 ++++++++++++++++++ third-party/bazel/dep_tool/Cargo.toml | 12 ++ third-party/bazel/dep_tool/src/main.rs | 45 ++++++ third-party/bazel/deps_versions.bzl | 75 +++++++++ third-party/bazel/repos.bzl | 132 ++++++++++++++- types/BUILD.bazel | 43 +++++ 27 files changed, 827 insertions(+), 22 deletions(-) create mode 100644 interfaces/BUILD.bazel create mode 100644 lib/3rd_party/nanopb/BUILD.bazel create mode 100644 lib/staging/gpio/BUILD.bazel create mode 100644 modules/Auth/BUILD.bazel create mode 100644 modules/EnergyManager/BUILD.bazel create mode 100644 modules/EvseManager/BUILD.bazel create mode 100644 modules/GenericPowermeter/BUILD.bazel create mode 100644 modules/PersistentStore/BUILD.bazel create mode 100644 modules/SerialCommHub/BUILD.bazel create mode 100644 modules/module.bzl create mode 100644 third-party/bazel/dep_tool/BUILD.bazel create mode 100644 third-party/bazel/dep_tool/Cargo.lock create mode 100644 third-party/bazel/dep_tool/Cargo.toml create mode 100644 third-party/bazel/dep_tool/src/main.rs create mode 100644 third-party/bazel/deps_versions.bzl create mode 100644 types/BUILD.bazel diff --git a/.gitignore b/.gitignore index a73a331aa..70850d8c4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ workspace.yaml .vscode/ /bazel-* +/modules/target diff --git a/BUILD.bazel b/BUILD.bazel index b92f9be5d..e63fee83a 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -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(), ) diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index 99368775c..3344f441b 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -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", @@ -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() @@ -24,6 +64,7 @@ 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() @@ -31,3 +72,7 @@ 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() \ No newline at end of file diff --git a/dependencies.yaml b/dependencies.yaml index 9da40260a..e76dfb35c 100644 --- a/dependencies.yaml +++ b/dependencies.yaml @@ -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 @@ -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 diff --git a/interfaces/BUILD.bazel b/interfaces/BUILD.bazel new file mode 100644 index 000000000..5c38ba0c5 --- /dev/null +++ b/interfaces/BUILD.bazel @@ -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"], +) \ No newline at end of file diff --git a/lib/3rd_party/nanopb/BUILD.bazel b/lib/3rd_party/nanopb/BUILD.bazel new file mode 100644 index 000000000..f73d20443 --- /dev/null +++ b/lib/3rd_party/nanopb/BUILD.bazel @@ -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"], +) \ No newline at end of file diff --git a/lib/staging/gpio/BUILD.bazel b/lib/staging/gpio/BUILD.bazel new file mode 100644 index 000000000..8931942b1 --- /dev/null +++ b/lib/staging/gpio/BUILD.bazel @@ -0,0 +1,7 @@ +cc_library( + name = "gpio", + srcs = ["gpio.cpp"], + hdrs = ["gpio.hpp"], + visibility = ["//visibility:public"], + includes = ["."], +) \ No newline at end of file diff --git a/modules/Auth/BUILD.bazel b/modules/Auth/BUILD.bazel new file mode 100644 index 000000000..bcbd73898 --- /dev/null +++ b/modules/Auth/BUILD.bazel @@ -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, +) \ No newline at end of file diff --git a/modules/EnergyManager/BUILD.bazel b/modules/EnergyManager/BUILD.bazel new file mode 100644 index 000000000..535ce5738 --- /dev/null +++ b/modules/EnergyManager/BUILD.bazel @@ -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", + ], + ), +) \ No newline at end of file diff --git a/modules/EvseManager/BUILD.bazel b/modules/EvseManager/BUILD.bazel new file mode 100644 index 000000000..62368b608 --- /dev/null +++ b/modules/EvseManager/BUILD.bazel @@ -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", + ], + ), +) \ No newline at end of file diff --git a/modules/GenericPowermeter/BUILD.bazel b/modules/GenericPowermeter/BUILD.bazel new file mode 100644 index 000000000..41a8f4512 --- /dev/null +++ b/modules/GenericPowermeter/BUILD.bazel @@ -0,0 +1,11 @@ +load("//modules:module.bzl", "cc_everest_module") + +IMPLS = [ + "main", +] + +cc_everest_module( + name = "GenericPowermeter", + deps = [], + impls = IMPLS, +) \ No newline at end of file diff --git a/modules/PersistentStore/BUILD.bazel b/modules/PersistentStore/BUILD.bazel new file mode 100644 index 000000000..e17968126 --- /dev/null +++ b/modules/PersistentStore/BUILD.bazel @@ -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, +) \ No newline at end of file diff --git a/modules/RsIskraMeter/BUILD.bazel b/modules/RsIskraMeter/BUILD.bazel index 60389668c..5de28bccd 100644 --- a/modules/RsIskraMeter/BUILD.bazel +++ b/modules/RsIskraMeter/BUILD.bazel @@ -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), ) diff --git a/modules/RsPaymentTerminal/BUILD.bazel b/modules/RsPaymentTerminal/BUILD.bazel index 6a519ea81..596ee399e 100644 --- a/modules/RsPaymentTerminal/BUILD.bazel +++ b/modules/RsPaymentTerminal/BUILD.bazel @@ -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), ) diff --git a/modules/SerialCommHub/BUILD.bazel b/modules/SerialCommHub/BUILD.bazel new file mode 100644 index 000000000..4c2c6e367 --- /dev/null +++ b/modules/SerialCommHub/BUILD.bazel @@ -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"]), +) \ No newline at end of file diff --git a/modules/module.bzl b/modules/module.bzl new file mode 100644 index 000000000..1a3aef714 --- /dev/null +++ b/modules/module.bzl @@ -0,0 +1,72 @@ +# Rules for building Everest modules + +def cc_everest_module( + name, + srcs = [], + deps = [], + impls = [] +): + """ + Define C++ Everest module. + + Args: + name: Name of the module. + srcs: List of source files, required files such as implemntations of + interfaces and the module main file are automatically included. + deps: List of dependencies. Libraries that are required to build the + module. + impls: List of implementations that the module has. It should match the + content of mainifest.yaml file. + """ + impl_srcs = native.glob([ + "{}/*.cpp".format(impl) + for impl in impls + ] + [ + "{}/*.hpp".format(impl) + for impl in impls + ]) + + module_srcs = [ + name + ".cpp", + name + ".hpp", + ] + + native.genrule( + name = "ld-ev", + outs = [ + "generated/modules/{}/ld-ev.hpp".format(name), + "generated/modules/{}/ld-ev.cpp".format(name), + ], + srcs = native.glob(["manifest.y*ml"], allow_empty = False) + [ + "@everest-framework//schemas:schemas", + "//types:types", + ], + tools = [ + "@everest-utils//ev-dev-tools:ev-cli", + ], + cmd = """ + $(location @everest-utils//ev-dev-tools:ev-cli) module generate-loader \ + --everest-dir . \ + --schemas-dir external/everest-framework/schemas \ + --disable-clang-format \ + --output-dir `dirname $(location generated/modules/{module_name}/ld-ev.hpp)`/.. \ + {module_name} + """.format(module_name = name) + ) + + + native.cc_binary( + name = name, + srcs = depset(srcs + impl_srcs + module_srcs + [ + ":ld-ev", + ]).to_list(), + deps = deps + [ + "//interfaces:interfaces_lib", + "@everest-framework//:framework", + ], + copts = ["-std=c++17"], + includes = [ + ".", + "generated/modules/" + name, + ], + ) \ No newline at end of file diff --git a/modules/rust_examples/RsExample/BUILD.bazel b/modules/rust_examples/RsExample/BUILD.bazel index e3f72f08f..38691036e 100644 --- a/modules/rust_examples/RsExample/BUILD.bazel +++ b/modules/rust_examples/RsExample/BUILD.bazel @@ -7,12 +7,15 @@ cargo_build_script( srcs = ["build.rs"], edition="2021", build_script_env = { + # This is a path to the folder where interfaces and types are placed. + # We are guessing it here since bazel doesn't provide a good way + # to resolve a directoryname of filegroup. "EVEREST_CORE_ROOT": "../../../", }, deps = all_crate_deps(build=True), data= [ - "//:types", - "//:interfaces", + "//types:types", + "//interfaces:interfaces", "manifest.yaml", ], ) diff --git a/modules/rust_examples/RsExampleUser/BUILD.bazel b/modules/rust_examples/RsExampleUser/BUILD.bazel index 2934a8d97..c03414cb0 100644 --- a/modules/rust_examples/RsExampleUser/BUILD.bazel +++ b/modules/rust_examples/RsExampleUser/BUILD.bazel @@ -11,8 +11,8 @@ cargo_build_script( }, deps = all_crate_deps(build=True), data= [ - "//:types", - "//:interfaces", + "//types:types", + "//interfaces:interfaces", "manifest.yaml", ], ) diff --git a/third-party/bazel/BUILD.bazel b/third-party/bazel/BUILD.bazel index 5503fa2c1..6945025ba 100644 --- a/third-party/bazel/BUILD.bazel +++ b/third-party/bazel/BUILD.bazel @@ -1,3 +1,5 @@ +load("@bazel_skylib//rules:diff_test.bzl", "diff_test") + [ alias( name = "boost_{}".format(name), @@ -10,5 +12,22 @@ "current_function", "uuid", "exception", + "asio" ] ] + +genrule( + name = "deps_versions.bzl.new", + srcs = ["//:dependencies.yaml"], + outs = ["deps_versions.bzl.new"], + tools = ["//third-party/bazel/dep_tool"], + cmd = "$(location //third-party/bazel/dep_tool) $(location //:dependencies.yaml) > $@", + visibility = ["//visibility:public"], +) + +diff_test( + name = "check_deps_versions", + failure_message = "Please run `bazel run //:update` to update the dependencies", + file1 = "deps_versions.bzl", + file2 = ":deps_versions.bzl.new", +) \ No newline at end of file diff --git a/third-party/bazel/defs.bzl b/third-party/bazel/defs.bzl index f8692a4a7..165ec2ec3 100644 --- a/third-party/bazel/defs.bzl +++ b/third-party/bazel/defs.bzl @@ -1,7 +1,9 @@ load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps") load("@everest_core_crate_index//:defs.bzl", "crate_repositories") +load("@rules_python//python:repositories.bzl", "py_repositories") def everest_core_defs(): boost_deps() - crate_repositories() \ No newline at end of file + crate_repositories() + py_repositories() diff --git a/third-party/bazel/dep_tool/BUILD.bazel b/third-party/bazel/dep_tool/BUILD.bazel new file mode 100644 index 000000000..5c2c62b53 --- /dev/null +++ b/third-party/bazel/dep_tool/BUILD.bazel @@ -0,0 +1,10 @@ +load("@dep_tool_crate_index//:defs.bzl", "all_crate_deps") +load("@rules_rust//rust:defs.bzl", "rust_binary") + + +rust_binary( + name = "dep_tool", + srcs = glob(["src/**/*.rs"]), + deps = all_crate_deps(), + visibility = ["//visibility:public"], +) \ No newline at end of file diff --git a/third-party/bazel/dep_tool/Cargo.lock b/third-party/bazel/dep_tool/Cargo.lock new file mode 100644 index 000000000..ae6982ae9 --- /dev/null +++ b/third-party/bazel/dep_tool/Cargo.lock @@ -0,0 +1,152 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "argh" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7af5ba06967ff7214ce4c7419c7d185be7ecd6cc4965a8f6e1d8ce0398aad219" +dependencies = [ + "argh_derive", + "argh_shared", +] + +[[package]] +name = "argh_derive" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56df0aeedf6b7a2fc67d06db35b09684c3e8da0c95f8f27685cb17e08413d87a" +dependencies = [ + "argh_shared", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "argh_shared" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5693f39141bda5760ecc4111ab08da40565d1771038c4a0250f03457ec707531" +dependencies = [ + "serde", +] + +[[package]] +name = "dep_tool" +version = "0.1.0" +dependencies = [ + "argh", + "serde", + "serde_derive", + "serde_yaml", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + +[[package]] +name = "indexmap" +version = "2.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b0b929d511467233429c45a44ac1dcaa21ba0f5ba11e4879e6ed28ddb4f9df4" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "itoa" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" + +[[package]] +name = "proc-macro2" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ryu" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" + +[[package]] +name = "serde" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_yaml" +version = "0.9.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd075d994154d4a774f95b51fb96bdc2832b0ea48425c92546073816cda1f2f" +dependencies = [ + "indexmap", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + +[[package]] +name = "syn" +version = "2.0.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unsafe-libyaml" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab4c90930b95a82d00dc9e9ac071b4991924390d46cbd0dfe566148667605e4b" diff --git a/third-party/bazel/dep_tool/Cargo.toml b/third-party/bazel/dep_tool/Cargo.toml new file mode 100644 index 000000000..63c6f4fee --- /dev/null +++ b/third-party/bazel/dep_tool/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "dep_tool" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +argh = "0.1.12" +serde = { version = "1.0.197", features = ["derive"] } +serde_derive = "1.0.197" +serde_yaml = "0.9.32" diff --git a/third-party/bazel/dep_tool/src/main.rs b/third-party/bazel/dep_tool/src/main.rs new file mode 100644 index 000000000..09e1104be --- /dev/null +++ b/third-party/bazel/dep_tool/src/main.rs @@ -0,0 +1,45 @@ +extern crate serde_yaml; +use serde::Deserialize; +use std::collections::BTreeMap; +use argh::FromArgs; + +#[derive(Debug, Deserialize)] +struct DependencyDescriptor { + git: String, + git_tag: String, + options: Option>, + cmake_condition: Option, +} + +#[derive(FromArgs)] +/// A tool to parse dependencies.yaml and generate bazel dependencies file +struct Args { + /// path to dependencies.yaml + #[argh(positional)] + path: String, +} + +fn sanitize_name(name: &str) -> String { + name.replace("-", "_") +} + +fn main() { + let args: Args = argh::from_env(); + eprintln!("Reading dependencies from {}", args.path); + let deps = std::fs::read_to_string(args.path).unwrap(); + let deps: BTreeMap = serde_yaml::from_str(&deps).unwrap(); + + println!("# This file is generated by dep_tool. Do not edit manually."); + println!("# To regenerate this file, after changing dependencies.yaml run:"); + println!("#"); + println!("# bazel run //:update"); + println!(""); + println!("EVEREST_DEPS = struct("); + for (name, dep) in deps { + println!("\t# {}", name); + println!("\t{}_repo = \"{}\",", sanitize_name(&name), dep.git); + println!("\t{}_tag = \"{}\",", sanitize_name(&name), dep.git_tag); + println!(""); + } + println!(")"); +} diff --git a/third-party/bazel/deps_versions.bzl b/third-party/bazel/deps_versions.bzl new file mode 100644 index 000000000..b717c404a --- /dev/null +++ b/third-party/bazel/deps_versions.bzl @@ -0,0 +1,75 @@ +# This file is generated by dep_tool. Do not edit manually. +# To regenerate this file, after changing dependencies.yaml run: +# +# bazel run //:update + +EVEREST_DEPS = struct( + # Josev + Josev_repo = "https://github.com/EVerest/ext-switchev-iso15118.git", + Josev_tag = "2024.2.1", + + # catch2 + catch2_repo = "https://github.com/catchorg/Catch2.git", + catch2_tag = "v3.4.0", + + # everest-framework + everest_framework_repo = "https://github.com/EVerest/everest-framework.git", + everest_framework_tag = "3e767e2a5652d3acb97d01fc88aae2f04f3f5282", + + # everest-utils + everest_utils_repo = "https://github.com/EVerest/everest-utils.git", + everest_utils_tag = "2d7ea3e4742114cb7e3b1e71b3d1e7da566e2146", + + # ext-mbedtls + ext_mbedtls_repo = "https://github.com/EVerest/ext-mbedtls.git", + ext_mbedtls_tag = "8b3f26a", + + # ext-openv2g + ext_openv2g_repo = "https://github.com/EVerest/ext-openv2g.git", + ext_openv2g_tag = "2023.3.0", + + # gtest + gtest_repo = "https://github.com/google/googletest.git", + gtest_tag = "release-1.12.1", + + # libcurl + libcurl_repo = "https://github.com/curl/curl.git", + libcurl_tag = "curl-8_4_0", + + # libevse-security + libevse_security_repo = "https://github.com/EVerest/libevse-security.git", + libevse_security_tag = "v0.5.0", + + # libfsm + libfsm_repo = "https://github.com/EVerest/libfsm.git", + libfsm_tag = "v0.2.0", + + # libmodbus + libmodbus_repo = "https://github.com/EVerest/libmodbus.git", + libmodbus_tag = "v0.3.1", + + # libocpp + libocpp_repo = "https://github.com/EVerest/libocpp.git", + libocpp_tag = "cc169be", + + # libslac + libslac_repo = "https://github.com/EVerest/libslac.git", + libslac_tag = "v0.3.0", + + # libtimer + libtimer_repo = "https://github.com/EVerest/libtimer.git", + libtimer_tag = "v0.1.1", + + # pugixml + pugixml_repo = "https://github.com/zeux/pugixml", + pugixml_tag = "v1.12.1", + + # sigslot + sigslot_repo = "https://github.com/palacaze/sigslot", + sigslot_tag = "v1.2.0", + + # sqlite_cpp + sqlite_cpp_repo = "https://github.com/SRombauts/SQLiteCpp.git", + sqlite_cpp_tag = "3.3.1", + +) diff --git a/third-party/bazel/repos.bzl b/third-party/bazel/repos.bzl index 81beae4fc..44175fe4e 100644 --- a/third-party/bazel/repos.bzl +++ b/third-party/bazel/repos.bzl @@ -1,9 +1,18 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") load("@rules_rust//crate_universe:defs.bzl", "crates_repository", "crate") load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies") +load("//third-party/bazel:deps_versions.bzl", "EVEREST_DEPS") def everest_core_repos(): + http_archive( + name = "rules_foreign_cc", + sha256 = "476303bd0f1b04cc311fc258f1708a5f6ef82d3091e53fd1977fa20383425a6a", + strip_prefix = "rules_foreign_cc-0.10.1", + url = "https://github.com/bazelbuild/rules_foreign_cc/releases/download/0.10.1/rules_foreign_cc-0.10.1.tar.gz", + ) + maybe( http_archive, name = "com_github_nelhage_rules_boost", @@ -13,11 +22,12 @@ def everest_core_repos(): ) maybe( - http_archive, + git_repository, name = "everest-framework", - url = "https://github.com/everest/everest-framework/archive/3e767e2a5652d3acb97d01fc88aae2f04f3f5282.tar.gz", - strip_prefix = "everest-framework-3e767e2a5652d3acb97d01fc88aae2f04f3f5282", + remote = EVEREST_DEPS.everest_framework_repo, + commit = EVEREST_DEPS.everest_framework_tag, ) + crates_repository( name = "everest_core_crate_index", cargo_lockfile = "@everest-core//modules:Cargo.lock", @@ -36,3 +46,119 @@ def everest_core_repos(): }, ) crate_universe_dependencies() + + + maybe( + http_archive, + name = "rules_python", + sha256 = "9acc0944c94adb23fba1c9988b48768b1bacc6583b52a2586895c5b7491e2e31", + strip_prefix = "rules_python-0.27.0", + url = "https://github.com/bazelbuild/rules_python/releases/download/0.27.0/rules_python-0.27.0.tar.gz", + ) + + maybe( + git_repository, + name = "pugixml", + remote = EVEREST_DEPS.pugixml_repo, + tag = EVEREST_DEPS.pugixml_tag, + build_file_content = """ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") +filegroup( + name = "all_srcs", + srcs = glob(["**"]), + visibility = ["//visibility:public"], +) + +cmake( + name = "libpugixml", + cache_entries = { + }, + lib_source = "@pugixml//:all_srcs", + visibility = ["//visibility:public"], +) + """ + ) + + maybe( + git_repository, + name = "libmodbus", + remote = EVEREST_DEPS.libmodbus_repo, + tag = EVEREST_DEPS.libmodbus_tag, + build_file_content = """ +cc_library( + name = "libmodbus_connection", + srcs = glob(["lib/connection/src/**/*.cpp"]), + hdrs = glob(["lib/connection/include/**/*.hpp"]), + strip_include_prefix = "lib/connection/include", + deps = [ + "@@com_github_everest_liblog//:liblog", + ] +) + +cc_library( + name = "libmodbus", + srcs = glob(["src/**/*.cpp"]), + hdrs = glob(["include/**/*.hpp"]), + deps = [ + "@com_github_everest_liblog//:liblog", + ":libmodbus_connection", + ], + strip_include_prefix = "include", + visibility = ["//visibility:public"], +) + """ + ) + + maybe( + git_repository, + name = "sigslot", + remote = EVEREST_DEPS.sigslot_repo, + tag = EVEREST_DEPS.sigslot_tag, + build_file_content = """ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") +filegroup( + name = "all_srcs", + srcs = glob(["**"]), + visibility = ["//visibility:public"], +) + +cmake( + name = "sigslot", + cache_entries = { + "SIGSLOT_COMPILE_EXAMPLES": "OFF", + }, + lib_source = "@sigslot//:all_srcs", + out_headers_only = True, + visibility = ["//visibility:public"], +) + """ + ) + + maybe( + git_repository, + name = "libtimer", + remote = EVEREST_DEPS.libtimer_repo, + tag = EVEREST_DEPS.libtimer_tag, + build_file_content = """ +cc_library( + name = "libtimer", + hdrs = ["include/everest/timer.hpp"], + deps = [], + strip_include_prefix = "include", + visibility = ["//visibility:public"], +) + """ + ) + + maybe( + git_repository, + name = "everest-utils", + remote = EVEREST_DEPS.everest_utils_repo, + # Note here, we use the `commit` instead of tag, + # because bazel is strict and doesn't allow to use + # something like "revision". + # Once we switch to tag in dependencies.yaml, we should + # use tag here as well. + commit = EVEREST_DEPS.everest_utils_tag, + ) + diff --git a/types/BUILD.bazel b/types/BUILD.bazel new file mode 100644 index 000000000..7d3c7e307 --- /dev/null +++ b/types/BUILD.bazel @@ -0,0 +1,43 @@ +yaml_srcs = glob(["*.yaml"]) +some_yaml = yaml_srcs[0] + +type_names = [name[:-5] for name in yaml_srcs] +cpp_headers = [ + "generated/types/{}.hpp".format(name) for name in type_names +] + +some_header = cpp_headers[0] + +filegroup( + name = "types", + srcs = yaml_srcs, + visibility = ["//visibility:public"], +) + +genrule( + name = "cpp-headers", + outs = cpp_headers, + srcs = yaml_srcs + [ + "@everest-framework//schemas:schemas", + ], + tools = [ + "@everest-utils//ev-dev-tools:ev-cli", + ], + cmd = """ +$(location @everest-utils//ev-dev-tools:ev-cli) types generate-headers \ + --everest-dir . \ + --schemas-dir external/everest-framework/schemas \ + --disable-clang-format \ + --output-dir `dirname $(location {some_header})` +""".format( + some_header = some_header + ) +) + +cc_library( + name = "types_lib", + hdrs = [":cpp-headers"], + visibility = ["//visibility:public"], + includes = ["."], + copts = ["-std=c++17"], +) \ No newline at end of file