Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ load("//bazel:cc_configure.bzl", "cc_configure")

envoy_dependencies()

load("@rules_foreign_cc//:workspace_definitions.bzl", "rules_foreign_cc_dependencies")

rules_foreign_cc_dependencies()

cc_configure()

load("@envoy_api//bazel:repositories.bzl", "api_dependencies")
Expand Down
17 changes: 15 additions & 2 deletions bazel/EXTERNAL_DEPS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ build process.
`external_deps` attribute.
3. `bazel test //test/...`

# Adding external dependencies to Envoy (external cmake)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: s/cmake/CMake/


This is the preferred style of adding dependencies that use cmake for their build system.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: s/cmake/CMake/


1. Define a the source Bazel repository in [`bazel/repositories.bzl`](repositories.bzl), in the
`envoy_dependencies()` function.
2. Add a `cmake_external` rule to [`bazel/foreign_cc/BUILD`](bazel/foreign_cc/BUILD). This will
reference the source repository in step 1.
3. Reference your new external dependency in some `envoy_cc_library` via Y in the
Comment thread
htuch marked this conversation as resolved.
Outdated
`external_deps` attribute.
4. `bazel test //test/...`

# Adding external dependencies to Envoy (genrule repository)

This is the newer style of adding dependencies with no upstream Bazel configs.
Expand Down Expand Up @@ -44,8 +56,9 @@ to binaries, libraries, headers, etc.

# Adding external dependencies to Envoy (build recipe)

This is the older style of adding dependencies. It uses shell scripts to build
and install dependencies into a shared directory prefix.
This is the older style of adding dependencies. It uses shell scripts to build and install
dependencies into a shared directory prefix. This should no longer be used unless there are
extenuating circumstances.

1. Add a build recipe X in [`ci/build_container/build_recipes`](../ci/build_container/build_recipes)
for developer-local and CI external dependency build flows.
Expand Down
82 changes: 82 additions & 0 deletions bazel/foreign_cc/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
licenses(["notice"]) # Apache 2

load("//bazel:envoy_build_system.bzl", "envoy_package")
load("@rules_foreign_cc//tools/build_defs:cmake.bzl", "cmake_external")
load("@foreign_cc_platform_utils//:tools.bzl", "NINJA_COMMAND", "NINJA_DEP")

envoy_package()

cmake_external(
name = "ares",
cache_entries = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add "CMAKE_BUILD_TYPE": "RelWithDebInfo" (possibly "Debug" for Windows builds?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, but I'm going to skip the Windows parts and let @sesmith177 take this.

"CARES_SHARED": "no",
"CARES_STATIC": "on",
},
cmake_options = ["-GNinja"],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to set generate_crosstool_file = true on Windows

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

lib_source = "@com_github_c_ares_c_ares//:all",
make_commands = [
NINJA_COMMAND,
NINJA_COMMAND + " install",
],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack. Let's merge as-is and you can do a small diff PR for this. I can't verify these steps, so will let you folks take this on.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a problem -- we can submit a followup PR that cleans up the Windows bits

static_libraries = ["libcares.a"],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output static library files are going to be different on Windows and Linux

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

tools_deps = NINJA_DEP,
)

cmake_external(
name = "event",
cache_entries = {
"EVENT__DISABLE_OPENSSL": "on",
"EVENT__DISABLE_REGRESS": "on",
},
cmake_options = ["-GNinja"],
lib_source = "@com_github_libevent_libevent//:all",
make_commands = [
NINJA_COMMAND,
NINJA_COMMAND + " install",
],
static_libraries = ["libevent.a"],
tools_deps = NINJA_DEP,
)

cmake_external(
name = "nghttp2",
cache_entries = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add "CMAKE_BUILD_TYPE": "RelWithDebInfo" (possibly "Debug" for Windows builds?)

"ENABLE_STATIC_LIB": "on",
"ENABLE_LIB_ONLY": "on",
},
cmake_options = ["-GNinja"],
lib_source = "@com_github_nghttp2_nghttp2//:all",
make_commands = [
NINJA_COMMAND,
NINJA_COMMAND + " install",
],
static_libraries = ["libnghttp2.a"],
tools_deps = NINJA_DEP,
)

cmake_external(
name = "yaml",
cache_entries = {
"YAML_CPP_BUILD_TESTS": "off",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add "CMAKE_BUILD_TYPE": "RelWithDebInfo" (possibly "Debug" for Windows builds?)

},
cmake_options = ["-GNinja"],
lib_source = "@com_github_jbeder_yaml_cpp//:all",
make_commands = [
NINJA_COMMAND,
NINJA_COMMAND + " install",
],
static_libraries = ["libyaml-cpp.a"],
tools_deps = NINJA_DEP,
)

