add bazel support

This commit is contained in:
wangzhulei 2021-08-15 19:56:37 +08:00
parent 53377f89f0
commit 7771384603
40 changed files with 500 additions and 0 deletions

1
.gitignore vendored
View File

@ -40,3 +40,4 @@ SRCVERSION
CMakeCache.txt
Makefile
bazel-*

295
BUILD Normal file
View File

@ -0,0 +1,295 @@
load("@rules_cc//cc:defs.bzl", "cc_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_library")
load(":srpc.bzl", "gen_srpc_pb_cc")
load(":srpc.bzl", "gen_srpc_thrift_cc")
proto_library(
name = "message_proto",
srcs = [
'src/message/rpc_meta.proto',
'src/message/rpc_meta_brpc.proto',
'src/message/rpc_meta_trpc.proto',
'src/message/rpc_span.proto',
],
strip_import_prefix = "src/message",
)
cc_proto_library(
name = "MessageProto",
deps = [":message_proto"],
)
cc_library(
name = 'srpc_hdrs',
hdrs = glob(['src/include/srpc/*']),
includes = ['src/include'],
deps = [
'@workflow//:workflow_hdrs',
],
visibility = ["//visibility:public"],
)
cc_library(
name = 'libsrpc',
srcs = glob(['src/**/*.cc']),
hdrs = glob([
'src/**/*.h',
'src/**/*.inl',
]),
includes = ['src', 'src/thrift', 'src/compress', 'src/message', 'src/module'],
deps = [
'@workflow//:http',
'@workflow//:upstream',
'@lz4//:lz4',
'@snappy//:snappy',
':MessageProto',
],
visibility = ["//visibility:public"],
)
cc_binary(
name ='srpc_generator',
srcs = glob(['src/generator/*.cc']),
deps = [':libsrpc'],
)
proto_library(
name = "echo_pb_proto",
srcs = [
'tutorial/echo_pb.proto',
],
strip_import_prefix = "tutorial",
)
cc_proto_library(
name = "EchoProto",
deps = [":echo_pb_proto"],
)
gen_srpc_pb_cc(
name = "echo_pb",
files = ["tutorial/echo_pb.proto",],
deps_lib = [':EchoProto'],
)
cc_binary(
name = 'srpc_pb_server',
srcs = ['tutorial/tutorial-01-srpc_pb_server.cc'],
deps = [
':libsrpc',
':echo_pb_server_cc',
],
linkopts = [
'-lpthread',
'-lssl',
'-lcrypto',
],
)
cc_binary(
name = 'srpc_pb_client',
srcs = ['tutorial/tutorial-02-srpc_pb_client.cc'],
deps = [
':libsrpc',
':echo_pb_client_cc',
],
linkopts = [
'-lpthread',
'-lssl',
'-lcrypto',
],
)
gen_srpc_thrift_cc(
name = "echo_thrift",
files = ["tutorial/echo_thrift.thrift",],
deps_lib = [],
)
cc_binary(
name = 'srpc_thrift_server',
srcs = ['tutorial/tutorial-03-srpc_thrift_server.cc'],
deps = [
':libsrpc',
':echo_thrift_server_cc',
],
linkopts = [
'-lpthread',
'-lssl',
'-lcrypto',
],
)
cc_binary(
name = 'srpc_thrift_client',
srcs = ['tutorial/tutorial-04-srpc_thrift_client.cc'],
deps = [
':libsrpc',
':echo_thrift_client_cc',
],
linkopts = [
'-lpthread',
'-lssl',
'-lcrypto',
],
)
cc_binary(
name = 'brpc_pb_server',
srcs = ['tutorial/tutorial-05-brpc_pb_server.cc'],
deps = [
':libsrpc',
':echo_pb_server_cc',
],
linkopts = [
'-lpthread',
'-lssl',
'-lcrypto',
],
)
cc_binary(
name = 'brpc_pb_client',
srcs = ['tutorial/tutorial-06-brpc_pb_client.cc'],
deps = [
':libsrpc',
':echo_pb_client_cc',
],
linkopts = [
'-lpthread',
'-lssl',
'-lcrypto',
],
)
cc_binary(
name = 'thrift_thrift_server',
srcs = ['tutorial/tutorial-07-thrift_thrift_server.cc'],
deps = [
':libsrpc',
':echo_thrift_server_cc',
],
linkopts = [
'-lpthread',
'-lssl',
'-lcrypto',
],
)
cc_binary(
name = 'thrift_thrift_client',
srcs = ['tutorial/tutorial-08-thrift_thrift_client.cc'],
deps = [
':libsrpc',
':echo_thrift_client_cc',
],
linkopts = [
'-lpthread',
'-lssl',
'-lcrypto',
],
)
cc_binary(
name = 'client_task',
srcs = ['tutorial/tutorial-09-client_task.cc'],
deps = [
':libsrpc',
':echo_pb_client_cc',
],
linkopts = [
'-lpthread',
'-lssl',
'-lcrypto',
],
)
cc_binary(
name = 'server_async',
srcs = ['tutorial/tutorial-10-server_async.cc'],
deps = [
':libsrpc',
':echo_pb_server_cc',
],
linkopts = [
'-lpthread',
'-lssl',
'-lcrypto',
],
)
proto_library(
name = "helloworld_proto",
srcs = [
'tutorial/helloworld.proto',
],
strip_import_prefix = "tutorial",
)
cc_proto_library(
name = "HelloworldProto",
deps = [":helloworld_proto"],
)
gen_srpc_pb_cc(
name = "helloworld",
files = ["tutorial/helloworld.proto",],
deps_lib = [':HelloworldProto'],
)
cc_binary(
name = 'trpc_pb_server',
srcs = ['tutorial/tutorial-11-trpc_pb_server.cc'],
deps = [
':libsrpc',
':helloworld_server_cc',
],
linkopts = [
'-lpthread',
'-lssl',
'-lcrypto',
],
)
cc_binary(
name = 'trpc_pb_client',
srcs = ['tutorial/tutorial-12-trpc_pb_client.cc'],
deps = [
':libsrpc',
':helloworld_client_cc',
],
linkopts = [
'-lpthread',
'-lssl',
'-lcrypto',
],
)
cc_binary(
name = 'trpc_http_server',
srcs = ['tutorial/tutorial-13-trpc_http_server.cc'],
deps = [
':libsrpc',
':helloworld_server_cc',
],
linkopts = [
'-lpthread',
'-lssl',
'-lcrypto',
],
)
cc_binary(
name = 'trpc_http_client',
srcs = ['tutorial/tutorial-14-trpc_http_client.cc'],
deps = [
':libsrpc',
':helloworld_client_cc',
],
linkopts = [
'-lpthread',
'-lssl',
'-lcrypto',
],
)

