Browse Source

add bazel support

wangzhulei 2 years ago
parent
commit
7771384603
40 changed files with 500 additions and 0 deletions
  1. 1 0
      .gitignore
  2. 295 0
      BUILD
  3. 32 0
      WORKSPACE
  4. 1 0
      src/include/srpc/descriptor.h
  5. 1 0
      src/include/srpc/generator.h
  6. 1 0
      src/include/srpc/parser.h
  7. 1 0
      src/include/srpc/printer.h
  8. 1 0
      src/include/srpc/rpc_basic.h
  9. 1 0
      src/include/srpc/rpc_buffer.h
  10. 1 0
      src/include/srpc/rpc_client.h
  11. 1 0
      src/include/srpc/rpc_compress.h
  12. 1 0
      src/include/srpc/rpc_compress_gzip.h
  13. 1 0
      src/include/srpc/rpc_compress_lz4.h
  14. 1 0
      src/include/srpc/rpc_compress_snappy.h
  15. 1 0
      src/include/srpc/rpc_context.h
  16. 1 0
      src/include/srpc/rpc_context.inl
  17. 1 0
      src/include/srpc/rpc_define.h
  18. 1 0
      src/include/srpc/rpc_global.h
  19. 1 0
      src/include/srpc/rpc_message.h
  20. 1 0
      src/include/srpc/rpc_message_brpc.h
  21. 1 0
      src/include/srpc/rpc_message_srpc.h
  22. 1 0
      src/include/srpc/rpc_message_thrift.h
  23. 1 0
      src/include/srpc/rpc_message_trpc.h
  24. 1 0
      src/include/srpc/rpc_module.h
  25. 1 0
      src/include/srpc/rpc_module_span.h
  26. 1 0
      src/include/srpc/rpc_options.h
  27. 1 0
      src/include/srpc/rpc_server.h
  28. 1 0
      src/include/srpc/rpc_service.h
  29. 1 0
      src/include/srpc/rpc_span_policies.h
  30. 1 0
      src/include/srpc/rpc_task.inl
  31. 1 0
      src/include/srpc/rpc_thrift_buffer.h
  32. 1 0
      src/include/srpc/rpc_thrift_enum.h
  33. 1 0
      src/include/srpc/rpc_thrift_idl.h
  34. 1 0
      src/include/srpc/rpc_thrift_idl.inl
  35. 1 0
      src/include/srpc/rpc_types.h
  36. 1 0
      src/include/srpc/rpc_zero_copy_stream.h
  37. 80 0
      srpc.bzl
  38. 0 0
      third_party/BUILD
  39. 18 0
      third_party/lz4.BUILD
  40. 41 0
      third_party/snappy.BUILD

+ 1 - 0
.gitignore

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

+ 295 - 0
BUILD

@@ -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 - 0
WORKSPACE

@@ -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")

+ 1 - 0
src/include/srpc/descriptor.h

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

+ 1 - 0
src/include/srpc/generator.h

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

+ 1 - 0
src/include/srpc/parser.h

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

+ 1 - 0
src/include/srpc/printer.h

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

+ 1 - 0
src/include/srpc/rpc_basic.h

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

+ 1 - 0
src/include/srpc/rpc_buffer.h

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

+ 1 - 0
src/include/srpc/rpc_client.h

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

+ 1 - 0
src/include/srpc/rpc_compress.h

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

+ 1 - 0
src/include/srpc/rpc_compress_gzip.h

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

+ 1 - 0
src/include/srpc/rpc_compress_lz4.h

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

+ 1 - 0
src/include/srpc/rpc_compress_snappy.h

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

+ 1 - 0
src/include/srpc/rpc_context.h

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

+ 1 - 0
src/include/srpc/rpc_context.inl

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

+ 1 - 0
src/include/srpc/rpc_define.h

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

+ 1 - 0
src/include/srpc/rpc_global.h

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

+ 1 - 0
src/include/srpc/rpc_message.h

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

+ 1 - 0
src/include/srpc/rpc_message_brpc.h

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

+ 1 - 0
src/include/srpc/rpc_message_srpc.h

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

+ 1 - 0
src/include/srpc/rpc_message_thrift.h

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

+ 1 - 0
src/include/srpc/rpc_message_trpc.h

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

+ 1 - 0
src/include/srpc/rpc_module.h

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

+ 1 - 0
src/include/srpc/rpc_module_span.h

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

+ 1 - 0
src/include/srpc/rpc_options.h

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

+ 1 - 0
src/include/srpc/rpc_server.h

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

+ 1 - 0
src/include/srpc/rpc_service.h

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

+ 1 - 0
src/include/srpc/rpc_span_policies.h

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

+ 1 - 0
src/include/srpc/rpc_task.inl

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

+ 1 - 0
src/include/srpc/rpc_thrift_buffer.h

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

+ 1 - 0
src/include/srpc/rpc_thrift_enum.h

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

+ 1 - 0
src/include/srpc/rpc_thrift_idl.h

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

+ 1 - 0
src/include/srpc/rpc_thrift_idl.inl

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

+ 1 - 0
src/include/srpc/rpc_types.h

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

+ 1 - 0
src/include/srpc/rpc_zero_copy_stream.h

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

+ 80 - 0
srpc.bzl

@@ -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 - 0
third_party/BUILD


+ 18 - 0
third_party/lz4.BUILD

@@ -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 - 0
third_party/snappy.BUILD

@@ -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"],
+)