cmake_external(
name = "zlib",
cmake_options = ["-GNinja"],
lib_source = "@com_github_madler_zlib//:all",
make_commands = [
NINJA_COMMAND,
NINJA_COMMAND + " install",
],
static_libraries = ["libz.a"],
tools_deps = NINJA_DEP,
)
12 changes: 12 additions & 0 deletions bazel/foreign_cc/nghttp2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 17e422b2..e58070f5 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -52,6 +52,7 @@
COMPILE_FLAGS "${WARNCFLAGS}"
VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION}
ARCHIVE_OUTPUT_NAME nghttp2
+ ARCHIVE_OUTPUT_DIRECTORY static

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This diff isn't going to work -- it builds the static nghttp2.lib in a different directory from the dynamic nghttp2.lib, but when ninja install is run, it installs both on top of each other.

To get this to work we updated our patch: https://github.com/greenhouse-org/envoy/blob/66776969519e993ea022bb385947897208704abe/bazel/foreign_cc/nghttp2.patch and associated PR: nghttp2/nghttp2#1198

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack. I'm going to go ahead with the PR as-is and we can update this when the nghttp2 patch merges.

)
target_compile_definitions(nghttp2_static PUBLIC "-DNGHTTP2_STATICLIB")
if(ENABLE_STATIC_LIB)
90 changes: 90 additions & 0 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ PPC_SKIP_TARGETS = {"luajit": "envoy.filters.http.lua"}
# go version for rules_go
GO_VERSION = "1.10.4"

# Make all contents of an external repository accessible under a filegroup. Used for external HTTP
# archives, e.g. cares.
BUILD_ALL_CONTENT = """filegroup(name = "all", srcs = glob(["**"]), visibility = ["//visibility:public"])"""

def _repository_impl(name, **kwargs):
# `existing_rule_keys` contains the names of repositories that have already
# been defined in the Bazel workspace. By skipping repos with existing keys,
Expand Down Expand Up @@ -265,13 +269,17 @@ def envoy_dependencies(path = "@envoy_deps//", skip_targets = []):
if "envoy_build_config" not in native.existing_rules().keys():
_default_envoy_build_config(name = "envoy_build_config")

# Setup rules_foreign_cc
_foreign_cc_dependencies()

# The long repo names (`com_github_fmtlib_fmt` instead of `fmtlib`) are
# semi-standard in the Bazel community, intended to avoid both duplicate
# dependencies and name conflicts.
_boringssl()
_com_google_absl()
_com_github_bombela_backward()
_com_github_circonus_labs_libcircllhist()
_com_github_c_ares_c_ares()
_com_github_cyan4973_xxhash()
_com_github_eile_tclap()
_com_github_fmtlib_fmt()
Expand All @@ -282,8 +290,13 @@ def envoy_dependencies(path = "@envoy_deps//", skip_targets = []):
_com_lightstep_tracer_cpp()
_com_github_datadog_dd_opentracing_cpp()
_com_github_grpc_grpc()
_com_github_google_benchmark()
_com_github_google_jwt_verify()
_com_github_jbeder_yaml_cpp()
_com_github_libevent_libevent()
_com_github_madler_zlib()
_com_github_nanopb_nanopb()
_com_github_nghttp2_nghttp2()
_com_github_nodejs_http_parser()
_com_github_tencent_rapidjson()
_com_google_googletest()
Expand Down Expand Up @@ -324,6 +337,18 @@ def _com_github_circonus_labs_libcircllhist():
actual = "@com_github_circonus_labs_libcircllhist//:libcircllhist",
)

def _com_github_c_ares_c_ares():
location = REPOSITORY_LOCATIONS["com_github_c_ares_c_ares"]
http_archive(
name = "com_github_c_ares_c_ares",
build_file_content = BUILD_ALL_CONTENT,
**location
)
native.bind(
name = "ares",
actual = "//bazel/foreign_cc:ares",
)

def _com_github_cyan4973_xxhash():
_repository_impl(
name = "com_github_cyan4973_xxhash",
Expand Down Expand Up @@ -374,6 +399,17 @@ def _com_github_gcovr_gcovr():
actual = "@com_github_gcovr_gcovr//:gcovr",
)

def _com_github_google_benchmark():
location = REPOSITORY_LOCATIONS["com_github_google_benchmark"]
http_archive(
name = "com_github_google_benchmark",
**location
)
native.bind(
name = "benchmark",
actual = "@com_github_google_benchmark//:benchmark",
)

