Merge pull request #13060 from jwpowell055/master

Allow Bazel to build gRPC as a third-party dependency without git submodules
pull/13288/head
Nicolas Noble 7 years ago committed by GitHub
commit 240762d4c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 61
      WORKSPACE
  2. 209
      third_party/cares/cares.BUILD
  3. 57
      third_party/cares/cares_local_files.BUILD
  4. 49
      tools/run_tests/sanity/check_bazel_workspace.py
  5. 1
      tools/run_tests/sanity/sanity_tests.yaml

@ -10,7 +10,7 @@ bind(
bind(
name = "zlib",
actual = "@submodule_zlib//:z",
actual = "@com_github_madler_zlib//:z",
)
bind(
@ -35,22 +35,22 @@ bind(
bind(
name = "cares",
actual = "@submodule_cares//:ares",
actual = "@com_github_cares_cares//:ares",
)
bind(
name = "gtest",
actual = "@submodule_gtest//:gtest",
actual = "@com_github_google_googletest//:gtest",
)
bind(
name = "gmock",
actual = "@submodule_gtest//:gmock",
actual = "@com_github_google_googletest//:gmock",
)
bind(
name = "benchmark",
actual = "@submodule_benchmark//:benchmark",
actual = "@com_github_google_benchmark//:benchmark",
)
bind(
@ -58,47 +58,60 @@ bind(
actual = "@com_github_gflags_gflags//:gflags",
)
local_repository(
http_archive(
name = "boringssl",
path = "third_party/boringssl-with-bazel",
# on the master-with-bazel branch
url = "https://boringssl.googlesource.com/boringssl/+archive/886e7d75368e3f4fab3f4d0d3584e4abfc557755.tar.gz",
)
new_local_repository(
name = "submodule_zlib",
new_http_archive(
name = "com_github_madler_zlib",
build_file = "third_party/zlib.BUILD",
path = "third_party/zlib",
strip_prefix = "zlib-cacf7f1d4e3d44d871b605da3b647f07d718623f",
url = "https://github.com/madler/zlib/archive/cacf7f1d4e3d44d871b605da3b647f07d718623f.tar.gz",
)
new_local_repository(
http_archive(
name = "com_google_protobuf",
build_file = "third_party/protobuf/BUILD",
path = "third_party/protobuf",
strip_prefix = "protobuf-80a37e0782d2d702d52234b62dd4b9ec74fd2c95",
url = "https://github.com/google/protobuf/archive/80a37e0782d2d702d52234b62dd4b9ec74fd2c95.tar.gz",
)
new_local_repository(
name = "submodule_gtest",
new_http_archive(
name = "com_github_google_googletest",
build_file = "third_party/gtest.BUILD",
path = "third_party/googletest",
strip_prefix = "googletest-ec44c6c1675c25b9827aacd08c02433cccde7780",
url = "https://github.com/google/googletest/archive/ec44c6c1675c25b9827aacd08c02433cccde7780.tar.gz",
)
local_repository(
http_archive(
name = "com_github_gflags_gflags",
path = "third_party/gflags",
strip_prefix = "gflags-30dbc81fb5ffdc98ea9b14b1918bfe4e8779b26e",
url = "https://github.com/gflags/gflags/archive/30dbc81fb5ffdc98ea9b14b1918bfe4e8779b26e.tar.gz",
)
new_local_repository(
name = "submodule_benchmark",
path = "third_party/benchmark",
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 = "submodule_cares",
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",
)
local_repository(
http_archive(
name = "com_google_absl",
path = "third_party/abseil-cpp",
strip_prefix = "abseil-cpp-cc4bed2d74f7c8717e31f9579214ab52a9c9c610",
url = "https://github.com/abseil/abseil-cpp/archive/cc4bed2d74f7c8717e31f9579214ab52a9c9c610.tar.gz",
)

@ -8,7 +8,7 @@ config_setting(
config_setting(
name = "android",
values = {
"crosstool_top": "//external:android/crosstool",
"crosstool_top": "//external:android/crosstool",
},
)
@ -18,120 +18,128 @@ 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"},
)
genrule(
name = "ares_build",
srcs = ["@cares_local_files//:ares_build_h"],
outs = ["ares_build.h"],
cmd = "cat $(location @cares_local_files//:ares_build_h) > $@",
)
# 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"],
outs = ["ares_config.h"],
cmd = "cat $(location @cares_local_files//:ares_config_h) > $@",
)
# cc_library(
# name = "ares_config_h",
# hdrs = ["ares_config.h"],
# data = [":ares_config"],
# includes = ["."],
# )
cc_library(
name = "ares",
srcs = [
"cares/ares__close_sockets.c",
"cares/ares__get_hostent.c",
"cares/ares__read_line.c",
"cares/ares__timeval.c",
"cares/ares_cancel.c",
"cares/ares_create_query.c",
"cares/ares_data.c",
"cares/ares_destroy.c",
"cares/ares_expand_name.c",
"cares/ares_expand_string.c",
"cares/ares_fds.c",
"cares/ares_free_hostent.c",
"cares/ares_free_string.c",
"cares/ares_getenv.c",
"cares/ares_gethostbyaddr.c",
"cares/ares_gethostbyname.c",
"cares/ares_getnameinfo.c",
"cares/ares_getopt.c",
"cares/ares_getsock.c",
"cares/ares_init.c",
"cares/ares_library_init.c",
"cares/ares_llist.c",
"cares/ares_mkquery.c",
"cares/ares_nowarn.c",
"cares/ares_options.c",
"cares/ares_parse_a_reply.c",
"cares/ares_parse_aaaa_reply.c",
"cares/ares_parse_mx_reply.c",
"cares/ares_parse_naptr_reply.c",
"cares/ares_parse_ns_reply.c",
"cares/ares_parse_ptr_reply.c",
"cares/ares_parse_soa_reply.c",
"cares/ares_parse_srv_reply.c",
"cares/ares_parse_txt_reply.c",
"cares/ares_platform.c",
"cares/ares_process.c",
"cares/ares_query.c",
"cares/ares_search.c",
"cares/ares_send.c",
"cares/ares_strcasecmp.c",
"cares/ares_strdup.c",
"cares/ares_strerror.c",
"cares/ares_timeout.c",
"cares/ares_version.c",
"cares/ares_writev.c",
"cares/bitncmp.c",
"cares/inet_net_pton.c",
"cares/inet_ntop.c",
"cares/windows_port.c",
"ares__close_sockets.c",
"ares__get_hostent.c",
"ares__read_line.c",
"ares__timeval.c",
"ares_cancel.c",
"ares_create_query.c",
"ares_data.c",
"ares_destroy.c",
"ares_expand_name.c",
"ares_expand_string.c",
"ares_fds.c",
"ares_free_hostent.c",
"ares_free_string.c",
"ares_getenv.c",
"ares_gethostbyaddr.c",
"ares_gethostbyname.c",
"ares_getnameinfo.c",
"ares_getopt.c",
"ares_getsock.c",
"ares_init.c",
"ares_library_init.c",
"ares_llist.c",
"ares_mkquery.c",
"ares_nowarn.c",
"ares_options.c",
"ares_parse_a_reply.c",
"ares_parse_aaaa_reply.c",
"ares_parse_mx_reply.c",
"ares_parse_naptr_reply.c",
"ares_parse_ns_reply.c",
"ares_parse_ptr_reply.c",
"ares_parse_soa_reply.c",
"ares_parse_srv_reply.c",
"ares_parse_txt_reply.c",
"ares_platform.c",
"ares_process.c",
"ares_query.c",
"ares_search.c",
"ares_send.c",
"ares_strcasecmp.c",
"ares_strdup.c",
"ares_strerror.c",
"ares_timeout.c",
"ares_version.c",
"ares_writev.c",
"bitncmp.c",
"inet_net_pton.c",
"inet_ntop.c",
"windows_port.c",
],
hdrs = [
"ares.h",
"ares_build.h",
"cares/ares.h",
"cares/ares_data.h",
"cares/ares_dns.h",
"cares/ares_getenv.h",
"cares/ares_getopt.h",
"cares/ares_inet_net_pton.h",
"cares/ares_iphlpapi.h",
"cares/ares_ipv6.h",
"cares/ares_library_init.h",
"cares/ares_llist.h",
"cares/ares_nowarn.h",
"cares/ares_platform.h",
"cares/ares_private.h",
"cares/ares_rules.h",
"cares/ares_setup.h",
"cares/ares_strcasecmp.h",
"cares/ares_strdup.h",
"cares/ares_version.h",
"cares/bitncmp.h",
"cares/config-win32.h",
"cares/nameser.h",
"cares/setup_once.h",
] + 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"],
}),
includes = [
".",
"cares"
] + select({
":ios_x86_64": ["config_darwin"],
":ios_armv7": ["config_darwin"],
":ios_armv7s": ["config_darwin"],
":ios_arm64": ["config_darwin"],
":darwin": ["config_darwin"],
":android": ["config_android"],
"//conditions:default": ["config_linux"],
}),
linkstatic = 1,
visibility = [
"//visibility:public",
"ares_config.h",
"ares_data.h",
"ares_dns.h",
"ares_getenv.h",
"ares_getopt.h",
"ares_inet_net_pton.h",
"ares_iphlpapi.h",
"ares_ipv6.h",
"ares_library_init.h",
"ares_llist.h",
"ares_nowarn.h",
"ares_platform.h",
"ares_private.h",
"ares_rules.h",
"ares_setup.h",
"ares_strcasecmp.h",
"ares_strdup.h",
"ares_version.h",
"bitncmp.h",
"config-win32.h",
"nameser.h",
"setup_once.h",
],
copts = [
"-D_GNU_SOURCE",
@ -139,4 +147,13 @@ cc_library(
"-DNOMINMAX",
"-DHAVE_CONFIG_H",
],
data = [
":ares_build",
":ares_config",
],
includes = ["."],
linkstatic = 1,
visibility = [
"//visibility:public",
],
)

@ -0,0 +1,57 @@
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"],
}),
)

@ -0,0 +1,49 @@
#!/usr/bin/env python
# Copyright 2016 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import ast
import os
import re
import subprocess
import sys
os.chdir(os.path.join(os.path.dirname(sys.argv[0]), '../../..'))
git_hash_pattern = re.compile('[0-9a-f]{40}')
# Parse git hashes from submodules
git_submodules = subprocess.check_output('git submodule', shell=True).strip().split('\n')
git_submodule_hashes = {re.search(git_hash_pattern, s).group() for s in git_submodules}
# Parse git hashes from Bazel WORKSPACE {new_}http_archive rules
with open('WORKSPACE', 'r') as f:
workspace_rules = [expr.value for expr in ast.parse(f.read()).body]
http_archive_rules = [rule for rule in workspace_rules if rule.func.id.endswith('http_archive')]
archive_urls = [kw.value.s for rule in http_archive_rules for kw in rule.keywords if kw.arg == 'url']
workspace_git_hashes = {re.search(git_hash_pattern, url).group() for url in archive_urls}
# Validate the equivalence of the git submodules and Bazel git dependencies. The
# condition we impose is that there is a git submodule for every dependency in
# the workspace, but not necessarily conversely. E.g. Bloaty is a dependency
# not used by any of the targets built by Bazel.
if len(workspace_git_hashes - git_submodule_hashes) > 0:
print("Found discrepancies between git submodules and Bazel WORKSPACE dependencies")
sys.exit(1)
sys.exit(0)

@ -1,4 +1,5 @@
# a set of tests that are run in parallel for sanity tests
- script: tools/run_tests/sanity/check_bazel_workspace.py
- script: tools/run_tests/sanity/check_cache_mk.sh
- script: tools/run_tests/sanity/check_owners.sh
- script: tools/run_tests/sanity/check_sources_and_headers.py

Loading…
Cancel
Save