Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ load("//bazel:repositories.bzl", "envoy_dependencies")
load("//bazel:cc_configure.bzl", "cc_configure")

envoy_dependencies()
load("@rules_foreign_cc//:workspace_definitions.bzl", "rules_foreign_cc_dependencies")
Copy link
Member Author

Choose a reason for hiding this comment

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

I would like to figure out how to roll this into envoy_dependencies(), but it depends on some of the setup there. load can't be used inside a macro, only at file level or in WORKSPACE. Might be possibly with a multi-phase envoy_dependencies() setup.

Choose a reason for hiding this comment

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

afaik, unfortunately you can only call the initialization function directly in WORKSPACE file. Should be resolved when recursive workspace paring be implemented.

rules_foreign_cc_dependencies()

cc_configure()

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

# Adding external dependencies to Envoy (extern cmake)

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

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
Copy link
Member Author

Choose a reason for hiding this comment

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

Will improve the writeup before we merge here. This is now like the 5th way of handling external deps (obligatory https://xkcd.com/927/).

`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
39 changes: 39 additions & 0 deletions bazel/foreign_cc/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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 = {
"CARES_SHARED": "no",
"CARES_STATIC": "on",
},
cmake_options = ["-GNinja"],
lib_source = "@com_github_c_ares_c_ares//:all",
make_commands = [
NINJA_COMMAND,
NINJA_COMMAND + " install",
],
static_libraries = ["libcares.a"],
tools_deps = NINJA_DEP,
)

cmake_external(
Copy link
Member Author

Choose a reason for hiding this comment

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

@sesmith177 any chance you can try out this PR and let me know if it does the right thing on Windows?

Copy link
Member

Choose a reason for hiding this comment

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

we can take a look at it when we get a chance. One thing we noticed is that the names of the static libraries are different on Windows and Linux ( cares.lib and nghttp2.lib vs libcares.a and libnghttp2.a)

Choose a reason for hiding this comment

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

Hi, here's my modified cares build for Windows (I just completed it, will update the examples):

cmake_external(
name = "cares",
cache_entries = {
"CARES_SHARED": "no",
"CARES_STATIC": "on",
},
defines = ["CARES_STATICLIB"],
cmake_options = ["-GNinja"],
lib_source = "@cares//:all",
make_commands = [
"ninja",
"ninja install",
],
)

  1. Since on Wndows cares.lib is created, "static_libraries" can be omitted (cares.lib is the calculated default)
  2. defines = ["CARES_STATICLIB"], is very important, for some reason CMake script does not set this up because of corresponding CMake variable
  3. I used the preinstalled ninja, seems one should not build it on Windows

Hope it helps. Will be happy to answer any questions.

name = "nghttp2",
cache_entries = {
"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,
)
Copy link
Member Author

Choose a reason for hiding this comment

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

We should add some more of the cmake deps as well once we have agreement on when we will be merging this.

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
)
target_compile_definitions(nghttp2_static PUBLIC "-DNGHTTP2_STATICLIB")
if(ENABLE_STATIC_LIB)
30 changes: 0 additions & 30 deletions bazel/patched_http_archive.bzl

This file was deleted.

46 changes: 45 additions & 1 deletion bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ load(
"git_repository",
"new_git_repository",
)
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load(":genrule_repository.bzl", "genrule_repository")
load(":patched_http_archive.bzl", "patched_http_archive")
load(":repository_locations.bzl", "REPOSITORY_LOCATIONS")
load(":target_recipes.bzl", "TARGET_RECIPES")
load(
Expand All @@ -17,6 +17,10 @@ load("@bazel_tools//tools/cpp:lib_cc_configure.bzl", "get_env_var")
# dict of {build recipe name: longform extension name,}
PPC_SKIP_TARGETS = {"luajit": "envoy.filters.http.lua"}

# 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 @@ -278,13 +282,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 @@ -296,6 +304,7 @@ def envoy_dependencies(path = "@envoy_deps//", skip_targets = []):
_com_github_grpc_grpc()
_com_github_google_jwt_verify()
_com_github_nanopb_nanopb()
_com_github_nghttp2_nghttp2()
_com_github_nodejs_http_parser()
_com_github_tencent_rapidjson()
_com_google_googletest()
Expand Down Expand Up @@ -336,6 +345,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 @@ -396,6 +417,21 @@ def _com_github_google_libprotobuf_mutator():
actual = "@com_github_google_libprotobuf_mutator//:libprotobuf_mutator",
)

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 @@ -542,6 +578,14 @@ def _com_github_google_jwt_verify():
actual = "@com_github_google_jwt_verify//:jwt_verify_lib",
)

def _foreign_cc_dependencies():
http_archive(
name = "rules_foreign_cc",
strip_prefix = "rules_foreign_cc-master",
# TODO(htuch): Pin to SHA or release.
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/master.zip",
)

def _apply_dep_blacklist(ctxt, recipes):
newlist = []
skip_list = dict()
Expand Down
10 changes: 10 additions & 0 deletions bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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 = "62dd12f0557918f89ad6f5b759f0bf4727174ae9979499f5452c02be38d9d3e8",
strip_prefix = "c-ares-cares-1_14_0",
urls = ["https://github.com/c-ares/c-ares/archive/cares-1_14_0.tar.gz"],
),
com_github_circonus_labs_libcircllhist = dict(
commit = "050da53a44dede7bda136b93a9aeef47bd91fa12", # 2018-07-02
remote = "https://github.com/circonus-labs/libcircllhist",
Expand Down Expand Up @@ -62,6 +67,11 @@ REPOSITORY_LOCATIONS = dict(
strip_prefix = "nanopb-f8ac463766281625ad710900479130c7fcb4d63b",
urls = ["https://github.com/nanopb/nanopb/archive/f8ac463766281625ad710900479130c7fcb4d63b.tar.gz"],
),
com_github_nghttp2_nghttp2 = dict(
sha256 = "42fff7f290100c02234ac3b0095852e4392e6bfd95ebed900ca8bd630850d88c",
strip_prefix = "nghttp2-1.33.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

@htuch nghttp2 version 1.35.0 is out if you would like to bump to that version. Master is currently set at 1.34.0
SHA256 for 1.35.0 is ea04e4e749df13d60a88b706752e04f6f907227bf380aefd7aeeb4aa0db43407

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, thanks, already bumped the versions.

urls = ["https://github.com/nghttp2/nghttp2/releases/download/v1.33.0/nghttp2-1.33.0.tar.gz"],
),
io_opentracing_cpp = dict(
sha256 = "4455ca507936bc4b658ded10a90d8ebbbd61c58f06207be565a4ffdc885687b5",
strip_prefix = "opentracing-cpp-1.5.0",
Expand Down
2 changes: 0 additions & 2 deletions bazel/target_recipes.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
# 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",
}
3 changes: 3 additions & 0 deletions ci/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ local_repository(
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
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
42 changes: 0 additions & 42 deletions ci/build_container/build_recipes/cares.sh

This file was deleted.

47 changes: 0 additions & 47 deletions ci/build_container/build_recipes/nghttp2.sh

This file was deleted.

20 changes: 0 additions & 20 deletions ci/prebuilt/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ config_setting(
values = {"cpu": "x64_windows"},
)

cc_library(
name = "ares",
srcs = select({
":windows_x86_64": ["thirdparty_build/lib/cares.lib"],
"//conditions:default": ["thirdparty_build/lib/libcares.a"],
}),
hdrs = glob(["thirdparty_build/include/ares*.h"]),
includes = ["thirdparty_build/include"],
)

cc_library(
name = "benchmark",
srcs = select({
Expand Down Expand Up @@ -49,16 +39,6 @@ cc_library(
# the headers get included using -I vs. -isystem which then causes old-style-cast warnings.
)

cc_library(
name = "nghttp2",
srcs = select({
":windows_x86_64": ["thirdparty_build/lib/nghttp2.lib"],
"//conditions:default": ["thirdparty_build/lib/libnghttp2.a"],
}),
hdrs = glob(["thirdparty_build/include/nghttp2/**/*.h"]),
includes = ["thirdparty_build/include"],
)

cc_library(
name = "tcmalloc_and_profiler",
srcs = ["thirdparty_build/lib/libtcmalloc_and_profiler.a"],
Expand Down
Loading