def _com_github_google_libprotobuf_mutator():
_repository_impl(
name = "com_github_google_libprotobuf_mutator",
Expand All @@ -384,6 +420,57 @@ def _com_github_google_libprotobuf_mutator():
actual = "@com_github_google_libprotobuf_mutator//:libprotobuf_mutator",
)

def _com_github_jbeder_yaml_cpp():
location = REPOSITORY_LOCATIONS["com_github_jbeder_yaml_cpp"]
http_archive(
name = "com_github_jbeder_yaml_cpp",
build_file_content = BUILD_ALL_CONTENT,
**location
)
native.bind(
name = "yaml_cpp",
actual = "//bazel/foreign_cc:yaml",
)

def _com_github_libevent_libevent():
location = REPOSITORY_LOCATIONS["com_github_libevent_libevent"]
http_archive(
name = "com_github_libevent_libevent",
build_file_content = BUILD_ALL_CONTENT,
**location
)
native.bind(
name = "event",
actual = "//bazel/foreign_cc:event",
)

def _com_github_madler_zlib():
location = REPOSITORY_LOCATIONS["com_github_madler_zlib"]
http_archive(
name = "com_github_madler_zlib",
build_file_content = BUILD_ALL_CONTENT,
**location
)
native.bind(
name = "zlib",
actual = "//bazel/foreign_cc:zlib",
)

def _com_github_nghttp2_nghttp2():
location = REPOSITORY_LOCATIONS["com_github_nghttp2_nghttp2"]
http_archive(
name = "com_github_nghttp2_nghttp2",
build_file_content = BUILD_ALL_CONTENT,
patch_args = ["-p1"],
patch_cmds = ["find . -name '*.sh' -exec sed -i.orig '1s|#!/usr/bin/env sh\$|/bin/sh\$|' {} +"],
patches = ["//bazel/foreign_cc:nghttp2.patch"],
**location
)
native.bind(
name = "nghttp2",
actual = "//bazel/foreign_cc:nghttp2",
)

def _io_opentracing_cpp():
_repository_impl("io_opentracing_cpp")
native.bind(
Expand Down Expand Up @@ -575,6 +662,9 @@ def _com_github_google_jwt_verify():
actual = "@com_github_google_jwt_verify//:jwt_verify_lib",
)

def _foreign_cc_dependencies():
_repository_impl("rules_foreign_cc")

