Skip to content

Commit

Permalink
Improved rust and bazel support for external usage. (#145)
Browse files Browse the repository at this point in the history
This change includes
  * bugfixes for rust-codegenerator
  * refactoring of everest-rs for easier usage outside of the everest-workspace
  * refactoring of bazel builds to support everestrs
  * small improvements to bazel-build for easier external usage.

Signed-off-by: Evgeny Petrov <evgeny@epetrov.net>
  • Loading branch information
golovasteek authored Jan 25, 2024
1 parent 12b7665 commit 95b5259
Show file tree
Hide file tree
Showing 28 changed files with 450 additions and 136 deletions.
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
*build
*build-cross
!everestrs-build
target
bazel-bin
bazel-out
bazel-everest-framework
bazel-testlogs
watcher.lua
workspace.yaml

Expand Down
23 changes: 9 additions & 14 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ cc_library(
strip_include_prefix = "include",
visibility = ["//visibility:public"],
deps = [
"@boost//:program_options",
"@boost//:uuid",
"@//third-party/bazel:boost_program_options",
"@//third-party/bazel:boost_uuid",
"@com_github_HowardHinnant_date//:date",
"@com_github_LiamBindle_mqtt-c//:libmqtt",
"@com_github_biojppm_rapidyaml//:ryml",
Expand All @@ -29,17 +29,12 @@ cc_library(

cc_library(
name = "controller-ipc",
srcs = glob(["src/controller/*.cpp"]),
hdrs = glob(["src/controller/*.hpp"]),
srcs = ["src/controller/ipc.cpp"],
hdrs = ["src/controller/ipc.hpp"],
copts = ["-std=c++17"],
strip_include_prefix = "src",
deps = [
":framework",
"@com_github_biojppm_rapidyaml//:ryml",
"@com_github_everest_liblog//:liblog",
"@com_github_fmtlib_fmt//:fmt",
"@com_github_nlohmann_json//:json",
"@com_github_warmcatt_libwebsockets//:libwebsockets",
],
)

Expand All @@ -57,12 +52,12 @@ cc_binary(
),
copts = ["-std=c++17"],
deps = [
":controller-ipc",
":framework",
"@com_github_biojppm_rapidyaml//:ryml",
"@com_github_everest_liblog//:liblog",
"@com_github_fmtlib_fmt//:fmt",
"@com_github_warmcatt_libwebsockets//:libwebsockets",
"@everest-framework//:controller-ipc",
"@everest-framework//:framework",
"@libcap//:libcap",
],
)
Expand All @@ -77,12 +72,12 @@ cc_binary(
),
visibility = ["//visibility:public"],
deps = [
":controller-ipc",
":framework",
"@boost//:program_options",
"@//third-party/bazel:boost_program_options",
"@com_github_everest_liblog//:liblog",
"@com_github_fmtlib_fmt//:fmt",
"@com_github_pboettch_json-schema-validator//:json-schema-validator",
"@everest-framework//:controller-ipc",
"@everest-framework//:framework",
"@libcap//:libcap",
],
)
39 changes: 38 additions & 1 deletion WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,41 @@
workspace(name = "com_github_everest_everest-framework")
workspace(name = "everest-framework")

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

http_archive(
name = "rules_rust",
sha256 = "36ab8f9facae745c9c9c1b33d225623d976e78f2cc3f729b7973d8c20934ab95",
urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.31.0/rules_rust-v0.31.0.tar.gz"],
)

load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")

rules_rust_dependencies()

rust_register_toolchains(
versions = ["1.74.0"],
)

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

crate_universe_dependencies()

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

crates_repository(
name = "crate_index",
cargo_lockfile = "//everestrs:Cargo.lock",
isolated = False,
manifests = [
"//everestrs:Cargo.toml",
"//everestrs/everestrs:Cargo.toml",
"//everestrs/everestrs-build:Cargo.toml",
],
)

load("@crate_index//:defs.bzl", "crate_repositories")

crate_repositories()

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

Expand Down
File renamed without changes.
13 changes: 6 additions & 7 deletions everestrs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@ if (NOT EXISTS ${CXXBRIDGE_BINARY})
endif ()
endif ()

set(CXXBRIDGE_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/cxxbridge)
set(EVERESTRS_FFI_HEADER ${CXXBRIDGE_OUTPUT_DIR}/lib.rs.h)
set(EVERESTRS_FFI_SOURCE ${CXXBRIDGE_OUTPUT_DIR}/lib.rs.cc)
set(CXXBRIDGE_HEADER ${CXXBRIDGE_OUTPUT_DIR}/rust.h)
set(CXXBRIDGE_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(CXXBRIDGE_HEADER ${CXXBRIDGE_OUTPUT_DIR}/rust/cxx.h)
set(EVERESTRS_FFI_HEADER ${CXXBRIDGE_OUTPUT_DIR}/everestrs/src/lib.rs.h)
set(EVERESTRS_FFI_SOURCE ${CXXBRIDGE_OUTPUT_DIR}/everestrs/src/lib.rs.cc)

add_custom_command(
OUTPUT
${CXXBRIDGE_OUTPUT_DIR}
${EVERESTRS_FFI_HEADER}
${EVERESTRS_FFI_SOURCE}
${CXXBRIDGE_HEADER}
COMMAND
${CMAKE_COMMAND} -E make_directory ${CXXBRIDGE_OUTPUT_DIR}
${CMAKE_COMMAND} -E make_directory ${CXXBRIDGE_OUTPUT_DIR}/everestrs/src ${CXXBRIDGE_OUTPUT_DIR}/rust
COMMAND
${CXXBRIDGE_BINARY} --header -o ${CXXBRIDGE_HEADER}
COMMAND
Expand All @@ -47,7 +46,7 @@ add_custom_command(

add_library(everestrs_sys STATIC
${EVERESTRS_FFI_SOURCE}
everestrs_sys/everestrs_sys.cpp
everestrs/src/everestrs_sys.cpp
)
add_library(everest::everestrs_sys ALIAS everestrs_sys)

Expand Down
71 changes: 39 additions & 32 deletions everestrs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions everestrs/everestrs-build/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library")

filegroup(
name = "templates",
srcs = glob(["jinja/**/*"]),
)

rust_library(
name = "everestrs-build",
srcs = glob(["src/**/*.rs"], exclude = ["src/bin/**"]),
deps = [
"@crate_index//:anyhow",
"@crate_index//:argh",
"@crate_index//:convert_case",
"@crate_index//:minijinja",
"@crate_index//:serde",
"@crate_index//:serde_json",
"@crate_index//:serde_yaml",
],
data = ["@everest-framework//everestrs/everestrs-build:templates"],
visibility = ["//visibility:public"],
edition = "2021",
)

rust_binary(
name = "codegen",
srcs = glob(["src/bin/**/*.rs"]),
deps = [
"@crate_index//:anyhow",
"@crate_index//:argh",
"@crate_index//:convert_case",
"@crate_index//:minijinja",
"@crate_index//:serde",
"@crate_index//:serde_json",
"@crate_index//:serde_yaml",
"@everest-framework//everestrs/everestrs-build:everestrs-build",
],
visibility = ["//visibility:public"],
edition = "2021",
)
Loading

0 comments on commit 95b5259

Please sign in to comment.