add bazel support (#258)

This commit is contained in:
PikachuHy 2023-04-11 09:57:50 +08:00 committed by GitHub
parent b62d7fa727
commit 8d3a1f3af1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 436 additions and 14 deletions

22
.github/workflows/bazel.yml vendored Normal file
View File

@ -0,0 +1,22 @@
name: Bazel
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Build
working-directory: ${{github.workspace}}
run: bazel build --action_env=CXX=clang++ --action_env=CC=clang ...
- name: Test
working-directory: ${{github.workspace}}
run: bazel test --action_env=CXX=clang++ --action_env=CC=clang --test_output=errors ...

4
.gitignore vendored
View File

@ -49,3 +49,7 @@ CMakeUserPresets.json
.DS_Store
node_modules
/CMakeSettings.json
# Bazel
bazel-*
!BUILD.bazel

88
BUILD.bazel Normal file
View File

@ -0,0 +1,88 @@
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
cc_library(
name = "struct_pack",
hdrs = glob([
"include/util/expected.hpp",
"include/struct_pack/struct_pack/*.hpp",
"include/struct_pack/struct_pack/*.h",
]) + ["include/struct_pack/struct_pack.hpp"],
include_prefix = "include",
includes = ["include"],
visibility = ["//visibility:public"],
)
cc_library(
name = "struct_pb",
hdrs = glob([
"include/struct_pb/struct_pb/*.hpp",
]) + ["include/struct_pb/struct_pb.hpp"],
include_prefix = "include",
includes = ["include"],
visibility = ["//visibility:public"],
)
cc_library(
name = "struct_json",
hdrs = glob([
"include/struct_json/*.h",
]),
include_prefix = "include",
includes = ["include"],
visibility = ["//visibility:public"],
deps = [
"//thirdparty:frozen",
"//thirdparty:iguana",
],
)
cc_library(
name = "easylog",
hdrs = glob([
"include/easylog/*.hpp",
"include/easylog/*.h",
]) + [
"include/util/dragonbox.h",
"include/util/dragonbox_to_chars.h",
"include/util/meta_string.hpp",
"include/util/type_traits.h",
],
include_prefix = "include",
includes = ["include"],
visibility = ["//visibility:public"],
)
cc_library(
name = "coro_rpc",
hdrs = glob([
"include/coro_rpc/**/*.hpp",
"include/asio_util/*.hpp",
"include/util/*.hpp",
"include/util/*.h",
]),
include_prefix = "include",
includes = ["include"],
visibility = ["//visibility:public"],
deps = [
"//:easylog",
"//:struct_pack",
"//thirdparty:asio",
"//thirdparty:async_simple",
],
)
cc_library(
name = "coro_http",
hdrs = glob([
"include/coro_http/*.h",
"include/asio_util/*.hpp",
]),
include_prefix = "include",
includes = ["include"],
visibility = ["//visibility:public"],
deps = [
"//thirdparty:asio",
"//thirdparty:async_simple",
"//thirdparty:cinatra",
],
)

0
WORKSPACE.bazel Normal file
View File

View File

@ -35,11 +35,11 @@
#include <variant>
#include <vector>
#include "error_code.h"
#include "md5_constexpr.hpp"
#include "struct_pack/struct_pack.hpp"
#include "tuple.hpp"
#include "varint.hpp"
#include "struct_pack/struct_pack/error_code.h"
#include "struct_pack/struct_pack/md5_constexpr.hpp"
#include "struct_pack/struct_pack/tuple.hpp"
#include "struct_pack/struct_pack/varint.hpp"
static_assert(std::endian::native == std::endian::little,
"only support little endian now");

View File

@ -4,8 +4,8 @@
#include <system_error>
#include <type_traits>
#include "error_code.h"
#include "reflection.h"
#include "struct_pack/struct_pack/error_code.h"
#include "struct_pack/struct_pack/reflection.h"
namespace struct_pack {
namespace detail {

View File

@ -16,7 +16,7 @@
#pragma once
#include <string_view>
#include "magic_names.hpp"
#include "util/magic_names.hpp"
namespace coro_rpc {
template <auto func>
constexpr std::string_view get_func_name() {

View File

@ -27,8 +27,8 @@
#if __has_include(<span>)
#include <span>
#include "meta_string.hpp"
#include "string_finder.hpp"
#include "util/meta_string.hpp"
#include "util/string_finder.hpp"
#endif
#include <string_view>

View File

@ -0,0 +1,11 @@
cc_binary(
name = "coro_http_example",
srcs =
[
"main.cpp",
],
copts = [
"-std=c++20",
],
deps = ["//:coro_http"],
)

View File

@ -0,0 +1,28 @@
cc_binary(
name = "file_client",
srcs =
[
"file_client/main.cpp",
"rpc_service/rpc_service.h",
],
copts = [
"-std=c++20",
"-Isrc/coro_rpc/examples/file_transfer",
],
deps = ["//:coro_rpc"],
)
cc_binary(
name = "file_server",
srcs =
[
"file_server/main.cpp",
"file_server/rpc_service.cpp",
"rpc_service/rpc_service.h",
],
copts = [
"-std=c++20",
"-Isrc/coro_rpc/examples/file_transfer",
],
deps = ["//:coro_rpc"],
)

View File

@ -2,7 +2,7 @@
#include <filesystem>
#include <iostream>
#include "../rpc_service/rpc_service.h"
#include "rpc_service/rpc_service.h"
async_simple::coro::Lazy<void> test(coro_rpc::coro_rpc_client &client,
auto filename) {

View File

@ -1,4 +1,4 @@
#include "../rpc_service/rpc_service.h"
#include "rpc_service/rpc_service.h"
#include <filesystem>

View File

@ -0,0 +1,44 @@
cc_binary(
name = "helloworld_server",
srcs =
[
"rpc_service/rpc_service.h",
"server/main.cpp",
"server/rpc_service.cpp",
],
copts = [
"-std=c++20",
"-Isrc/coro_rpc/examples/helloworld",
],
deps = ["//:coro_rpc"],
)
cc_binary(
name = "helloworld_client",
srcs =
[
"client/main.cpp",
"rpc_service/rpc_service.h",
"server/rpc_service.cpp",
],
copts = [
"-std=c++20",
"-Isrc/coro_rpc/examples/helloworld",
],
deps = ["//:coro_rpc"],
)
cc_binary(
name = "helloworld_concurrency_clients",
srcs =
[
"concurrency_clients/main.cpp",
"rpc_service/rpc_service.h",
"server/rpc_service.cpp",
],
copts = [
"-std=c++20",
"-Isrc/coro_rpc/examples/helloworld",
],
deps = ["//:coro_rpc"],
)

View File

@ -0,0 +1,27 @@
cc_binary(
name = "nested_rpc_call_client",
srcs =
[
"client/main.cpp",
"rpc_service/rpc_service.h",
],
copts = [
"-std=c++20",
"-Isrc/coro_rpc/examples/nested_rpc_call",
],
deps = ["//:coro_rpc"],
)
cc_binary(
name = "nested_rpc_call_server",
srcs =
[
"rpc_service/rpc_service.h",
"server/main.cpp",
],
copts = [
"-std=c++20",
"-Isrc/coro_rpc/examples/nested_rpc_call",
],
deps = ["//:coro_rpc"],
)

View File

@ -0,0 +1,33 @@
load("@rules_cc//cc:defs.bzl", "cc_test")
cc_test(
name = "test_rpc",
srcs =
[
"ServerTester.hpp",
"inject_action.hpp",
"main.cpp",
"rpc_api.hpp",
"rpc_service.cpp",
"test_connection.cpp",
"test_coro_rpc_client.cpp",
"test_coro_rpc_server.cpp",
"test_function_name.cpp",
"test_register_handler.cpp",
"test_router.cpp",
"test_variadic.cpp",
],
copts = [
"-std=c++20",
"-Isrc/coro_rpc/tests",
],
defines = [
"UNIT_TEST_INJECT",
"STRUCT_PACK_ENABLE_UNPORTABLE_TYPE",
],
deps = [
"//:coro_rpc",
"//:struct_pack",
"//thirdparty:doctest",
],
)

View File

@ -1,4 +1,4 @@
find_package(glog)
find_package(glog QUIET)
add_executable(easylog_benchmark
main.cpp

View File

@ -0,0 +1,14 @@
load("@rules_cc//cc:defs.bzl", "cc_test")
cc_test(
name = "test_easylog",
srcs = [
"main.cpp",
"test_easylog.cpp",
],
copts = ["-std=c++20"],
deps = [
"//:easylog",
"//thirdparty:doctest",
],
)

View File

@ -0,0 +1,11 @@
cc_binary(
name = "struct_json_example",
srcs =
[
"main.cpp",
],
copts = [
"-std=c++20",
],
deps = ["//:struct_json"],
)

View File

@ -0,0 +1,38 @@
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
cc_binary(
name = "struct_pack_benchmark",
srcs = glob([
"generated_code/*.cc",
"generated_code/*.h",
]) + [
"ScopedTimer.hpp",
"benchmark.cpp",
"config.hpp",
"data_def.hpp",
"no_op.cpp",
"no_op.h",
"sample.hpp",
"struct_pack_sample.hpp",
],
copts = ["-std=c++20"],
defines = ["STRUCT_PACK_OPTIMIZE"],
deps = [
"//:struct_pack",
"//:struct_pb",
],
)
cc_library(
name = "struct_pack_benchmark_config_header",
hdrs = [
"ScopedTimer.hpp",
"config.hpp",
"data_def.hpp",
"no_op.h",
"sample.hpp",
"struct_pb_sample.hpp",
],
includes = ["src/struct_pack/benchmark"],
visibility = ["//visibility:public"],
)

View File

@ -33,7 +33,7 @@ else ()
endif ()
# TODO
find_package(Msgpack)
find_package(Msgpack QUIET)
if (Msgpack_FOUND)
message(STATUS "Msgpack_FOUND: ${Msgpack_FOUND}")
target_link_libraries(struct_pack_benchmark PRIVATE msgpackc-cxx)

View File

@ -0,0 +1,10 @@
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
cc_binary(
name = "serialize_example",
srcs = ["serialize/serialize.cpp"],
copts = ["-std=c++20"],
deps = [
"//:struct_pack",
],
)

View File

@ -0,0 +1,12 @@
load("@rules_cc//cc:defs.bzl", "cc_test")
cc_test(
name = "test_serialize",
srcs = glob(["*.cpp"]) + ["test_struct.hpp"],
copts = ["-std=c++20"],
defines = ["STRUCT_PACK_ENABLE_UNPORTABLE_TYPE"],
deps = [
"//:struct_pack",
"//thirdparty:doctest",
],
)

View File

@ -0,0 +1,21 @@
load("@rules_cc//cc:defs.bzl", "cc_test")
cc_test(
name = "test_struct_pb",
srcs = glob([
"*.cpp",
"*.hpp",
"generated_code/*.cc",
"generated_code/*.h",
]),
copts = [
"-std=c++20",
"-Isrc/struct_pack/benchmark",
],
includes = ["generated_code"],
deps = [
"//:struct_pb",
"//src/struct_pack/benchmark:struct_pack_benchmark_config_header",
"//thirdparty:doctest",
],
)

View File

@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "config.hpp"
#ifdef HAVE_PROTOBUF
#include "protobuf_sample.hpp"
#endif

60
thirdparty/BUILD.bazel vendored Normal file
View File

@ -0,0 +1,60 @@
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
cc_library(
name = "doctest",
hdrs = ["doctest/doctest.h"],
includes = ["doctest"],
visibility = ["//visibility:public"],
)
cc_library(
name = "async_simple",
hdrs = glob([
"async_simple/async_simple/*.h",
"async_simple/async_simple/coro/*.h",
"async_simple/async_simple/executors/*.h",
"async_simple/async_simple/experimental/*.h",
"async_simple/async_simple/util/*.h",
]),
includes = ["async_simple"],
visibility = ["//visibility:public"],
)
cc_library(
name = "asio",
hdrs = glob([
"asio/**/*.hpp",
"asio/**/*.ipp",
]),
includes = ["asio"],
visibility = ["//visibility:public"],
)
cc_library(
name = "frozen",
hdrs = glob([
"frozen/**/*.h",
]),
includes = ["frozen"],
visibility = ["//visibility:public"],
)
cc_library(
name = "iguana",
hdrs = glob([
"iguana/**/*.hpp",
"iguana/**/*.h",
]),
includes = ["iguana"],
visibility = ["//visibility:public"],
)
cc_library(
name = "cinatra",
hdrs = glob([
"cinatra/**/*.hpp",
"cinatra/**/*.h",
]),
includes = ["cinatra"],
visibility = ["//visibility:public"],
)