From 174e02ae3e377e1cfc36a620a078d8046b0887c1 Mon Sep 17 00:00:00 2001 From: Ning Ren Date: Mon, 20 Nov 2017 15:24:21 -0800 Subject: [PATCH] Packs contents of WORKSPACE into a bzl function, so that it can be resued by other projects, and simplifies cares build. --- BUILD | 2 +- WORKSPACE | 129 +--------------------- bazel/grpc_deps.bzl | 112 +++++++++++++++++++ third_party/BUILD | 6 + third_party/cares/BUILD | 9 ++ third_party/cares/cares.BUILD | 38 +++---- third_party/cares/cares_local_files.BUILD | 57 ---------- 7 files changed, 145 insertions(+), 208 deletions(-) create mode 100644 bazel/grpc_deps.bzl create mode 100644 third_party/BUILD create mode 100644 third_party/cares/BUILD delete mode 100644 third_party/cares/cares_local_files.BUILD diff --git a/BUILD b/BUILD index dba6592f172..5ea4d2f3879 100644 --- a/BUILD +++ b/BUILD @@ -1417,7 +1417,7 @@ grpc_cc_library( ], hdrs = [ "src/core/ext/transport/cronet/transport/cronet_transport.h", - "third_party/objective_c/Cronet/bidirectional_stream_c.h", + "//third_party:objective_c/Cronet/bidirectional_stream_c.h", ], language = "c++", public_hdrs = [ diff --git a/WORKSPACE b/WORKSPACE index bf09aa7cc93..adce8091628 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,127 +1,4 @@ -bind( - name = "nanopb", - actual = "//third_party/nanopb", -) +workspace(name = "com_github_grpc_grpc") -bind( - name = "libssl", - actual = "@boringssl//:ssl", -) - -bind( - name = "zlib", - actual = "@com_github_madler_zlib//:z", -) - -bind( - name = "protobuf", - actual = "@com_google_protobuf//:protobuf", -) - -bind( - name = "protobuf_clib", - actual = "@com_google_protobuf//:protoc_lib", -) - -bind( - name = "protobuf_headers", - actual = "@com_google_protobuf//:protobuf_headers", -) - -bind( - name = "protocol_compiler", - actual = "@com_google_protobuf//:protoc", -) - -bind( - name = "cares", - actual = "@com_github_cares_cares//:ares", -) - -bind( - name = "gtest", - actual = "@com_github_google_googletest//:gtest", -) - -bind( - name = "gmock", - actual = "@com_github_google_googletest//:gmock", -) - -bind( - name = "benchmark", - actual = "@com_github_google_benchmark//:benchmark", -) - -bind( - name = "gflags", - actual = "@com_github_gflags_gflags//:gflags", -) - -http_archive( - name = "boringssl", - # on the master-with-bazel branch - url = "https://boringssl.googlesource.com/boringssl/+archive/886e7d75368e3f4fab3f4d0d3584e4abfc557755.tar.gz", -) - -new_http_archive( - name = "com_github_madler_zlib", - build_file = "third_party/zlib.BUILD", - strip_prefix = "zlib-cacf7f1d4e3d44d871b605da3b647f07d718623f", - url = "https://github.com/madler/zlib/archive/cacf7f1d4e3d44d871b605da3b647f07d718623f.tar.gz", -) - -http_archive( - name = "com_google_protobuf", - strip_prefix = "protobuf-2761122b810fe8861004ae785cc3ab39f384d342", - url = "https://github.com/google/protobuf/archive/2761122b810fe8861004ae785cc3ab39f384d342.tar.gz", -) - -new_http_archive( - name = "com_github_google_googletest", - build_file = "third_party/gtest.BUILD", - strip_prefix = "googletest-ec44c6c1675c25b9827aacd08c02433cccde7780", - url = "https://github.com/google/googletest/archive/ec44c6c1675c25b9827aacd08c02433cccde7780.tar.gz", -) - -http_archive( - name = "com_github_gflags_gflags", - strip_prefix = "gflags-30dbc81fb5ffdc98ea9b14b1918bfe4e8779b26e", - url = "https://github.com/gflags/gflags/archive/30dbc81fb5ffdc98ea9b14b1918bfe4e8779b26e.tar.gz", -) - -new_http_archive( - name = "com_github_google_benchmark", - build_file = "third_party/benchmark.BUILD", - strip_prefix = "benchmark-5b7683f49e1e9223cf9927b24f6fd3d6bd82e3f8", - url = "https://github.com/google/benchmark/archive/5b7683f49e1e9223cf9927b24f6fd3d6bd82e3f8.tar.gz", -) - -new_local_repository( - name = "cares_local_files", - build_file = "third_party/cares/cares_local_files.BUILD", - path = "third_party/cares", -) - -new_http_archive( - name = "com_github_cares_cares", - build_file = "third_party/cares/cares.BUILD", - strip_prefix = "c-ares-3be1924221e1326df520f8498d704a5c4c8d0cce", - url = "https://github.com/c-ares/c-ares/archive/3be1924221e1326df520f8498d704a5c4c8d0cce.tar.gz", -) - -http_archive( - name = "com_google_absl", - strip_prefix = "abseil-cpp-cc4bed2d74f7c8717e31f9579214ab52a9c9c610", - url = "https://github.com/abseil/abseil-cpp/archive/cc4bed2d74f7c8717e31f9579214ab52a9c9c610.tar.gz", -) - -http_archive( - name = "bazel_toolchains", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/archive/af4681c3d19f063f090222ec3d04108c4e0ca255.tar.gz", - "https://github.com/bazelbuild/bazel-toolchains/archive/af4681c3d19f063f090222ec3d04108c4e0ca255.tar.gz", - ], - strip_prefix = "bazel-toolchains-af4681c3d19f063f090222ec3d04108c4e0ca255", - sha256 = "d58bb2d6c8603f600d522b6104d6192a65339aa26cbba9f11ff5c4b36dedb928", -) +load("//bazel:grpc_deps.bzl", "grpc_deps") +grpc_deps() diff --git a/bazel/grpc_deps.bzl b/bazel/grpc_deps.bzl new file mode 100644 index 00000000000..fd848d80e65 --- /dev/null +++ b/bazel/grpc_deps.bzl @@ -0,0 +1,112 @@ +def grpc_deps(): + native.bind( + name = "nanopb", + actual = "@com_github_grpc_grpc//third_party/nanopb", + ) + + native.bind( + name = "libssl", + actual = "@boringssl//:ssl", + ) + + native.bind( + name = "zlib", + actual = "@com_github_madler_zlib//:z", + ) + + native.bind( + name = "protobuf", + actual = "@com_google_protobuf//:protobuf", + ) + + native.bind( + name = "protobuf_clib", + actual = "@com_google_protobuf//:protoc_lib", + ) + + native.bind( + name = "protobuf_headers", + actual = "@com_google_protobuf//:protobuf_headers", + ) + + native.bind( + name = "protocol_compiler", + actual = "@com_google_protobuf//:protoc", + ) + + native.bind( + name = "cares", + actual = "@com_github_cares_cares//:ares", + ) + + native.bind( + name = "gtest", + actual = "@com_github_google_googletest//:gtest", + ) + + native.bind( + name = "gmock", + actual = "@com_github_google_googletest//:gmock", + ) + + native.bind( + name = "benchmark", + actual = "@com_github_google_benchmark//:benchmark", + ) + + native.bind( + name = "gflags", + actual = "@com_github_gflags_gflags//:gflags", + ) + + native.http_archive( + name = "boringssl", + # on the master-with-bazel branch + url = "https://boringssl.googlesource.com/boringssl/+archive/886e7d75368e3f4fab3f4d0d3584e4abfc557755.tar.gz", + ) + + native.new_http_archive( + name = "com_github_madler_zlib", + build_file = "@com_github_grpc_grpc//third_party:zlib.BUILD", + strip_prefix = "zlib-cacf7f1d4e3d44d871b605da3b647f07d718623f", + url = "https://github.com/madler/zlib/archive/cacf7f1d4e3d44d871b605da3b647f07d718623f.tar.gz", + ) + + native.http_archive( + name = "com_google_protobuf", + strip_prefix = "protobuf-80a37e0782d2d702d52234b62dd4b9ec74fd2c95", + url = "https://github.com/google/protobuf/archive/80a37e0782d2d702d52234b62dd4b9ec74fd2c95.tar.gz", + ) + + native.new_http_archive( + name = "com_github_google_googletest", + build_file = "@com_github_grpc_grpc//third_party:gtest.BUILD", + strip_prefix = "googletest-ec44c6c1675c25b9827aacd08c02433cccde7780", + url = "https://github.com/google/googletest/archive/ec44c6c1675c25b9827aacd08c02433cccde7780.tar.gz", + ) + + native.http_archive( + name = "com_github_gflags_gflags", + strip_prefix = "gflags-30dbc81fb5ffdc98ea9b14b1918bfe4e8779b26e", + url = "https://github.com/gflags/gflags/archive/30dbc81fb5ffdc98ea9b14b1918bfe4e8779b26e.tar.gz", + ) + + native.new_http_archive( + name = "com_github_google_benchmark", + build_file = "@com_github_grpc_grpc//third_party:benchmark.BUILD", + strip_prefix = "benchmark-5b7683f49e1e9223cf9927b24f6fd3d6bd82e3f8", + url = "https://github.com/google/benchmark/archive/5b7683f49e1e9223cf9927b24f6fd3d6bd82e3f8.tar.gz", + ) + + native.new_http_archive( + name = "com_github_cares_cares", + build_file = "@com_github_grpc_grpc//third_party:cares/cares.BUILD", + strip_prefix = "c-ares-3be1924221e1326df520f8498d704a5c4c8d0cce", + url = "https://github.com/c-ares/c-ares/archive/3be1924221e1326df520f8498d704a5c4c8d0cce.tar.gz", + ) + + native.http_archive( + name = "com_google_absl", + strip_prefix = "abseil-cpp-cc4bed2d74f7c8717e31f9579214ab52a9c9c610", + url = "https://github.com/abseil/abseil-cpp/archive/cc4bed2d74f7c8717e31f9579214ab52a9c9c610.tar.gz", + ) diff --git a/third_party/BUILD b/third_party/BUILD new file mode 100644 index 00000000000..dea1229684b --- /dev/null +++ b/third_party/BUILD @@ -0,0 +1,6 @@ +exports_files([ + "benchmark.BUILD", + "gtest.BUILD", + "objective_c/Cronet/bidirectional_stream_c.h", + "zlib.BUILD", +]) diff --git a/third_party/cares/BUILD b/third_party/cares/BUILD new file mode 100644 index 00000000000..ad27d93c0f5 --- /dev/null +++ b/third_party/cares/BUILD @@ -0,0 +1,9 @@ +exports_files([ + "ares_build.h", + "cares.BUILD", + "config_android/ares_config.h", + "config_darwin/ares_config.h", + "config_freebsd/ares_config.h", + "config_linux/ares_config.h", + "config_openbsd/ares_config.h", +]) diff --git a/third_party/cares/cares.BUILD b/third_party/cares/cares.BUILD index 85ca506ab0d..3ac02875e68 100644 --- a/third_party/cares/cares.BUILD +++ b/third_party/cares/cares.BUILD @@ -35,33 +35,27 @@ config_setting( ) genrule( - name = "ares_build", - srcs = ["@cares_local_files//:ares_build_h"], + name = "ares_build_h", + srcs = ["@com_github_grpc_grpc//third_party/cares:ares_build.h"], outs = ["ares_build.h"], - cmd = "cat $(location @cares_local_files//:ares_build_h) > $@", + cmd = "cat $< > $@", ) -# cc_library( -# name = "ares_build_h", -# hdrs = ["ares_build.h"], -# data = [":ares_build"], -# includes = ["."], -# ) - genrule( - name = "ares_config", - srcs = ["@cares_local_files//:ares_config_h"], + name = "ares_config_h", + srcs = select({ + ":ios_x86_64": ["@com_github_grpc_grpc//third_party/cares:config_darwin/ares_config.h"], + ":ios_armv7": ["@com_github_grpc_grpc//third_party/cares:config_darwin/ares_config.h"], + ":ios_armv7s": ["@com_github_grpc_grpc//third_party/cares:config_darwin/ares_config.h"], + ":ios_arm64": ["@com_github_grpc_grpc//third_party/cares:config_darwin/ares_config.h"], + ":darwin": ["@com_github_grpc_grpc//third_party/cares:config_darwin/ares_config.h"], + ":android": ["@com_github_grpc_grpc//third_party/cares:config_android/ares_config.h"], + "//conditions:default": ["@com_github_grpc_grpc//third_party/cares:config_linux/ares_config.h"], + }), outs = ["ares_config.h"], - cmd = "cat $(location @cares_local_files//:ares_config_h) > $@", + cmd = "cat $< > $@", ) -# cc_library( -# name = "ares_config_h", -# hdrs = ["ares_config.h"], -# data = [":ares_config"], -# includes = ["."], -# ) - cc_library( name = "ares", srcs = [ @@ -147,10 +141,6 @@ cc_library( "-DNOMINMAX", "-DHAVE_CONFIG_H", ], - data = [ - ":ares_build", - ":ares_config", - ], includes = ["."], linkstatic = 1, visibility = [ diff --git a/third_party/cares/cares_local_files.BUILD b/third_party/cares/cares_local_files.BUILD deleted file mode 100644 index fe59447beb3..00000000000 --- a/third_party/cares/cares_local_files.BUILD +++ /dev/null @@ -1,57 +0,0 @@ -package( - default_visibility = ["//visibility:public"], -) - -config_setting( - name = "darwin", - values = {"cpu": "darwin"}, -) - -# Android is not officially supported through C++. -# This just helps with the build for now. -config_setting( - name = "android", - values = { - "crosstool_top": "//external:android/crosstool", - }, -) - -# iOS is not officially supported through C++. -# This just helps with the build for now. -config_setting( - name = "ios_x86_64", - values = {"cpu": "ios_x86_64"}, -) - -config_setting( - name = "ios_armv7", - values = {"cpu": "ios_armv7"}, -) - -config_setting( - name = "ios_armv7s", - values = {"cpu": "ios_armv7s"}, -) - -config_setting( - name = "ios_arm64", - values = {"cpu": "ios_arm64"}, -) - -filegroup( - name = "ares_build_h", - srcs = ["ares_build.h"], -) - -filegroup( - name = "ares_config_h", - srcs = select({ - ":ios_x86_64": ["config_darwin/ares_config.h"], - ":ios_armv7": ["config_darwin/ares_config.h"], - ":ios_armv7s": ["config_darwin/ares_config.h"], - ":ios_arm64": ["config_darwin/ares_config.h"], - ":darwin": ["config_darwin/ares_config.h"], - ":android": ["config_android/ares_config.h"], - "//conditions:default": ["config_linux/ares_config.h"], - }), -)