diff --git a/BUILD.bazel b/BUILD.bazel index b92f9be5df..e63fee83a7 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 437b86620b..8aedcd7b06 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,6 +33,7 @@ rules_rust_dependencies() rust_register_toolchains( versions = ["1.74.0"], + edition="2021", ) load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies") @@ -43,6 +63,19 @@ load("@crate_index//:defs.bzl", "crate_repositories") crate_repositories() +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() @@ -51,6 +84,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() @@ -58,3 +92,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 54aa66164e..5c490b33cd 100644 --- a/dependencies.yaml +++ b/dependencies.yaml @@ -1,7 +1,7 @@ --- everest-framework: git: https://github.com/EVerest/everest-framework.git - git_tag: v0.10.1 + git_tag: 01468678f5b627a96791f749f3139c3d169bf081 options: ["BUILD_TESTING OFF"] sigslot: git: https://github.com/palacaze/sigslot @@ -72,8 +72,8 @@ ext-mbedtls: - MBEDTLS_FATAL_WARNINGS OFF # disables setting warnings as errors FIXME: workaround until upstream-fixes are included # everest-testing everest-utils: - git: https://github.com/EVerest/everest-utils.git - git_tag: v0.2.1 + git: https://github.com/Qwello/everest-utils.git + git_tag: dc8c07f6ac534f9edba8a01a416f7d185bdc5478 cmake_condition: "EVEREST_CORE_BUILD_TESTING" # evse-security, since this is a direct dependency of libocpp it will get overwritten by the version set there # setting it here can be misleading since it does not affect the version being used diff --git a/interfaces/BUILD.bazel b/interfaces/BUILD.bazel new file mode 100644 index 0000000000..5c38ba0c5f --- /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 0000000000..f73d204432 --- /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 0000000000..8931942b15 --- /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 0000000000..bcbd738987 --- /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 0000000000..535ce57388 --- /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 0000000000..62368b6085 --- /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 0000000000..41a8f45123 --- /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 0000000000..e179681267 --- /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 647583001d..01c16c4730 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/SerialCommHub/BUILD.bazel b/modules/SerialCommHub/BUILD.bazel new file mode 100644 index 0000000000..4c2c6e3679 --- /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 0000000000..1a3aef7148 --- /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 912542029e..d39281f7fa 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 88625bcced..fd22679fb0 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 5503fa2c1c..6945025baa 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 c01c5081ed..0814ccc37f 100644 --- a/third-party/bazel/defs.bzl +++ b/third-party/bazel/defs.bzl @@ -1,4 +1,6 @@ load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps") +load("@rules_python//python:repositories.bzl", "py_repositories") def everest_core_defs(): boost_deps() + 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 0000000000..5c2c62b53e --- /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 0000000000..ae6982ae91 --- /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 0000000000..63c6f4feea --- /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 0000000000..09e1104bef --- /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 0000000000..f3c7143511 --- /dev/null +++ b/third-party/bazel/deps_versions.bzl @@ -0,0 +1,71 @@ +# 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", + + # everest-framework + everest_framework_repo = "https://github.com/EVerest/everest-framework.git", + everest_framework_tag = "01468678f5b627a96791f749f3139c3d169bf081", + + # everest-utils + everest_utils_repo = "https://github.com/Qwello/everest-utils.git", + everest_utils_tag = "dc8c07f6ac534f9edba8a01a416f7d185bdc5478", + + # 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.4.3", + + # 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 = "86adda6", + + # libslac + libslac_repo = "https://github.com/EVerest/libslac.git", + libslac_tag = "486cd8b", + + # libsunspec + libsunspec_repo = "https://github.com/EVerest/libsunspec.git", + libsunspec_tag = "v0.2.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", + +) diff --git a/third-party/bazel/ev-cli.requirements.txt b/third-party/bazel/ev-cli.requirements.txt new file mode 100644 index 0000000000..287cdfff50 --- /dev/null +++ b/third-party/bazel/ev-cli.requirements.txt @@ -0,0 +1,9 @@ +attrs==23.1.0 +Jinja2==3.1.2 +jsonschema==4.20.0 +jsonschema-specifications==2023.11.1 +MarkupSafe==2.1.3 +PyYAML==6.0.1 +referencing==0.31.0 +rpds-py==0.13.1 +stringcase==1.2.0 diff --git a/third-party/bazel/repos.bzl b/third-party/bazel/repos.bzl index 5053e0b1df..2332ba3c42 100644 --- a/third-party/bazel/repos.bzl +++ b/third-party/bazel/repos.bzl @@ -1,7 +1,16 @@ 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("//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", @@ -11,8 +20,149 @@ def everest_core_repos(): ) maybe( - http_archive, + git_repository, name = "everest-framework", - url = "https://github.com/everest/everest-framework/archive/01468678f5b627a96791f749f3139c3d169bf081.tar.gz", - strip_prefix = "everest-framework-01468678f5b627a96791f749f3139c3d169bf081", + remote = EVEREST_DEPS.everest_framework_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_framework_tag, + ) + + 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 = "libsunspec", + remote = EVEREST_DEPS.libsunspec_repo, + tag = EVEREST_DEPS.libsunspec_tag, + build_file_content = """ +cc_library( + name = "libsunspec", + srcs = glob(["src/**/*.cpp"]), + hdrs = glob(["include/**/*.hpp"]), + deps = [ + "@com_github_everest_liblog//:liblog", + "@com_github_nlohmann_json//:json", + "@libmodbus//:libmodbus", + "@//third-party/bazel:boost_program_options", + ], + strip_include_prefix = "include", +) + """ + ) + + 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 0000000000..7d3c7e3071 --- /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