-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Minimal Bazel infrastructure (#415). This patch introduces the minimal Bazel infrastructure required to build and execute utility_test, as a step towards conversion of the cmake build system to Bazel (#415). The main contributions are: * Machinery for declaring Envoy C++ library and test targets (envoy_cc_library, envoy_cc_test). * External dependency management that works both inside the Docker CI environment (using prebuilts) and with developer-local dependency fetch/build (based on #416). * Handling of the implicit dependencies that are today sourced via prebuilts. * Simple example of building and running a unit test with only its dependencies built. With the cmake system, we would need to build all of Envoy and all tests to run utility_test. E.g. blaze test //test/common/common:utility_test This is not intended to be used by anyone other than those working with the Bazel conversion at this point. The plan is to add "ci/do_ci.sh bazel.debug" as a Travis target to ensure we don't bit rot.
- Loading branch information
1 parent
dea277a
commit 72e88af
Showing
14 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
/build | ||
/docs/landing_source/.bundle | ||
/generated | ||
/bazel-* | ||
/ci/bazel-* | ||
/ci/prebuilt/thirdparty | ||
/ci/prebuilt/thirdparty_build | ||
cscope.* | ||
BROWSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
workspace(name = "envoy") | ||
|
||
load("//bazel:repositories.bzl", "envoy_dependencies") | ||
|
||
envoy_dependencies() | ||
|
||
bind( | ||
name = "googletest_main", | ||
actual = "@googletest//:googletest_main", | ||
) | ||
|
||
bind( | ||
name = "spdlog", | ||
actual = "@spdlog_git//:spdlog", | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
ENVOY_COPTS = [ | ||
"-fno-omit-frame-pointer", | ||
"-Wall", | ||
"-Wextra", | ||
"-Werror", | ||
"-Wnon-virtual-dtor", | ||
"-Woverloaded-virtual", | ||
"-Wold-style-cast", | ||
"-std=c++0x", | ||
"-includesource/precompiled/precompiled.h", | ||
"-iquoteinclude", | ||
"-iquotesource", | ||
] | ||
|
||
# References to Envoy external dependencies should be wrapped with this function. | ||
def envoy_external_dep_path(dep): | ||
return "//external:%s" % dep | ||
|
||
# Envoy C++ library targets should be specified with this function. | ||
def envoy_cc_library(name, | ||
srcs = [], | ||
hdrs = [], | ||
public_hdrs = [], | ||
copts = [], | ||
alwayslink = None, | ||
visibility = None, | ||
external_deps = [], | ||
deps = []): | ||
native.cc_library( | ||
name = name, | ||
srcs = srcs, | ||
hdrs = hdrs + public_hdrs, | ||
copts = ENVOY_COPTS + copts, | ||
visibility = visibility, | ||
deps = deps + [envoy_external_dep_path(dep) for dep in external_deps] + [ | ||
"//source/precompiled:precompiled_includes", | ||
], | ||
alwayslink = alwayslink, | ||
) | ||
|
||
# Envoy C++ test targets should be specified with this function. | ||
def envoy_cc_test(name, | ||
srcs = [], | ||
deps = []): | ||
native.cc_test( | ||
name = name, | ||
srcs = srcs, | ||
copts = ENVOY_COPTS + ["-includetest/precompiled/precompiled_test.h"], | ||
linkopts = ["-pthread"], | ||
deps = deps + [ | ||
"//source/precompiled:precompiled_includes", | ||
"//test/precompiled:precompiled_includes", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# The build rules below for external dependencies build rules are maintained on a best effort basis. | ||
# The rules are provided for developer convenience. For production builds, we recommend building the | ||
# libraries according to their canonical build systems and expressing the dependencies in a manner | ||
# similar to ci/WORKSPACE. | ||
|
||
def googletest_repositories(): | ||
BUILD = """ | ||
cc_library( | ||
name = "googletest", | ||
srcs = [ | ||
"googlemock/src/gmock-all.cc", | ||
"googletest/src/gtest-all.cc", | ||
], | ||
hdrs = glob([ | ||
"googlemock/include/**/*.h", | ||
"googlemock/src/*.cc", | ||
"googletest/include/**/*.h", | ||
"googletest/src/*.cc", | ||
"googletest/src/*.h", | ||
]), | ||
includes = [ | ||
"googlemock", | ||
"googlemock/include", | ||
"googletest", | ||
"googletest/include", | ||
], | ||
visibility = ["//visibility:public"], | ||
) | ||
cc_library( | ||
name = "googletest_main", | ||
srcs = ["googlemock/src/gmock_main.cc"], | ||
visibility = ["//visibility:public"], | ||
deps = [":googletest"], | ||
) | ||
""" | ||
native.new_git_repository( | ||
name = "googletest", | ||
build_file_content = BUILD, | ||
# v1.8.0 release | ||
commit = "ec44c6c1675c25b9827aacd08c02433cccde7780", | ||
remote = "https://github.com/google/googletest.git", | ||
) | ||
|
||
def spdlog_repositories(): | ||
BUILD = """ | ||
package(default_visibility = ["//visibility:public"]) | ||
cc_library( | ||
name = "spdlog", | ||
hdrs = glob([ | ||
"include/**/*.cc", | ||
"include/**/*.h", | ||
]), | ||
strip_include_prefix = "include", | ||
) | ||
""" | ||
|
||
native.new_git_repository( | ||
name = "spdlog_git", | ||
build_file_content = BUILD, | ||
# v0.11.0 release | ||
commit = "1f1f6a5f3b424203a429e9cb78e6548037adefa8", | ||
remote = "https://github.com/gabime/spdlog.git", | ||
) | ||
|
||
def envoy_dependencies(): | ||
googletest_repositories() | ||
spdlog_repositories() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
bind( | ||
name = "googletest_main", | ||
actual = "//ci/prebuilt:googletest_main", | ||
) | ||
|
||
bind( | ||
name = "spdlog", | ||
actual = "//ci/prebuilt:spdlog", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
cc_library( | ||
name = "googletest_main", | ||
srcs = [ | ||
"thirdparty_build/lib/libgmock.a", | ||
"thirdparty_build/lib/libgtest.a", | ||
"thirdparty_build/lib/libgtest_main.a", | ||
], | ||
hdrs = glob([ | ||
"thirdparty_build/include/gmock/**/*.h", | ||
"thirdparty_build/include/gtest/**/*.h", | ||
]), | ||
strip_include_prefix = "thirdparty_build/include", | ||
) | ||
|
||
cc_library( | ||
name = "spdlog", | ||
hdrs = glob([ | ||
"thirdparty/spdlog-0.11.0/include/**/*.cc", | ||
"thirdparty/spdlog-0.11.0/include/**/*.h", | ||
]), | ||
strip_include_prefix = "thirdparty/spdlog-0.11.0/include", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
load("//bazel:envoy_build_system.bzl", "envoy_cc_library") | ||
|
||
envoy_cc_library( | ||
name = "base_includes", | ||
hdrs = [ | ||
"exception.h", | ||
"pure.h", | ||
], | ||
) | ||
|
||
envoy_cc_library( | ||
name = "time_includes", | ||
hdrs = ["time.h"], | ||
deps = [":base_includes"], | ||
) | ||
|
||
envoy_cc_library( | ||
name = "optional_includes", | ||
hdrs = ["optional.h"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
load("//bazel:envoy_build_system.bzl", "envoy_cc_library") | ||
|
||
envoy_cc_library( | ||
name = "utility_lib", | ||
srcs = ["utility.cc"], | ||
hdrs = ["utility.h"], | ||
deps = ["//include/envoy/common:time_includes"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
load("//bazel:envoy_build_system.bzl", "envoy_external_dep_path") | ||
|
||
cc_library( | ||
name = "precompiled_includes", | ||
hdrs = ["precompiled.h"], | ||
deps = [envoy_external_dep_path("spdlog")], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
load("//bazel:envoy_build_system.bzl", "envoy_cc_test") | ||
|
||
envoy_cc_test( | ||
name = "utility_test", | ||
srcs = ["utility_test.cc"], | ||
deps = ["//source/common/common:utility_lib"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_external_dep_path") | ||
|
||
cc_library( | ||
name = "precompiled_includes", | ||
hdrs = ["precompiled_test.h"], | ||
deps = [ | ||
envoy_external_dep_path("googletest_main"), | ||
"//test/test_common:printers_includes", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
cc_library( | ||
name = "printers_includes", | ||
hdrs = ["printers.h"], | ||
) |