Skip to content

Commit

Permalink
bazel: additional build targets and tests (envoyproxy#415). (envoypro…
Browse files Browse the repository at this point in the history
…xy#617)

This takes us to ~65% of targets. I've switched to machine generating the BUILD files based on
header analysis, the Envoy file naming conventions and a hardcoded list of exceptions. The remaining
targets should be much faster.
  • Loading branch information
htuch authored and mattklein123 committed Mar 24, 2017
1 parent 33ece57 commit e64489f
Show file tree
Hide file tree
Showing 103 changed files with 1,734 additions and 154 deletions.
40 changes: 40 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ bind(
actual = "@cares_git//:ares",
)

bind(
name = "cc_wkt_protos_genproto",
actual = "@protobuf_git//:cc_wkt_protos_genproto",
)

bind(
name = "cc_wkt_protos",
actual = "@protobuf_git//:cc_wkt_protos",
)

bind(
name = "event",
actual = "@libevent_git//:event",
Expand All @@ -24,6 +34,36 @@ bind(
actual = "@googletest_git//:googletest",
)

bind(
name = "http_parser",
actual = "@http_parser_git//:http_parser",
)

bind(
name = "lightstep",
actual = "@lightstep_git//:lightstep_core",
)

bind(
name = "nghttp2",
actual = "@nghttp2_tar//:nghttp2",
)

bind(
name = "protobuf",
actual = "@protobuf_git//:protobuf",
)

bind(
name = "protoc",
actual = "@protobuf_git//:protoc",
)

bind(
name = "rapidjson",
actual = "@rapidjson_git//:rapidjson",
)

bind(
name = "spdlog",
actual = "@spdlog_git//:spdlog",
Expand Down
26 changes: 26 additions & 0 deletions bazel/envoy_build_system.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def envoy_cc_library(name,
copts = ENVOY_COPTS + copts,
visibility = visibility,
deps = deps + [envoy_external_dep_path(dep) for dep in external_deps] + [
"//include/envoy/common:base_includes",
"//source/precompiled:precompiled_includes",
],
alwayslink = alwayslink,
Expand All @@ -65,3 +66,28 @@ def envoy_cc_test(name,
"//test/precompiled:precompiled_includes",
],
)

# Envoy C++ test related libraries (that want gtest, gmock) should be specified with this function.
def envoy_cc_test_library(name,
srcs = [],
hdrs = [],
deps = []):
native.cc_library(
name = name,
srcs = srcs,
hdrs = hdrs,
copts = ENVOY_COPTS + ["-includetest/precompiled/precompiled_test.h"],
testonly = 1,
alwayslink = 1,
deps = deps + [
"//source/precompiled:precompiled_includes",
"//test/precompiled:precompiled_includes",
],
)

# Envoy C++ mock targets should be specified with this function.
def envoy_cc_mock(name,
srcs = [],
hdrs = [],
deps = []):
envoy_cc_test_library(name, srcs, hdrs, deps)
174 changes: 173 additions & 1 deletion bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,27 @@ cc_library(
remote = "https://github.com/google/googletest.git",
)

def http_parser_repositories():
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,
)

def libevent_repositories():
BUILD = """
genrule(
Expand Down Expand Up @@ -270,6 +291,153 @@ cc_library(
build_file_content = BUILD,
)

def lightstep_repositories():
BUILD = """
load("@protobuf_git//:protobuf.bzl", "cc_proto_library")
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/carrier.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.36\\"'",
"-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",
"@lightstep_common_git//:lightstep_carrier_proto",
"//external:protobuf",
],
)"""

COMMON_BUILD = """
load("@protobuf_git//:protobuf.bzl", "cc_proto_library")
cc_proto_library(
name = "collector_proto",
srcs = ["collector.proto"],
include = ".",
deps = [
"//external:cc_wkt_protos",
],
protoc = "//external:protoc",
default_runtime = "//external:protobuf",
visibility = ["//visibility:public"],
)
cc_proto_library(
name = "lightstep_carrier_proto",
srcs = ["lightstep_carrier.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 = "cbbecd671c1ae1f20ae873c5da688c8c14d04ec3",
build_file_content = COMMON_BUILD,
)

native.new_git_repository(
name = "lightstep_git",
remote = "https://github.com/lightstep/lightstep-tracer-cpp.git",
commit = "f1dc8f3dfd529350e053fd21273e627f409ae428", # 0.36
build_file_content = BUILD,
)

def nghttp2_repositories():
BUILD = """
genrule(
name = "config",
srcs = glob(["**/*"]),
outs = ["config.h"],
cmd = "TMPDIR=$(@D) $(location configure) --enable-lib-only --enable-shared=no" +
" && cp config.h $@",
tools = ["configure"],
)
cc_library(
name = "nghttp2",
srcs = glob([
"lib/*.c",
"lib/*.h",
]) + ["config.h"],
hdrs = glob(["lib/includes/nghttp2/*.h"]),
copts = [
"-DHAVE_CONFIG_H",
"-DBUILDING_NGHTTP2",
],
includes = [
".",
"lib/includes",
],
visibility = ["//visibility:public"],
)
"""

native.new_http_archive(
name = "nghttp2_tar",
url = "https://github.com/nghttp2/nghttp2/releases/download/v1.20.0/nghttp2-1.20.0.tar.gz",
strip_prefix = "nghttp2-1.20.0",
build_file_content = BUILD,
)

def protobuf_repositories():
native.git_repository(
name = "protobuf_git",
commit = "a428e42072765993ff674fda72863c9f1aa2d268", # v3.1.0
remote = "https://github.com/google/protobuf.git",
)

def rapidjson_repositories():
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,
)