32
WORKSPACE Normal file
View File

@ -0,0 +1,32 @@
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "rules_proto",
sha256 = "d8992e6eeec276d49f1d4e63cfa05bbed6d4a26cfe6ca63c972827a0d141ea3b",
strip_prefix = "rules_proto-cfdc2fa31879c0aebe31ce7702b1a9c8a4be02d2",
urls = [
"https://github.com/bazelbuild/rules_proto/archive/cfdc2fa31879c0aebe31ce7702b1a9c8a4be02d2.tar.gz",
],
)
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
rules_proto_dependencies()
rules_proto_toolchains()
git_repository(
name = "workflow",
commit = "bbcf8173be22f26e7b8f4da95d80011f748f5e8b",
remote = "https://github.com/sogou/workflow.git")
new_git_repository(
name = "lz4",
build_file = "@//third_party:lz4.BUILD",
commit = "bdc9d3b0c10cbf7e1ff40fc6e27dad5f693a00e7",
remote = "https://github.com/lz4/lz4.git")
new_git_repository(
name = "snappy",
build_file = "@//third_party:snappy.BUILD",
commit = "78650d126afc55f834d15d018b430985f0c8c87c",
remote = "https://github.com/google/snappy.git")

View File

@ -0,0 +1 @@
../../generator/descriptor.h

View File

@ -0,0 +1 @@
../../generator/generator.h

1
src/include/srpc/parser.h Symbolic link
View File

@ -0,0 +1 @@
../../generator/parser.h

1
src/include/srpc/printer.h Symbolic link
View File

@ -0,0 +1 @@
../../generator/printer.h

View File

@ -0,0 +1 @@
../../rpc_basic.h

View File

@ -0,0 +1 @@
../../rpc_buffer.h

View File

@ -0,0 +1 @@
../../rpc_client.h

View File

@ -0,0 +1 @@
../../compress/rpc_compress.h

View File

@ -0,0 +1 @@
../../compress/rpc_compress_gzip.h

View File

@ -0,0 +1 @@
../../compress/rpc_compress_lz4.h

View File

@ -0,0 +1 @@
../../compress/rpc_compress_snappy.h

View File

@ -0,0 +1 @@
../../rpc_context.h

View File

@ -0,0 +1 @@
../../rpc_context.inl

View File

@ -0,0 +1 @@
../../rpc_define.h

View File

@ -0,0 +1 @@
../../rpc_global.h

View File

@ -0,0 +1 @@
../../message/rpc_message.h

View File

@ -0,0 +1 @@
../../message/rpc_message_brpc.h

View File

@ -0,0 +1 @@
../../message/rpc_message_srpc.h

View File

@ -0,0 +1 @@
../../message/rpc_message_thrift.h

View File

@ -0,0 +1 @@
../../message/rpc_message_trpc.h

View File

@ -0,0 +1 @@
../../module/rpc_module.h

View File

@ -0,0 +1 @@
../../module/rpc_module_span.h

View File

@ -0,0 +1 @@
../../rpc_options.h

View File

