mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-22 22:48:52 +00:00
Allow to run cpp tests under grpc/tests/ using bazel. (#6040)
This is the first step to upgrade grpc dependency to the latest version. - Patch protobuf 3.6.1. and grpc 1.15.1 to fix build errors when using the latest Bazel version (3.4.1). - Add grpc/tests:grpc_test. One can kick off tests in Bazel by calling `bazel test grpc/tests/...`. - Add missing build targets in tests/BUILD in order to support grpc/tests/BUILD
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -127,3 +127,4 @@ grpc/google/
|
|||||||
**/Package.resolved
|
**/Package.resolved
|
||||||
.clangd/**
|
.clangd/**
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
.clwb
|
||||||
1
BUILD
1
BUILD
@@ -27,6 +27,7 @@ filegroup(
|
|||||||
"include/flatbuffers/code_generators.h",
|
"include/flatbuffers/code_generators.h",
|
||||||
"include/flatbuffers/flatbuffers.h",
|
"include/flatbuffers/flatbuffers.h",
|
||||||
"include/flatbuffers/flexbuffers.h",
|
"include/flatbuffers/flexbuffers.h",
|
||||||
|
"include/flatbuffers/grpc.h",
|
||||||
"include/flatbuffers/hash.h",
|
"include/flatbuffers/hash.h",
|
||||||
"include/flatbuffers/idl.h",
|
"include/flatbuffers/idl.h",
|
||||||
"include/flatbuffers/minireflect.h",
|
"include/flatbuffers/minireflect.h",
|
||||||
|
|||||||
23
WORKSPACE
23
WORKSPACE
@@ -4,27 +4,44 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
|||||||
|
|
||||||
http_archive(
|
http_archive(
|
||||||
name = "io_bazel_rules_go",
|
name = "io_bazel_rules_go",
|
||||||
|
sha256 = "e88471aea3a3a4f19ec1310a55ba94772d087e9ce46e41ae38ecebe17935de7b",
|
||||||
urls = [
|
urls = [
|
||||||
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/rules_go/releases/download/v0.20.3/rules_go-v0.20.3.tar.gz",
|
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/rules_go/releases/download/v0.20.3/rules_go-v0.20.3.tar.gz",
|
||||||
"https://github.com/bazelbuild/rules_go/releases/download/v0.20.3/rules_go-v0.20.3.tar.gz",
|
"https://github.com/bazelbuild/rules_go/releases/download/v0.20.3/rules_go-v0.20.3.tar.gz",
|
||||||
],
|
],
|
||||||
sha256 = "e88471aea3a3a4f19ec1310a55ba94772d087e9ce46e41ae38ecebe17935de7b",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies", "go_register_toolchains")
|
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
|
||||||
|
|
||||||
go_rules_dependencies()
|
go_rules_dependencies()
|
||||||
|
|
||||||
go_register_toolchains()
|
go_register_toolchains()
|
||||||
|
|
||||||
|
##### Protobuf
|
||||||
|
_PROTOBUF_VERSION = "3.6.1"
|
||||||
|
|
||||||
|
http_archive(
|
||||||
|
name = "com_google_protobuf",
|
||||||
|
patch_args = ["-p1"],
|
||||||
|
patches = [
|
||||||
|
"//bazel:protobuf_deps_3_6_1.patch",
|
||||||
|
],
|
||||||
|
strip_prefix = "protobuf-" + _PROTOBUF_VERSION,
|
||||||
|
urls = [
|
||||||
|
"https://github.com/protocolbuffers/protobuf/archive/v" + _PROTOBUF_VERSION + ".tar.gz",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
##### GRPC
|
##### GRPC
|
||||||
_GRPC_VERSION = "1.15.1"
|
_GRPC_VERSION = "1.15.1"
|
||||||
|
|
||||||
http_archive(
|
http_archive(
|
||||||
name = "com_github_grpc_grpc",
|
name = "com_github_grpc_grpc",
|
||||||
patches = ["//bazel:grpc_deps_1_15_1.patch"],
|
|
||||||
patch_args = ["-p1"],
|
patch_args = ["-p1"],
|
||||||
|
patches = [
|
||||||
|
"//bazel:grpc_deps_1_15_1.patch",
|
||||||
|
"//bazel:grpc_deps_1_15_1_02.patch",
|
||||||
|
],
|
||||||
strip_prefix = "grpc-" + _GRPC_VERSION,
|
strip_prefix = "grpc-" + _GRPC_VERSION,
|
||||||
urls = ["https://github.com/grpc/grpc/archive/v" + _GRPC_VERSION + ".tar.gz"],
|
urls = ["https://github.com/grpc/grpc/archive/v" + _GRPC_VERSION + ".tar.gz"],
|
||||||
)
|
)
|
||||||
|
|||||||
48
bazel/grpc_deps_1_15_1_02.patch
Normal file
48
bazel/grpc_deps_1_15_1_02.patch
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
diff --git a/bazel/cc_grpc_library.bzl b/bazel/cc_grpc_library.bzl
|
||||||
|
index 3288565714..6bfcd653f5 100644
|
||||||
|
--- a/bazel/cc_grpc_library.bzl
|
||||||
|
+++ b/bazel/cc_grpc_library.bzl
|
||||||
|
@@ -1,6 +1,6 @@
|
||||||
|
"""Generates and compiles C++ grpc stubs from proto_library rules."""
|
||||||
|
|
||||||
|
-load("//:bazel/generate_cc.bzl", "generate_cc")
|
||||||
|
+load("//bazel:generate_cc.bzl", "generate_cc")
|
||||||
|
|
||||||
|
def cc_grpc_library(name, srcs, deps, proto_only, well_known_protos, generate_mocks = False, use_external = False, **kwargs):
|
||||||
|
"""Generates C++ grpc classes from a .proto file.
|
||||||
|
diff --git a/bazel/generate_cc.bzl b/bazel/generate_cc.bzl
|
||||||
|
index ae747aa42c..2f14071f92 100644
|
||||||
|
--- a/bazel/generate_cc.bzl
|
||||||
|
+++ b/bazel/generate_cc.bzl
|
||||||
|
@@ -83,7 +83,7 @@ _generate_cc = rule(
|
||||||
|
attrs = {
|
||||||
|
"srcs": attr.label_list(
|
||||||
|
mandatory = True,
|
||||||
|
- non_empty = True,
|
||||||
|
+ allow_empty = False,
|
||||||
|
providers = ["proto"],
|
||||||
|
),
|
||||||
|
"plugin": attr.label(
|
||||||
|
diff --git a/bazel/grpc_build_system.bzl b/bazel/grpc_build_system.bzl
|
||||||
|
index 73147bf3ac..e8c392aa93 100644
|
||||||
|
--- a/bazel/grpc_build_system.bzl
|
||||||
|
+++ b/bazel/grpc_build_system.bzl
|
||||||
|
@@ -24,6 +24,9 @@
|
||||||
|
#
|
||||||
|
|
||||||
|
# The set of pollers to test against if a test exercises polling
|
||||||
|
+
|
||||||
|
+load("//bazel:cc_grpc_library.bzl", "cc_grpc_library")
|
||||||
|
+
|
||||||
|
POLLERS = ['epollex', 'epollsig', 'epoll1', 'poll', 'poll-cv']
|
||||||
|
|
||||||
|
def if_not_windows(a):
|
||||||
|
@@ -95,8 +98,6 @@ def grpc_proto_plugin(name, srcs = [], deps = []):
|
||||||
|
deps = deps,
|
||||||
|
)
|
||||||
|
|
||||||
|
-load("//:bazel/cc_grpc_library.bzl", "cc_grpc_library")
|
||||||
|
-
|
||||||
|
def grpc_proto_library(name, srcs = [], deps = [], well_known_protos = False,
|
||||||
|
has_services = True, use_external = False, generate_mocks = False):
|
||||||
|
cc_grpc_library(
|
||||||
24
bazel/protobuf_deps_3_6_1.patch
Normal file
24
bazel/protobuf_deps_3_6_1.patch
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
diff --git a/protobuf.bzl b/protobuf.bzl
|
||||||
|
index 78f19c621..3b6d183b9 100644
|
||||||
|
--- a/protobuf.bzl
|
||||||
|
+++ b/protobuf.bzl
|
||||||
|
@@ -130,7 +130,7 @@ proto_gen = rule(
|
||||||
|
"protoc": attr.label(
|
||||||
|
cfg = "host",
|
||||||
|
executable = True,
|
||||||
|
- single_file = True,
|
||||||
|
+ allow_single_file = True,
|
||||||
|
mandatory = True,
|
||||||
|
),
|
||||||
|
"plugin": attr.label(
|
||||||
|
@@ -266,8 +266,8 @@ def internal_gen_well_known_protos_java(srcs):
|
||||||
|
Args:
|
||||||
|
srcs: the well known protos
|
||||||
|
"""
|
||||||
|
- root = Label("%s//protobuf_java" % (REPOSITORY_NAME)).workspace_root
|
||||||
|
- pkg = PACKAGE_NAME + "/" if PACKAGE_NAME else ""
|
||||||
|
+ root = Label("%s//protobuf_java" % (native.repository_name())).workspace_root
|
||||||
|
+ pkg = native.package_name() + "/" if native.package_name() else ""
|
||||||
|
if root == "":
|
||||||
|
include = " -I%ssrc " % pkg
|
||||||
|
else:
|
||||||
0
grpc/BUILD
Normal file
0
grpc/BUILD
Normal file
@@ -22,6 +22,12 @@ the GRPC libraries for this to compile. This test will build using the
|
|||||||
5. `cmake -DFLATBUFFERS_BUILD_GRPCTEST=ON -DGRPC_INSTALL_PATH=${GRPC_INSTALL_PATH} -DPROTOBUF_DOWNLOAD_PATH=${PROTOBUF_DOWNLOAD_PATH} ..`
|
5. `cmake -DFLATBUFFERS_BUILD_GRPCTEST=ON -DGRPC_INSTALL_PATH=${GRPC_INSTALL_PATH} -DPROTOBUF_DOWNLOAD_PATH=${PROTOBUF_DOWNLOAD_PATH} ..`
|
||||||
6. `make`
|
6. `make`
|
||||||
|
|
||||||
|
For Bazel users:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$bazel test src/compiler/...
|
||||||
|
```
|
||||||
|
|
||||||
## Running FlatBuffer gRPC tests
|
## Running FlatBuffer gRPC tests
|
||||||
|
|
||||||
### Linux
|
### Linux
|
||||||
@@ -29,3 +35,9 @@ the GRPC libraries for this to compile. This test will build using the
|
|||||||
1. `ln -s ${GRPC_INSTALL_PATH}/lib/libgrpc++_unsecure.so.6 ${GRPC_INSTALL_PATH}/lib/libgrpc++_unsecure.so.1`
|
1. `ln -s ${GRPC_INSTALL_PATH}/lib/libgrpc++_unsecure.so.6 ${GRPC_INSTALL_PATH}/lib/libgrpc++_unsecure.so.1`
|
||||||
2. `export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${GRPC_INSTALL_PATH}/lib`
|
2. `export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${GRPC_INSTALL_PATH}/lib`
|
||||||
3. `make test ARGS=-V`
|
3. `make test ARGS=-V`
|
||||||
|
|
||||||
|
For Bazel users:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$bazel test tests/...
|
||||||
|
```
|
||||||
17
grpc/tests/BUILD
Normal file
17
grpc/tests/BUILD
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
cc_test(
|
||||||
|
name = "grpc_test",
|
||||||
|
srcs = [
|
||||||
|
"grpctest.cpp",
|
||||||
|
"message_builder_test.cpp",
|
||||||
|
],
|
||||||
|
copts = ["-Itests"],
|
||||||
|
# This is required.
|
||||||
|
linkstatic = 1,
|
||||||
|
deps = [
|
||||||
|
"//tests:monster_test_cc_fbs",
|
||||||
|
"//tests:monster_test_grpc",
|
||||||
|
"//tests:test_assert",
|
||||||
|
"//tests:test_builder",
|
||||||
|
"@com_github_grpc_grpc//:grpc++",
|
||||||
|
],
|
||||||
|
)
|
||||||
@@ -55,8 +55,8 @@ cc_library(
|
|||||||
"idl_gen_php.cpp",
|
"idl_gen_php.cpp",
|
||||||
"idl_gen_python.cpp",
|
"idl_gen_python.cpp",
|
||||||
"idl_gen_rust.cpp",
|
"idl_gen_rust.cpp",
|
||||||
"idl_gen_text.cpp",
|
|
||||||
"idl_gen_swift.cpp",
|
"idl_gen_swift.cpp",
|
||||||
|
"idl_gen_text.cpp",
|
||||||
"util.cpp",
|
"util.cpp",
|
||||||
],
|
],
|
||||||
hdrs = [
|
hdrs = [
|
||||||
|
|||||||
42
tests/BUILD
42
tests/BUILD
@@ -9,6 +9,7 @@ cc_test(
|
|||||||
srcs = [
|
srcs = [
|
||||||
"evolution_test/evolution_v1_generated.h",
|
"evolution_test/evolution_v1_generated.h",
|
||||||
"evolution_test/evolution_v2_generated.h",
|
"evolution_test/evolution_v2_generated.h",
|
||||||
|
"monster_test_bfbs_generated.h",
|
||||||
"namespace_test/namespace_test1_generated.h",
|
"namespace_test/namespace_test1_generated.h",
|
||||||
"namespace_test/namespace_test2_generated.h",
|
"namespace_test/namespace_test2_generated.h",
|
||||||
"native_type_test_impl.cpp",
|
"native_type_test_impl.cpp",
|
||||||
@@ -19,7 +20,6 @@ cc_test(
|
|||||||
"test_builder.cpp",
|
"test_builder.cpp",
|
||||||
"test_builder.h",
|
"test_builder.h",
|
||||||
"union_vector/union_vector_generated.h",
|
"union_vector/union_vector_generated.h",
|
||||||
"monster_test_bfbs_generated.h",
|
|
||||||
],
|
],
|
||||||
copts = [
|
copts = [
|
||||||
"-DFLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE",
|
"-DFLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE",
|
||||||
@@ -70,6 +70,45 @@ cc_test(
|
|||||||
# Test bzl rules
|
# Test bzl rules
|
||||||
load("//:build_defs.bzl", "flatbuffer_cc_library")
|
load("//:build_defs.bzl", "flatbuffer_cc_library")
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "test_assert",
|
||||||
|
srcs = ["test_assert.cpp"],
|
||||||
|
hdrs = ["test_assert.h"],
|
||||||
|
visibility = ["//grpc/tests:__subpackages__"],
|
||||||
|
deps = ["//:flatbuffers"],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "test_builder",
|
||||||
|
srcs = ["test_builder.cpp"],
|
||||||
|
hdrs = ["test_builder.h"],
|
||||||
|
visibility = ["//grpc/tests:__subpackages__"],
|
||||||
|
deps = [
|
||||||
|
":monster_test_grpc",
|
||||||
|
":test_assert",
|
||||||
|
"//:flatbuffers",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "monster_test_grpc",
|
||||||
|
srcs = [
|
||||||
|
"monster_test.grpc.fb.cc",
|
||||||
|
"monster_test.grpc.fb.h",
|
||||||
|
"monster_test_generated.h",
|
||||||
|
],
|
||||||
|
hdrs = [
|
||||||
|
"monster_test.grpc.fb.h",
|
||||||
|
"monster_test_generated.h",
|
||||||
|
],
|
||||||
|
includes = ["."],
|
||||||
|
visibility = ["//grpc/tests:__subpackages__"],
|
||||||
|
deps = [
|
||||||
|
"//:flatbuffers",
|
||||||
|
"@com_github_grpc_grpc//:grpc++",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
flatbuffer_cc_library(
|
flatbuffer_cc_library(
|
||||||
name = "monster_test_cc_fbs",
|
name = "monster_test_cc_fbs",
|
||||||
srcs = ["monster_test.fbs"],
|
srcs = ["monster_test.fbs"],
|
||||||
@@ -78,6 +117,7 @@ flatbuffer_cc_library(
|
|||||||
"include_test/include_test1.fbs",
|
"include_test/include_test1.fbs",
|
||||||
"include_test/sub/include_test2.fbs",
|
"include_test/sub/include_test2.fbs",
|
||||||
],
|
],
|
||||||
|
visibility = ["//grpc/tests:__subpackages__"],
|
||||||
)
|
)
|
||||||
|
|
||||||
flatbuffer_cc_library(
|
flatbuffer_cc_library(
|
||||||
|
|||||||
Reference in New Issue
Block a user