def spdlog_repositories():
BUILD = """
package(default_visibility = ["//visibility:public"])
Expand Down Expand Up @@ -330,7 +498,6 @@ cc_library(
visibility = ["//visibility:public"],
)
"""

native.new_http_archive(
name = "tclap_archive",
url = "https://storage.googleapis.com/istio-build-deps/tclap-1.2.1.tar.gz",
Expand All @@ -342,6 +509,11 @@ def envoy_dependencies():
ares_repositories()
boringssl_repositories()
googletest_repositories()
http_parser_repositories()
libevent_repositories()
lightstep_repositories()
nghttp2_repositories()
protobuf_repositories()
rapidjson_repositories()
spdlog_repositories()
tclap_repositories()
11 changes: 11 additions & 0 deletions include/envoy/access_log/BUILD.wip
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package(default_visibility = ["//visibility:public"])

load("//bazel:envoy_build_system.bzl", "envoy_cc_library")

envoy_cc_library(
name = "access_log_includes",
hdrs = ["access_log.h"],
deps = [
"//include/envoy/filesystem:filesystem_includes",
],
)
12 changes: 12 additions & 0 deletions include/envoy/api/BUILD.wip
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package(default_visibility = ["//visibility:public"])

load("//bazel:envoy_build_system.bzl", "envoy_cc_library")

envoy_cc_library(
name = "api_includes",
hdrs = ["api.h"],
deps = [
"//include/envoy/event:dispatcher_includes",
"//include/envoy/thread:thread_includes",
],
)
1 change: 0 additions & 1 deletion include/envoy/buffer/BUILD.wip
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ load("//bazel:envoy_build_system.bzl", "envoy_cc_library")
envoy_cc_library(
name = "buffer_includes",
hdrs = ["buffer.h"],
deps = ["//include/envoy/common:base_includes"],
)
5 changes: 2 additions & 3 deletions include/envoy/common/BUILD.wip
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@ package(default_visibility = ["//visibility:public"])

load("//bazel:envoy_build_system.bzl", "envoy_cc_library")

envoy_cc_library(
cc_library(
name = "base_includes",
hdrs = [
"exception.h",
"pure.h",
],
include_prefix = "envoy/common",
)

envoy_cc_library(
name = "time_includes",
hdrs = ["time.h"],
deps = [":base_includes"],
)

envoy_cc_library(
name = "optional_includes",
hdrs = ["optional.h"],
deps = [":base_includes"],
)
2 changes: 0 additions & 2 deletions include/envoy/event/BUILD.wip
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ envoy_cc_library(
envoy_cc_library(
name = "file_event_includes",
hdrs = ["file_event.h"],
deps = ["//include/envoy/common:base_includes"],
)

envoy_cc_library(
Expand All @@ -38,5 +37,4 @@ envoy_cc_library(
envoy_cc_library(
name = "timer_includes",
hdrs = ["timer.h"],
deps = ["//include/envoy/common:base_includes"],
)
1 change: 0 additions & 1 deletion include/envoy/filesystem/BUILD.wip
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ load("//bazel:envoy_build_system.bzl", "envoy_cc_library")
envoy_cc_library(
name = "filesystem_includes",
hdrs = ["filesystem.h"],
deps = ["//include/envoy/common:base_includes"],
)
Loading

0 comments on commit e64489f

Please sign in to comment.