@ -0,0 +1 @@
../../rpc_server.h

View File

@ -0,0 +1 @@
../../rpc_service.h

View File

@ -0,0 +1 @@
../../module/rpc_span_policies.h

View File

@ -0,0 +1 @@
../../rpc_task.inl

View File

@ -0,0 +1 @@
../../thrift/rpc_thrift_buffer.h

View File

@ -0,0 +1 @@
../../thrift/rpc_thrift_enum.h

View File

@ -0,0 +1 @@
../../thrift/rpc_thrift_idl.h

View File

@ -0,0 +1 @@
../../thrift/rpc_thrift_idl.inl

View File

@ -0,0 +1 @@
../../rpc_types.h

View File

@ -0,0 +1 @@
../../rpc_zero_copy_stream.h

80
srpc.bzl Normal file
View File

@ -0,0 +1,80 @@
def gen_srpc_pb_cc(name, files, deps_lib):
native.genrule(
name = name,
srcs = files,
outs = [
name + ".srpc.h",
"client." + name + ".srpc.cc",
"server." + name + ".srpc.cc",
],
cmd = "$(location srpc_generator) protobuf $(<) ./ && mv " + name + ".srpc.h $(location " + name + ".srpc.h) && mv client.pb_skeleton.cc $(location client." + name + ".srpc.cc) && mv server.pb_skeleton.cc $(location server." + name + ".srpc.cc)",
tools = [":srpc_generator"],
)
native.cc_library(
name = name + "_client_cc",
srcs = [
"client." + name + ".srpc.cc",
],
hdrs = [
name + ".srpc.h",
],
deps = [
':srpc_hdrs',
] + deps_lib,
)
native.cc_library(
name = name + "_server_cc",
srcs = [
"server." + name + ".srpc.cc",
],
hdrs = [
name + ".srpc.h",
],
deps = [
':srpc_hdrs',
] + deps_lib,
)
def gen_srpc_thrift_cc(name, files, deps_lib):
native.genrule(
name = name,
srcs = files,
outs = [
name + ".srpc.h",
name + ".thrift.h",
"client." + name + ".thrift.cc",
"server." + name + ".thrift.cc",
],
cmd = "$(location srpc_generator) thrift $(<) ./ && mv " + name + ".thrift.h $(location " + name + ".thrift.h) && mv " + name + ".srpc.h $(location " + name + ".srpc.h) && mv client.thrift_skeleton.cc $(location client." + name + ".thrift.cc) && mv server.thrift_skeleton.cc $(location server." + name + ".thrift.cc)",
tools = [":srpc_generator"],
)
native.cc_library(
name = name + "_client_cc",
srcs = [
"client." + name + ".thrift.cc",
],
hdrs = [
name + ".srpc.h",
name + ".thrift.h",
],
deps = [
':srpc_hdrs',
] + deps_lib,
)
native.cc_library(
name = name + "_server_cc",
srcs = [
"server." + name + ".thrift.cc",
],
hdrs = [
name + ".srpc.h",
name + ".thrift.h",
],
deps = [
':srpc_hdrs',
] + deps_lib,
)

0
third_party/BUILD vendored Normal file
View File

18
third_party/lz4.BUILD vendored Normal file
View File

@ -0,0 +1,18 @@
cc_library(
name = "lz4",
srcs = [
'lib/lz4.c',
'lib/lz4hc.c',
'lib/lz4frame.c',
'lib/xxhash.c',
],
hdrs = [
'lib/lz4.h',
'lib/lz4.c',
'lib/lz4hc.h',
'lib/lz4frame.h',
'lib/xxhash.h',
],
includes = ['lib'],
visibility = ["//visibility:public"],
)

41
third_party/snappy.BUILD vendored Normal file
View File

@ -0,0 +1,41 @@
genrule(
name = "snappy_stubs_public_h",
srcs = [
"snappy-stubs-public.h.in",
],
outs = [
"snappy-stubs-public.h",
],
cmd = "sed 's/$${HAVE_SYS_UIO_H_01}/true/g' $(<) | " +
"sed 's/$${PROJECT_VERSION_MAJOR}/0/g' | " +
"sed 's/$${PROJECT_VERSION_MINOR}/9/g' | " +
"sed 's/$${PROJECT_VERSION_PATCH}/2/g' >$(@)",
)
cc_library(
name = "snappy",
srcs = [
"snappy.cc",
"snappy-c.cc",
"snappy-sinksource.cc",
"snappy-stubs-internal.cc",
],
hdrs = [
":snappy_stubs_public_h",
"snappy.h",
"snappy-c.h",
"snappy-internal.h",
"snappy-sinksource.h",
"snappy-stubs-internal.h",
"snappy-stubs-public.h.in",
],
copts = [
"-Wno-non-virtual-dtor",
"-Wno-unused-variable",
"-Wno-implicit-fallthrough",
"-Wno-unused-function",
],
includes = ["."],
visibility = ["//visibility:public"],
)