def _apply_dep_blacklist(ctxt, recipes):
newlist = []
skip_list = dict()
Expand Down
36 changes: 36 additions & 0 deletions bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ REPOSITORY_LOCATIONS = dict(
strip_prefix = "backward-cpp-1.4",
urls = ["https://github.com/bombela/backward-cpp/archive/v1.4.tar.gz"],
),
com_github_c_ares_c_ares = dict(
sha256 = "7deb7872cbd876c29036d5f37e30c4cbc3cc068d59d8b749ef85bb0736649f04",
strip_prefix = "c-ares-cares-1_15_0",
urls = ["https://github.com/c-ares/c-ares/archive/cares-1_15_0.tar.gz"],
),
com_github_circonus_labs_libcircllhist = dict(
sha256 = "9949e2864b8ad00ee5c3e9c1c3c01e51b6b68bb442a919652fc66b9776477987",
strip_prefix = "libcircllhist-fd8a14463739d247b414825cc56ca3946792a3b9",
Expand Down Expand Up @@ -74,6 +79,11 @@ REPOSITORY_LOCATIONS = dict(
strip_prefix = "nanopb-f8ac463766281625ad710900479130c7fcb4d63b",
urls = ["https://github.com/nanopb/nanopb/archive/f8ac463766281625ad710900479130c7fcb4d63b.tar.gz"],
),
com_github_nghttp2_nghttp2 = dict(
sha256 = "8889399ddd38aa0405f6e84f1c050a292286089441686b8a9c5e937de4f5b61d",
strip_prefix = "nghttp2-1.34.0",
urls = ["https://github.com/nghttp2/nghttp2/releases/download/v1.34.0/nghttp2-1.34.0.tar.gz"],
),
io_opentracing_cpp = dict(
sha256 = "4455ca507936bc4b658ded10a90d8ebbbd61c58f06207be565a4ffdc885687b5",
strip_prefix = "opentracing-cpp-1.5.0",
Expand All @@ -95,6 +105,27 @@ REPOSITORY_LOCATIONS = dict(
strip_prefix = "dd-opentracing-cpp-0.3.6",
urls = ["https://github.com/DataDog/dd-opentracing-cpp/archive/v0.3.6.tar.gz"],
),
com_github_google_benchmark = dict(
# TODO (moderation) change back to tarball method on next benchmark release
sha256 = "0de43b6eaddd356f1d6cd164f73f37faf2f6c96fd684e1f7ea543ce49c1d144e",
strip_prefix = "benchmark-505be96ab23056580a3a2315abba048f4428b04e",
urls = ["https://github.com/google/benchmark/archive/505be96ab23056580a3a2315abba048f4428b04e.tar.gz"],
),
com_github_libevent_libevent = dict(
sha256 = "316ddb401745ac5d222d7c529ef1eada12f58f6376a66c1118eee803cb70f83d",
strip_prefix = "libevent-release-2.1.8-stable",
urls = ["https://github.com/libevent/libevent/archive/release-2.1.8-stable.tar.gz"],
),
com_github_madler_zlib = dict(
sha256 = "629380c90a77b964d896ed37163f5c3a34f6e6d897311f1df2a7016355c45eff",
strip_prefix = "zlib-1.2.11",
urls = ["https://github.com/madler/zlib/archive/v1.2.11.tar.gz"],
),
com_github_jbeder_yaml_cpp = dict(
sha256 = "53dcffd55f3433b379fcc694f45c54898711c0e29159a7bd02e82a3e0253bac3",
strip_prefix = "yaml-cpp-0f9a586ca1dc29c2ecb8dd715a315b93e3f40f79",
urls = ["https://github.com/jbeder/yaml-cpp/archive/0f9a586ca1dc29c2ecb8dd715a315b93e3f40f79.tar.gz"],
),
com_github_msgpack_msgpack_c = dict(
sha256 = "bda49f996a73d2c6080ff0523e7b535917cd28c8a79c3a5da54fc29332d61d1e",
strip_prefix = "msgpack-c-cpp-3.1.1",
Expand Down Expand Up @@ -179,6 +210,11 @@ REPOSITORY_LOCATIONS = dict(
sha256 = "ee5fe78fe417c685ecb77a0a725dc9f6040ae5beb44a0ba4ddb55453aad23a8a",
urls = ["https://github.com/bazelbuild/rules_go/releases/download/0.16.0/rules_go-0.16.0.tar.gz"],
),
rules_foreign_cc = dict(
sha256 = "e7f1a286479ed6499eb2e68a063f9d0aadcca0de7d6d710a10b8a3c3042f9c5a",
strip_prefix = "rules_foreign_cc-8ec19f39590871a4176be7edf76acecad9acd7be",
urls = ["https://github.com/bazelbuild/rules_foreign_cc/archive/8ec19f39590871a4176be7edf76acecad9acd7be.tar.gz"],
),
six_archive = dict(
sha256 = "105f8d68616f8248e24bf0e9372ef04d3cc10104f1980f54d57b2ce73a5ad56a",
urls = ["https://pypi.python.org/packages/source/s/six/six-1.10.0.tar.gz#md5=34eed507548117b2ab523ab14b2f8b55"],
Expand Down
6 changes: 0 additions & 6 deletions bazel/target_recipes.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
# target in //ci/prebuilt/BUILD to the underlying build recipe in
# ci/build_container/build_recipes.
TARGET_RECIPES = {
"ares": "cares",
"benchmark": "benchmark",
"event": "libevent",
"tcmalloc_and_profiler": "gperftools",
"luajit": "luajit",
"nghttp2": "nghttp2",
"yaml_cpp": "yaml-cpp",
"zlib": "zlib",
}
5 changes: 5 additions & 0 deletions ci/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ envoy_dependencies(
path = "@envoy//ci/prebuilt",
)

# TODO(htuch): Roll this into envoy_dependencies()
load("@rules_foreign_cc//:workspace_definitions.bzl", "rules_foreign_cc_dependencies")

rules_foreign_cc_dependencies()

cc_configure()

load("@envoy_api//bazel:repositories.bzl", "api_dependencies")
Expand Down
3 changes: 3 additions & 0 deletions ci/WORKSPACE.filter.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ load("//bazel:cc_configure.bzl", "cc_configure")
envoy_dependencies(
path = "@envoy//ci/prebuilt",
)
# TODO(htuch): Roll this into envoy_dependencies()
load("@rules_foreign_cc//:workspace_definitions.bzl", "rules_foreign_cc_dependencies")
rules_foreign_cc_dependencies()

cc_configure()

Expand Down
Loading