From 8135afcdbf90630f194650140562a93b492d8578 Mon Sep 17 00:00:00 2001 From: Lizan Zhou Date: Thu, 2 Feb 2017 17:47:00 -0800 Subject: [PATCH 1/5] Add bazel BUILD file --- .gitignore | 1 + BUILD | 152 +++++++++++++ WORKSPACE | 33 +++ repositories.bzl | 559 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 745 insertions(+) create mode 100644 BUILD create mode 100644 WORKSPACE create mode 100644 repositories.bzl diff --git a/.gitignore b/.gitignore index 3c07f45d3536..6724ec93aba1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /generated cscope.* BROWSE +bazel-* diff --git a/BUILD b/BUILD new file mode 100644 index 000000000000..f814eb14aa51 --- /dev/null +++ b/BUILD @@ -0,0 +1,152 @@ +load("@protobuf_git//:protobuf.bzl", "cc_proto_library") + +exports_files(["source/precompiled/precompiled.h"]) + +package(default_visibility = ["//visibility:public"]) + +genrule( + name = "envoy-ratelimit-proto", + srcs = [ + "source/common/ratelimit/ratelimit.proto", + ], + outs = [ + "source/common/generated/ratelimit.proto", + ], + cmd = "cp $(SRCS) $@", +) + +cc_proto_library( + name = "envoy-ratelimit-pb", + srcs = [ + "source/common/generated/ratelimit.proto", + ], + default_runtime = "//external:protobuf", + protoc = "//external:protoc", + include = "source", +) + +genrule( + name = "envoy-test-proto", + srcs = [ + "test/proto/helloworld.proto", + ], + outs = [ + "test/generated/helloworld.proto", + ], + cmd = "cp $(SRCS) $@", +) + +cc_proto_library( + name = "envoy-test-pb", + srcs = [ + "test/generated/helloworld.proto", + ], + default_runtime = "//external:protobuf", + protoc = "//external:protoc", + include = "test", +) + +genrule( + name = "envoy-version", + srcs = glob([ + ".git/**", + ]), + tools = [ + "tools/gen_git_sha.sh", + ], + outs = [ + "source/common/version_generated.cc", + ], + cmd = "touch $@ && $(location tools/gen_git_sha.sh) $$(dirname $(location tools/gen_git_sha.sh)) $@", + local = 1, +) + +cc_library( + name = "envoy-common", + srcs = glob([ + "source/**/*.cc", + "source/**/*.h", + "include/**/*.h", + ], exclude=["source/exe/main.cc"]) + [ + "source/common/version_generated.cc", + ], + copts = [ + "-includesource/precompiled/precompiled.h", + ], + includes = [ + "include", + "source", + ], + linkopts = [ + "-lpthread", + "-lanl", + "-lrt", + ], + linkstatic=1, + alwayslink=1, + deps = [ + ":envoy-ratelimit-pb", + "//external:libssl", + "//external:nghttp2", + "//external:spdlog", + "//external:tclap", + "//external:lightstep", + "//external:event", + "//external:protobuf", + "//external:http_parser", + "//external:rapidjson", + "//external:event_pthreads", + ], +) + +cc_binary( + name = "envoy", + srcs = [ + "source/exe/main.cc", + ], + copts = [ + "-includesource/precompiled/precompiled.h", + ], + deps = [ + ":envoy-common", + ], + linkstatic=1, +) + +cc_library( + name = "envoy-test-lib", + srcs = glob([ + "test/**/*.cc", + "test/**/*.h", + ]), + copts = [ + "-includetest/precompiled/precompiled_test.h", + ], + deps = [ + ":envoy-common", + ":envoy-test-pb", + "//external:googletest", + ], + alwayslink=1, +) + +filegroup( + name = "envoy-testdata", + srcs = glob([ + "generated/**/*", + "test/**/*", + ]), +) + +cc_test( + name = "envoy-test", + data = [ + ":envoy-testdata", + ], + deps = [ + ":envoy-test-lib", + ":envoy-test-pb", + "//external:googletest", + ], + linkstatic=1, +) diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 000000000000..d0bc5195b423 --- /dev/null +++ b/WORKSPACE @@ -0,0 +1,33 @@ +load( + "//:repositories.bzl", + "boringssl_repositories", + "protobuf_repositories", + "googletest_repositories", + "libevent_repositories", + "spdlog_repositories", + "tclap_repositories", + "lightstep_repositories", + "http_parser_repositories", + "rapidjson_repositories", + "nghttp2_repositories", +) + +boringssl_repositories() + +protobuf_repositories() + +googletest_repositories() + +libevent_repositories() + +spdlog_repositories() + +tclap_repositories() + +lightstep_repositories() + +http_parser_repositories() + +rapidjson_repositories() + +nghttp2_repositories() diff --git a/repositories.bzl b/repositories.bzl new file mode 100644 index 000000000000..c65db6a268ea --- /dev/null +++ b/repositories.bzl @@ -0,0 +1,559 @@ +def boringssl_repositories(bind=True): + native.git_repository( + name = "boringssl", + commit = "bfd36df3da38dbf8828e712f42fbab2a0034bc40", # 2017-02-02 + remote = "https://boringssl.googlesource.com/boringssl", + ) + + if bind: + native.bind( + name = "boringssl_crypto", + actual = "@boringssl//:crypto", + ) + + native.bind( + name = "libssl", + actual = "@boringssl//:ssl", + ) + + +def protobuf_repositories(bind=True): + native.git_repository( + name = "protobuf_git", + commit = "a428e42072765993ff674fda72863c9f1aa2d268", # v3.1.0 + remote = "https://github.com/google/protobuf.git", + ) + + if bind: + native.bind( + name = "protoc", + actual = "@protobuf_git//:protoc", + ) + + native.bind( + name = "protobuf", + actual = "@protobuf_git//:protobuf", + ) + + native.bind( + name = "cc_wkt_protos", + actual = "@protobuf_git//:cc_wkt_protos", + ) + + native.bind( + name = "cc_wkt_protos_genproto", + actual = "@protobuf_git//:cc_wkt_protos_genproto", + ) + + native.bind( + name = "protobuf_compiler", + actual = "@protobuf_git//:protoc_lib", + ) + +def googletest_repositories(bind=True): + BUILD = """ +# Copyright 2016 Google Inc. All Rights Reserved. +# +# 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. +# +################################################################################ +# + +cc_library( + name = "googletest", + srcs = [ + "googletest/src/gtest-all.cc", + "googlemock/src/gmock-all.cc", + ], + hdrs = glob([ + "googletest/include/**/*.h", + "googlemock/include/**/*.h", + "googletest/src/*.cc", + "googletest/src/*.h", + "googlemock/src/*.cc", + ]), + includes = [ + "googlemock", + "googletest", + "googletest/include", + "googlemock/include", + ], + visibility = ["//visibility:public"], +) + +cc_library( + name = "googletest_main", + srcs = ["googlemock/src/gmock_main.cc"], + visibility = ["//visibility:public"], + deps = [":googletest"], +) + +cc_library( + name = "googletest_prod", + hdrs = [ + "googletest/include/gtest/gtest_prod.h", + ], + includes = [ + "googletest/include", + ], + visibility = ["//visibility:public"], +) +""" + native.new_git_repository( + name = "googletest_git", + build_file_content = BUILD, + commit = "d225acc90bc3a8c420a9bcd1f033033c1ccd7fe0", + remote = "https://github.com/google/googletest.git", + ) + + if bind: + native.bind( + name = "googletest", + actual = "@googletest_git//:googletest", + ) + + native.bind( + name = "googletest_main", + actual = "@googletest_git//:googletest_main", + ) + + native.bind( + name = "googletest_prod", + actual = "@googletest_git//:googletest_prod", + ) + +def libevent_repositories(bind=True): + BUILD = """ +genrule( + name = "config", + srcs = glob([ + "**/*", + ]), + outs = [ + "config.h", + ], + tools = [ + "configure", + ], + cmd = ' '.join([ + "$(location configure) --enable-shared=no --disable-libevent-regress --disable-openssl", + "&& cp config.h $@", + ]), +) + +genrule( + name = "event-config", + srcs = [ + "config.h", + "make-event-config.sed", + ], + outs = [ + "include/event2/event-config.h", + ], + cmd = "sed -f $(location make-event-config.sed) < $(location config.h) > $@", +) + +event_srcs = [ + "buffer.c", + "bufferevent.c", + "bufferevent_filter.c", + "bufferevent_pair.c", + "bufferevent_ratelim.c", + "bufferevent_sock.c", + "epoll.c", + "evdns.c", + "event.c", + "event_tagging.c", + "evmap.c", + "evrpc.c", + "evthread.c", + "evutil.c", + "evutil_rand.c", + "http.c", + "listener.c", + "log.c", + "poll.c", + "select.c", + "signal.c", + "strlcpy.c", + ":event-config", +] + glob(["*.h"]) + + +event_pthread_srcs = [ + "evthread_pthread.c", + ":event-config", +] + +cc_library( + name = "event", + hdrs = glob(["include/**/*.h"]) + [ + "arc4random.c", # arc4random.c is included by evutil_rand.c + "bufferevent-internal.h", + "defer-internal.h", + "evbuffer-internal.h", + "event-internal.h", + "event.h", + "evthread-internal.h", + "evutil.h", + "http-internal.h", + "iocp-internal.h", + "ipv6-internal.h", + "log-internal.h", + "minheap-internal.h", + "mm-internal.h", + "strlcpy-internal.h", + "util-internal.h", + "compat/sys/queue.h", + ], + srcs = event_srcs, + includes = [ + "include", + "compat", + ], + copts = [ + "-w", + "-DHAVE_CONFIG_H", + ], + visibility = ["//visibility:public"], +) + +cc_library( + name = "event_pthreads", + srcs = event_pthread_srcs + ["include/event2/thread.h"], + hdrs = [ + "evthread-internal.h", + "compat/sys/queue.h", + ], + copts = [ + "-w", + "-DHAVE_CONFIG_H", + ], + includes = [ + "include", + "compat", + ], + deps = [ + ":event", + ], + visibility = ["//visibility:public"], +)""" + + native.new_http_archive( + name = "libevent_git", + url = "https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz", + strip_prefix = "libevent-2.0.22-stable", + build_file_content = BUILD, + ) + + if bind: + native.bind( + name = "event", + actual = "@libevent_git//:event", + ) + + native.bind( + name = "event_pthreads", + actual = "@libevent_git//:event_pthreads", + ) + + +def spdlog_repositories(bind=True): + BUILD = """ +package(default_visibility=["//visibility:public"]) + +cc_library( + name = "spdlog", + hdrs = glob([ + "include/**/*.h", + "include/**/*.cc", + ]), + includes = [ + "include", + ], +)""" + + native.new_git_repository( + name = "spdlog_git", + remote = "https://github.com/gabime/spdlog.git", + commit = "1f1f6a5f3b424203a429e9cb78e6548037adefa8", + build_file_content = BUILD, + ) + + if bind: + native.bind( + name = "spdlog", + actual = "@spdlog_git//:spdlog", + ) + +def tclap_repositories(bind=True): + BUILD = """ +cc_library( + name = "tclap", + hdrs = [ + "include/tclap/Arg.h", + "include/tclap/ArgException.h", + "include/tclap/ArgTraits.h", + "include/tclap/CmdLine.h", + "include/tclap/CmdLineInterface.h", + "include/tclap/CmdLineOutput.h", + "include/tclap/Constraint.h", + "include/tclap/DocBookOutput.h", + "include/tclap/HelpVisitor.h", + "include/tclap/IgnoreRestVisitor.h", + "include/tclap/MultiArg.h", + "include/tclap/MultiSwitchArg.h", + "include/tclap/OptionalUnlabeledTracker.h", + "include/tclap/StandardTraits.h", + "include/tclap/StdOutput.h", + "include/tclap/SwitchArg.h", + "include/tclap/UnlabeledMultiArg.h", + "include/tclap/UnlabeledValueArg.h", + "include/tclap/ValueArg.h", + "include/tclap/ValuesConstraint.h", + "include/tclap/VersionVisitor.h", + "include/tclap/Visitor.h", + "include/tclap/XorHandler.h", + "include/tclap/ZshCompletionOutput.h", + ], + defines = [ + "HAVE_LONG_LONG=1", + "HAVE_SSTREAM=1", + ], + includes = [ + "include", + ], + visibility = ["//visibility:public"], +)""" + + native.new_http_archive( + name = "tclap_tar", + url = "https://storage.googleapis.com/istio-build-deps/tclap-1.2.1.tar.gz", + strip_prefix = "tclap-1.2.1", + build_file_content = BUILD, + ) + if bind: + native.bind( + name = "tclap", + actual = "@tclap_tar//:tclap", + ) + +def lightstep_repositories(bind=True): + BUILD = """ +load("@protobuf_git//:protobuf.bzl", "cc_proto_library") + +genrule( + name = "envoy_carrier_pb", + srcs = ["src/c++11/envoy/envoy_carrier.proto"], + outs = ["lightstep/envoy_carrier.proto"], + cmd = "cp $(SRCS) $@", +) + +cc_proto_library( + name = "envoy_carrier_proto", + srcs = ["lightstep/envoy_carrier.proto"], + include = ".", + deps = [ + "//external:cc_wkt_protos", + ], + protoc = "//external:protoc", + default_runtime = "//external:protobuf", + visibility = ["//visibility:public"], +) + +cc_library( + name = "lightstep_core", + srcs = [ + "src/c++11/impl.cc", + "src/c++11/span.cc", + "src/c++11/tracer.cc", + "src/c++11/util.cc", + ], + hdrs = [ + "src/c++11/lightstep/impl.h", + "src/c++11/lightstep/options.h", + "src/c++11/lightstep/propagation.h", + "src/c++11/lightstep/envoy.h", + "src/c++11/lightstep/span.h", + "src/c++11/lightstep/tracer.h", + "src/c++11/lightstep/util.h", + "src/c++11/lightstep/value.h", + "src/c++11/mapbox_variant/recursive_wrapper.hpp", + "src/c++11/mapbox_variant/variant.hpp", + ], + copts = [ + "-DPACKAGE_VERSION='\\"0.19\\"'", + "-Iexternal/lightstep_git/src/c++11/lightstep", + "-Iexternal/lightstep_git/src/c++11/mapbox_variant", + ], + includes = [ + "src/c++11", + ], + visibility = ["//visibility:public"], + deps = [ + "@lightstep_common_git//:collector_proto", + ":envoy_carrier_proto", + "//external:protobuf", + ], +)""" + + COMMON_BUILD = """ +load("@protobuf_git//:protobuf.bzl", "cc_proto_library") + +genrule( + name = "collector_pb", + srcs = ["collector.proto"], + outs = ["lightstep/collector.proto"], + cmd = "cp $(SRCS) $@", +) + +cc_proto_library( + name = "collector_proto", + srcs = ["lightstep/collector.proto"], + include = ".", + deps = [ + "//external:cc_wkt_protos", + ], + protoc = "//external:protoc", + default_runtime = "//external:protobuf", + visibility = ["//visibility:public"], +)""" + + native.new_git_repository( + name = "lightstep_common_git", + remote = "https://github.com/lightstep/lightstep-tracer-common.git", + commit = "8d932f7f76cd286691e6179621d0012b0ff1e6aa", + build_file_content = COMMON_BUILD, + ) + + native.new_git_repository( + name = "lightstep_git", + remote = "https://github.com/lightstep/lightstep-tracer-cpp.git", + commit = "5a71d623cac17a059041b04fabca4ed86ffff7cc", + build_file_content = BUILD, + ) + + if bind: + native.bind( + name = "lightstep", + actual = "@lightstep_git//:lightstep_core", + ) + +def http_parser_repositories(bind=True): + BUILD = """ +cc_library( + name = "http_parser", + srcs = [ + "http_parser.c", + ], + hdrs = [ + "http_parser.h", + ], + visibility = ["//visibility:public"], +)""" + + native.new_git_repository( + name = "http_parser_git", + remote = "https://github.com/nodejs/http-parser.git", + commit = "9b0d5b33ebdaacff1dadd06bad4e198b11ff880e", + build_file_content = BUILD, + ) + + if bind: + native.bind( + name = "http_parser", + actual = "@http_parser_git//:http_parser", + ) + +def rapidjson_repositories(bind=True): + BUILD = """ +cc_library( + name = "rapidjson", + srcs = glob([ + "include/rapidjson/internal/*.h", + ]), + hdrs = glob([ + "include/rapidjson/*.h", + "include/rapidjson/error/*.h", + ]), + includes = ["include"], + visibility = ["//visibility:public"], +) +""" + + native.new_git_repository( + name = "rapidjson_git", + remote = "https://github.com/miloyip/rapidjson.git", + commit = "f54b0e47a08782a6131cc3d60f94d038fa6e0a51", # v1.1.0 + build_file_content = BUILD, + ) + + if bind: + native.bind( + name = "rapidjson", + actual = "@rapidjson_git//:rapidjson", + ) + +def nghttp2_repositories(bind=True): + BUILD = """ +genrule( + name = "config", + srcs = glob([ + "**/*", + ]), + outs = [ + "config.h", + ], + tools = [ + "configure", + ], + cmd = ' '.join([ + "$(location configure) --enable-lib-only --enable-shared=no", + "&& cp config.h $@", + ]), +) + +cc_library( + name = "nghttp2", + srcs = glob([ + "lib/*.c", + "lib/*.h", + ]) + ["config.h"], + hdrs = glob([ + "lib/includes/nghttp2/*.h", + ]), + copts = [ + "-DHAVE_CONFIG_H", + "-DBUILDING_NGHTTP2", + "-Iexternal/nghttp2_tar", + ], + includes = [ + ".", + "lib/includes", + ], + visibility = ["//visibility:public"], +) +""" + + native.new_http_archive( + name = "nghttp2_tar", + url = "https://github.com/nghttp2/nghttp2/releases/download/v1.14.1/nghttp2-1.14.1.tar.gz", + strip_prefix = "nghttp2-1.14.1", + build_file_content = BUILD, + ) + + if bind: + native.bind( + name = "nghttp2", + actual = "@nghttp2_tar//:nghttp2", + ) From 2d0f96c6ea048b8acf921675c4f02e4b6bdf6bcb Mon Sep 17 00:00:00 2001 From: Lizan Zhou Date: Thu, 2 Feb 2017 18:57:21 -0800 Subject: [PATCH 2/5] Add building instruction --- docs/install/building.rst | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/install/building.rst b/docs/install/building.rst index c34daa2ccd05..e6acb1c54ccb 100644 --- a/docs/install/building.rst +++ b/docs/install/building.rst @@ -27,3 +27,24 @@ available to turn on debug builds, address sanitizer, etc.). * :repo:`CMakeLists.txt` * :repo:`common.cmake` * :repo:`thirdparty.cmake` + +(Experimental) Building with Bazel_ + +Follow the instruction_ to install Bazel, then run following command to build Envoy: + +.. code-block:: console + + bazel build //:envoy + +The built binary will be at `bazel-bin/envoy` + +To run tests, run following command: + +.. code-block:: console + + bazel test //:envoy-test + +Note not all tests pass with Bazel yet. + +.. _Bazel: https://bazel.build/ +.. _instruction: https://bazel.build/versions/master/docs/install.html From a444344021eaf821fd99f2991d5d90f68063189d Mon Sep 17 00:00:00 2001 From: Lizan Zhou Date: Fri, 3 Feb 2017 12:46:41 -0800 Subject: [PATCH 3/5] Apply bulidifier --- BUILD | 45 +++++++++++++++++++------------------ repositories.bzl | 58 +++++++++++++++++++++++------------------------- 2 files changed, 52 insertions(+), 51 deletions(-) diff --git a/BUILD b/BUILD index f814eb14aa51..45c0bb7d1290 100644 --- a/BUILD +++ b/BUILD @@ -20,9 +20,9 @@ cc_proto_library( srcs = [ "source/common/generated/ratelimit.proto", ], + include = "source", default_runtime = "//external:protobuf", protoc = "//external:protoc", - include = "source", ) genrule( @@ -41,9 +41,9 @@ cc_proto_library( srcs = [ "test/generated/helloworld.proto", ], + include = "test", default_runtime = "//external:protobuf", protoc = "//external:protoc", - include = "test", ) genrule( @@ -51,23 +51,26 @@ genrule( srcs = glob([ ".git/**", ]), - tools = [ - "tools/gen_git_sha.sh", - ], outs = [ "source/common/version_generated.cc", ], cmd = "touch $@ && $(location tools/gen_git_sha.sh) $$(dirname $(location tools/gen_git_sha.sh)) $@", local = 1, + tools = [ + "tools/gen_git_sha.sh", + ], ) cc_library( name = "envoy-common", - srcs = glob([ - "source/**/*.cc", - "source/**/*.h", - "include/**/*.h", - ], exclude=["source/exe/main.cc"]) + [ + srcs = glob( + [ + "source/**/*.cc", + "source/**/*.h", + "include/**/*.h", + ], + exclude = ["source/exe/main.cc"], + ) + [ "source/common/version_generated.cc", ], copts = [ @@ -82,21 +85,21 @@ cc_library( "-lanl", "-lrt", ], - linkstatic=1, - alwayslink=1, + linkstatic = 1, deps = [ ":envoy-ratelimit-pb", + "//external:event", + "//external:event_pthreads", + "//external:http_parser", "//external:libssl", - "//external:nghttp2", - "//external:spdlog", - "//external:tclap", "//external:lightstep", - "//external:event", + "//external:nghttp2", "//external:protobuf", - "//external:http_parser", "//external:rapidjson", - "//external:event_pthreads", + "//external:spdlog", + "//external:tclap", ], + alwayslink = 1, ) cc_binary( @@ -107,10 +110,10 @@ cc_binary( copts = [ "-includesource/precompiled/precompiled.h", ], + linkstatic = 1, deps = [ ":envoy-common", ], - linkstatic=1, ) cc_library( @@ -127,7 +130,7 @@ cc_library( ":envoy-test-pb", "//external:googletest", ], - alwayslink=1, + alwayslink = 1, ) filegroup( @@ -143,10 +146,10 @@ cc_test( data = [ ":envoy-testdata", ], + linkstatic = 1, deps = [ ":envoy-test-lib", ":envoy-test-pb", "//external:googletest", ], - linkstatic=1, ) diff --git a/repositories.bzl b/repositories.bzl index c65db6a268ea..7d9dc4b09f90 100644 --- a/repositories.bzl +++ b/repositories.bzl @@ -72,8 +72,8 @@ def googletest_repositories(bind=True): cc_library( name = "googletest", srcs = [ - "googletest/src/gtest-all.cc", "googlemock/src/gmock-all.cc", + "googletest/src/gtest-all.cc", ], hdrs = glob([ "googletest/include/**/*.h", @@ -84,9 +84,9 @@ cc_library( ]), includes = [ "googlemock", + "googlemock/include", "googletest", "googletest/include", - "googlemock/include", ], visibility = ["//visibility:public"], ) @@ -142,13 +142,11 @@ genrule( outs = [ "config.h", ], + cmd = "$(location configure) --enable-shared=no --disable-libevent-regress --disable-openssl" + + " && cp config.h $@", tools = [ "configure", ], - cmd = ' '.join([ - "$(location configure) --enable-shared=no --disable-libevent-regress --disable-openssl", - "&& cp config.h $@", - ]), ) genrule( @@ -189,7 +187,6 @@ event_srcs = [ ":event-config", ] + glob(["*.h"]) - event_pthread_srcs = [ "evthread_pthread.c", ":event-config", @@ -197,6 +194,7 @@ event_pthread_srcs = [ cc_library( name = "event", + srcs = event_srcs, hdrs = glob(["include/**/*.h"]) + [ "arc4random.c", # arc4random.c is included by evutil_rand.c "bufferevent-internal.h", @@ -216,15 +214,14 @@ cc_library( "util-internal.h", "compat/sys/queue.h", ], - srcs = event_srcs, - includes = [ - "include", - "compat", - ], copts = [ "-w", "-DHAVE_CONFIG_H", ], + includes = [ + "compat", + "include", + ], visibility = ["//visibility:public"], ) @@ -232,22 +229,23 @@ cc_library( name = "event_pthreads", srcs = event_pthread_srcs + ["include/event2/thread.h"], hdrs = [ - "evthread-internal.h", "compat/sys/queue.h", + "evthread-internal.h", ], copts = [ "-w", "-DHAVE_CONFIG_H", ], includes = [ - "include", "compat", + "include", ], + visibility = ["//visibility:public"], deps = [ ":event", ], - visibility = ["//visibility:public"], -)""" +) +""" native.new_http_archive( name = "libevent_git", @@ -363,12 +361,12 @@ cc_proto_library( name = "envoy_carrier_proto", srcs = ["lightstep/envoy_carrier.proto"], include = ".", + default_runtime = "//external:protobuf", + protoc = "//external:protoc", + visibility = ["//visibility:public"], deps = [ "//external:cc_wkt_protos", ], - protoc = "//external:protoc", - default_runtime = "//external:protobuf", - visibility = ["//visibility:public"], ) cc_library( @@ -380,10 +378,10 @@ cc_library( "src/c++11/util.cc", ], hdrs = [ + "src/c++11/lightstep/envoy.h", "src/c++11/lightstep/impl.h", "src/c++11/lightstep/options.h", "src/c++11/lightstep/propagation.h", - "src/c++11/lightstep/envoy.h", "src/c++11/lightstep/span.h", "src/c++11/lightstep/tracer.h", "src/c++11/lightstep/util.h", @@ -401,11 +399,12 @@ cc_library( ], visibility = ["//visibility:public"], deps = [ - "@lightstep_common_git//:collector_proto", ":envoy_carrier_proto", "//external:protobuf", + "@lightstep_common_git//:collector_proto", ], -)""" +) +""" COMMON_BUILD = """ load("@protobuf_git//:protobuf.bzl", "cc_proto_library") @@ -421,13 +420,14 @@ cc_proto_library( name = "collector_proto", srcs = ["lightstep/collector.proto"], include = ".", + default_runtime = "//external:protobuf", + protoc = "//external:protoc", + visibility = ["//visibility:public"], deps = [ "//external:cc_wkt_protos", ], - protoc = "//external:protoc", - default_runtime = "//external:protobuf", - visibility = ["//visibility:public"], -)""" +) +""" native.new_git_repository( name = "lightstep_common_git", @@ -514,13 +514,11 @@ genrule( outs = [ "config.h", ], + cmd = "$(location configure) --enable-lib-only --enable-shared=no" + + " && cp config.h $@", tools = [ "configure", ], - cmd = ' '.join([ - "$(location configure) --enable-lib-only --enable-shared=no", - "&& cp config.h $@", - ]), ) cc_library( From 975131ea9f022329a6be32afab70e7f9f9056610 Mon Sep 17 00:00:00 2001 From: Lizan Zhou Date: Fri, 3 Feb 2017 14:38:47 -0800 Subject: [PATCH 4/5] No bind --- BUILD | 34 +++++----- repositories.bzl | 166 +++++++++-------------------------------------- 2 files changed, 49 insertions(+), 151 deletions(-) diff --git a/BUILD b/BUILD index 45c0bb7d1290..165fc09b907a 100644 --- a/BUILD +++ b/BUILD @@ -1,4 +1,4 @@ -load("@protobuf_git//:protobuf.bzl", "cc_proto_library") +load("@protobuf//:protobuf.bzl", "cc_proto_library") exports_files(["source/precompiled/precompiled.h"]) @@ -21,8 +21,8 @@ cc_proto_library( "source/common/generated/ratelimit.proto", ], include = "source", - default_runtime = "//external:protobuf", - protoc = "//external:protoc", + default_runtime = "@protobuf//:protobuf", + protoc = "@protobuf//:protoc", ) genrule( @@ -42,8 +42,8 @@ cc_proto_library( "test/generated/helloworld.proto", ], include = "test", - default_runtime = "//external:protobuf", - protoc = "//external:protoc", + default_runtime = "@protobuf//:protobuf", + protoc = "@protobuf//:protoc", ) genrule( @@ -88,16 +88,16 @@ cc_library( linkstatic = 1, deps = [ ":envoy-ratelimit-pb", - "//external:event", - "//external:event_pthreads", - "//external:http_parser", - "//external:libssl", - "//external:lightstep", - "//external:nghttp2", - "//external:protobuf", - "//external:rapidjson", - "//external:spdlog", - "//external:tclap", + "@libevent//:event", + "@libevent//:event_pthreads", + "@http_parser//:http_parser", + "@boringssl//:ssl", + "@lightstep//:lightstep_core", + "@nghttp2//:nghttp2", + "@protobuf//:protobuf", + "@rapidjson//:rapidjson", + "@spdlog//:spdlog", + "@tclap//:tclap", ], alwayslink = 1, ) @@ -128,7 +128,7 @@ cc_library( deps = [ ":envoy-common", ":envoy-test-pb", - "//external:googletest", + "@googletest//:googletest", ], alwayslink = 1, ) @@ -150,6 +150,6 @@ cc_test( deps = [ ":envoy-test-lib", ":envoy-test-pb", - "//external:googletest", + "@googletest//:googletest", ], ) diff --git a/repositories.bzl b/repositories.bzl index 7d9dc4b09f90..23f1e9174c90 100644 --- a/repositories.bzl +++ b/repositories.bzl @@ -1,56 +1,18 @@ -def boringssl_repositories(bind=True): +def boringssl_repositories(): native.git_repository( name = "boringssl", commit = "bfd36df3da38dbf8828e712f42fbab2a0034bc40", # 2017-02-02 remote = "https://boringssl.googlesource.com/boringssl", ) - if bind: - native.bind( - name = "boringssl_crypto", - actual = "@boringssl//:crypto", - ) - - native.bind( - name = "libssl", - actual = "@boringssl//:ssl", - ) - - -def protobuf_repositories(bind=True): +def protobuf_repositories(): native.git_repository( - name = "protobuf_git", + name = "protobuf", commit = "a428e42072765993ff674fda72863c9f1aa2d268", # v3.1.0 remote = "https://github.com/google/protobuf.git", ) - if bind: - native.bind( - name = "protoc", - actual = "@protobuf_git//:protoc", - ) - - native.bind( - name = "protobuf", - actual = "@protobuf_git//:protobuf", - ) - - native.bind( - name = "cc_wkt_protos", - actual = "@protobuf_git//:cc_wkt_protos", - ) - - native.bind( - name = "cc_wkt_protos_genproto", - actual = "@protobuf_git//:cc_wkt_protos_genproto", - ) - - native.bind( - name = "protobuf_compiler", - actual = "@protobuf_git//:protoc_lib", - ) - -def googletest_repositories(bind=True): +def googletest_repositories(): BUILD = """ # Copyright 2016 Google Inc. All Rights Reserved. # @@ -110,29 +72,13 @@ cc_library( ) """ native.new_git_repository( - name = "googletest_git", + name = "googletest", build_file_content = BUILD, commit = "d225acc90bc3a8c420a9bcd1f033033c1ccd7fe0", remote = "https://github.com/google/googletest.git", ) - if bind: - native.bind( - name = "googletest", - actual = "@googletest_git//:googletest", - ) - - native.bind( - name = "googletest_main", - actual = "@googletest_git//:googletest_main", - ) - - native.bind( - name = "googletest_prod", - actual = "@googletest_git//:googletest_prod", - ) - -def libevent_repositories(bind=True): +def libevent_repositories(): BUILD = """ genrule( name = "config", @@ -248,25 +194,13 @@ cc_library( """ native.new_http_archive( - name = "libevent_git", + name = "libevent", url = "https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz", strip_prefix = "libevent-2.0.22-stable", build_file_content = BUILD, ) - if bind: - native.bind( - name = "event", - actual = "@libevent_git//:event", - ) - - native.bind( - name = "event_pthreads", - actual = "@libevent_git//:event_pthreads", - ) - - -def spdlog_repositories(bind=True): +def spdlog_repositories(): BUILD = """ package(default_visibility=["//visibility:public"]) @@ -282,19 +216,13 @@ cc_library( )""" native.new_git_repository( - name = "spdlog_git", + name = "spdlog", remote = "https://github.com/gabime/spdlog.git", commit = "1f1f6a5f3b424203a429e9cb78e6548037adefa8", build_file_content = BUILD, ) - if bind: - native.bind( - name = "spdlog", - actual = "@spdlog_git//:spdlog", - ) - -def tclap_repositories(bind=True): +def tclap_repositories(): BUILD = """ cc_library( name = "tclap", @@ -335,20 +263,15 @@ cc_library( )""" native.new_http_archive( - name = "tclap_tar", + name = "tclap", url = "https://storage.googleapis.com/istio-build-deps/tclap-1.2.1.tar.gz", strip_prefix = "tclap-1.2.1", build_file_content = BUILD, ) - if bind: - native.bind( - name = "tclap", - actual = "@tclap_tar//:tclap", - ) -def lightstep_repositories(bind=True): +def lightstep_repositories(): BUILD = """ -load("@protobuf_git//:protobuf.bzl", "cc_proto_library") +load("@protobuf//:protobuf.bzl", "cc_proto_library") genrule( name = "envoy_carrier_pb", @@ -361,11 +284,11 @@ cc_proto_library( name = "envoy_carrier_proto", srcs = ["lightstep/envoy_carrier.proto"], include = ".", - default_runtime = "//external:protobuf", - protoc = "//external:protoc", + default_runtime = "@protobuf//:protobuf", + protoc = "@protobuf//:protoc", visibility = ["//visibility:public"], deps = [ - "//external:cc_wkt_protos", + "@protobuf//:cc_wkt_protos", ], ) @@ -391,8 +314,8 @@ cc_library( ], copts = [ "-DPACKAGE_VERSION='\\"0.19\\"'", - "-Iexternal/lightstep_git/src/c++11/lightstep", - "-Iexternal/lightstep_git/src/c++11/mapbox_variant", + "-Iexternal/lightstep/src/c++11/lightstep", + "-Iexternal/lightstep/src/c++11/mapbox_variant", ], includes = [ "src/c++11", @@ -400,14 +323,14 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":envoy_carrier_proto", - "//external:protobuf", - "@lightstep_common_git//:collector_proto", + "@lightstep_common//:collector_proto", + "@protobuf//:protobuf", ], ) """ COMMON_BUILD = """ -load("@protobuf_git//:protobuf.bzl", "cc_proto_library") +load("@protobuf//:protobuf.bzl", "cc_proto_library") genrule( name = "collector_pb", @@ -420,36 +343,30 @@ cc_proto_library( name = "collector_proto", srcs = ["lightstep/collector.proto"], include = ".", - default_runtime = "//external:protobuf", - protoc = "//external:protoc", + default_runtime = "@protobuf//:protobuf", + protoc = "@protobuf//:protoc", visibility = ["//visibility:public"], deps = [ - "//external:cc_wkt_protos", + "@protobuf//:cc_wkt_protos", ], ) """ native.new_git_repository( - name = "lightstep_common_git", + name = "lightstep_common", remote = "https://github.com/lightstep/lightstep-tracer-common.git", commit = "8d932f7f76cd286691e6179621d0012b0ff1e6aa", build_file_content = COMMON_BUILD, ) native.new_git_repository( - name = "lightstep_git", + name = "lightstep", remote = "https://github.com/lightstep/lightstep-tracer-cpp.git", commit = "5a71d623cac17a059041b04fabca4ed86ffff7cc", build_file_content = BUILD, ) - if bind: - native.bind( - name = "lightstep", - actual = "@lightstep_git//:lightstep_core", - ) - -def http_parser_repositories(bind=True): +def http_parser_repositories(): BUILD = """ cc_library( name = "http_parser", @@ -463,19 +380,13 @@ cc_library( )""" native.new_git_repository( - name = "http_parser_git", + name = "http_parser", remote = "https://github.com/nodejs/http-parser.git", commit = "9b0d5b33ebdaacff1dadd06bad4e198b11ff880e", build_file_content = BUILD, ) - if bind: - native.bind( - name = "http_parser", - actual = "@http_parser_git//:http_parser", - ) - -def rapidjson_repositories(bind=True): +def rapidjson_repositories(): BUILD = """ cc_library( name = "rapidjson", @@ -492,19 +403,13 @@ cc_library( """ native.new_git_repository( - name = "rapidjson_git", + name = "rapidjson", remote = "https://github.com/miloyip/rapidjson.git", commit = "f54b0e47a08782a6131cc3d60f94d038fa6e0a51", # v1.1.0 build_file_content = BUILD, ) - if bind: - native.bind( - name = "rapidjson", - actual = "@rapidjson_git//:rapidjson", - ) - -def nghttp2_repositories(bind=True): +def nghttp2_repositories(): BUILD = """ genrule( name = "config", @@ -533,7 +438,6 @@ cc_library( copts = [ "-DHAVE_CONFIG_H", "-DBUILDING_NGHTTP2", - "-Iexternal/nghttp2_tar", ], includes = [ ".", @@ -544,14 +448,8 @@ cc_library( """ native.new_http_archive( - name = "nghttp2_tar", + name = "nghttp2", url = "https://github.com/nghttp2/nghttp2/releases/download/v1.14.1/nghttp2-1.14.1.tar.gz", strip_prefix = "nghttp2-1.14.1", build_file_content = BUILD, ) - - if bind: - native.bind( - name = "nghttp2", - actual = "@nghttp2_tar//:nghttp2", - ) From f3f7cbc5bd38322ad69b13a4c36ef1379ab01e54 Mon Sep 17 00:00:00 2001 From: Lizan Zhou Date: Mon, 6 Feb 2017 17:02:53 -0800 Subject: [PATCH 5/5] Address review comments --- WORKSPACE | 34 ++-------------------------------- repositories.bzl | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index d0bc5195b423..f0c1dd421419 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,33 +1,3 @@ -load( - "//:repositories.bzl", - "boringssl_repositories", - "protobuf_repositories", - "googletest_repositories", - "libevent_repositories", - "spdlog_repositories", - "tclap_repositories", - "lightstep_repositories", - "http_parser_repositories", - "rapidjson_repositories", - "nghttp2_repositories", -) +load("//:repositories.bzl", "envoy_dependencies") -boringssl_repositories() - -protobuf_repositories() - -googletest_repositories() - -libevent_repositories() - -spdlog_repositories() - -tclap_repositories() - -lightstep_repositories() - -http_parser_repositories() - -rapidjson_repositories() - -nghttp2_repositories() +envoy_dependencies() diff --git a/repositories.bzl b/repositories.bzl index 23f1e9174c90..eac2ffa9d157 100644 --- a/repositories.bzl +++ b/repositories.bzl @@ -213,7 +213,8 @@ cc_library( includes = [ "include", ], -)""" +) +""" native.new_git_repository( name = "spdlog", @@ -260,7 +261,8 @@ cc_library( "include", ], visibility = ["//visibility:public"], -)""" +) +""" native.new_http_archive( name = "tclap", @@ -377,7 +379,8 @@ cc_library( "http_parser.h", ], visibility = ["//visibility:public"], -)""" +) +""" native.new_git_repository( name = "http_parser", @@ -453,3 +456,16 @@ cc_library( strip_prefix = "nghttp2-1.14.1", build_file_content = BUILD, ) + + +def envoy_dependencies(): + boringssl_repositories() + protobuf_repositories() + googletest_repositories() + libevent_repositories() + spdlog_repositories() + tclap_repositories() + lightstep_repositories() + http_parser_repositories() + rapidjson_repositories() + nghttp2_repositories()