Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bazel: update rules_foreign_cc #18174

Merged
merged 1 commit into from
Sep 23, 2021
Merged
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
2 changes: 1 addition & 1 deletion bazel/EXTERNAL_DEPS.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ The name of the dependency can be found in
[the repository locations file.](https://github.com/envoyproxy/envoy/blob/main/bazel/repository_locations.bzl)
The path of the local copy has to be absolute path.

For repositories built by `envoy_cmake_external()` in `bazel/foreign_cc/BUILD`,
For repositories built by `envoy_cmake()` in `bazel/foreign_cc/BUILD`,
it is necessary to populate the local copy with some additional Bazel machinery
to support `--override_repository`:
1. Place an empty `WORKSPACE` in the root.
Expand Down
5 changes: 3 additions & 2 deletions bazel/dependency_imports.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@rules_foreign_cc//:workspace_definitions.bzl", "rules_foreign_cc_dependencies")
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@envoy_build_tools//toolchains:rbe_toolchains_config.bzl", "rbe_toolchains_config")
load("@bazel_toolchains//rules/exec_properties:exec_properties.bzl", "create_rbe_exec_properties_dict", "custom_exec_properties")
Expand All @@ -14,7 +14,8 @@ load("@proxy_wasm_rust_sdk//bazel:dependencies.bzl", "proxy_wasm_rust_sdk_depend
GO_VERSION = "1.15.5"

def envoy_dependency_imports(go_version = GO_VERSION):
rules_foreign_cc_dependencies()
# TODO: allow building of tools for easier onboarding
rules_foreign_cc_dependencies(register_default_tools = False, register_built_tools = False)
go_rules_dependencies()
go_register_toolchains(go_version)
rbe_toolchains_config()
Expand Down
16 changes: 7 additions & 9 deletions bazel/envoy_build_system.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The main Envoy bazel file. Load this file for all Envoy-specific build macros
# and rules that you'd like to use in your BUILD files.
load("@rules_foreign_cc//tools/build_defs:cmake.bzl", "cmake_external")
load("@rules_foreign_cc//foreign_cc:cmake.bzl", "cmake")
load(":envoy_binary.bzl", _envoy_cc_binary = "envoy_cc_binary")
load(":envoy_internal.bzl", "envoy_external_dep_path")
load(
Expand Down Expand Up @@ -92,15 +92,12 @@ envoy_directory_genrule = rule(

# External CMake C++ library targets should be specified with this function. This defaults
# to building the dependencies with ninja
def envoy_cmake_external(
def envoy_cmake(
name,
cache_entries = {},
debug_cache_entries = {},
cmake_options = ["-GNinja"],
make_commands = ["ninja -v", "ninja -v install"],
lib_source = "",
postfix_script = "",
static_libraries = [],
copy_pdb = False,
pdb_name = "",
cmake_files_dir = "$BUILD_TMPDIR/CMakeFiles",
Expand Down Expand Up @@ -128,22 +125,23 @@ def envoy_cmake_external(
else:
pf = postfix_script

cmake_external(
cmake(
name = name,
cache_entries = select({
"@envoy//bazel:dbg_build": cache_entries_debug,
"//conditions:default": cache_entries,
}),
cmake_options = cmake_options,
generate_args = ["-GNinja"],
targets = ["", "install"],
# TODO: Remove install target and make this work
install = False,
# TODO(lizan): Make this always true
generate_crosstool_file = select({
"@envoy//bazel:windows_x86_64": True,
"//conditions:default": generate_crosstool_file,
}),
lib_source = lib_source,
make_commands = make_commands,
postfix_script = pf,
static_libraries = static_libraries,
**kwargs
)

Expand Down
79 changes: 40 additions & 39 deletions bazel/foreign_cc/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
load("//bazel:envoy_build_system.bzl", "envoy_cmake_external", "envoy_package")
load("@rules_foreign_cc//tools/build_defs:configure.bzl", "configure_make")
load("//bazel:envoy_build_system.bzl", "envoy_cmake", "envoy_package")
load("@rules_foreign_cc//foreign_cc:configure.bzl", "configure_make")

licenses(["notice"]) # Apache 2

Expand All @@ -20,12 +20,14 @@ configure_make(
}),
lib_source = "@com_github_gperftools_gperftools//:all",
linkopts = ["-lpthread"],
make_commands = ["make install-libLTLIBRARIES install-perftoolsincludeHEADERS"],
static_libraries = select({
out_static_libs = select({
"//bazel:debug_tcmalloc": ["libtcmalloc_debug.a"],
"//conditions:default": ["libtcmalloc_and_profiler.a"],
}),
tags = ["skip_on_windows"],
targets = [
"install-libLTLIBRARIES install-perftoolsincludeHEADERS",
],
)

# Workaround for https://github.com/bazelbuild/rules_foreign_cc/issues/227
Expand All @@ -44,14 +46,14 @@ configure_make(
configure_in_place = True,
configure_options = ["--disable-ssl --disable-gssapi --disable-lz4-ext --disable-zstd && cp Makefile.config src/.. && cp config.h src/.."],
lib_source = "@edenhill_librdkafka//:all",
make_commands = [
"make ARFLAGS='' libs install-subdirs",
],
static_libraries = [
out_static_libs = [
"librdkafka.a",
"librdkafka++.a",
],
tags = ["skip_on_windows"],
targets = [
"ARFLAGS='' libs install-subdirs",
],
alwayslink = True,
)

Expand All @@ -66,7 +68,7 @@ cc_library(
configure_make(
name = "luajit",
configure_command = "build.py",
configure_env_vars = select({
env = select({
# This shouldn't be needed! See
# https://github.com/envoyproxy/envoy/issues/6084
# TODO(htuch): Remove when #6084 is fixed
Expand All @@ -76,18 +78,18 @@ configure_make(
"//conditions:default": {},
}),
lib_source = "@com_github_luajit_luajit//:all",
make_commands = [],
out_include_dir = "include/luajit-2.1",
static_libraries = select({
out_static_libs = select({
"//bazel:windows_x86_64": ["lua51.lib"],
"//conditions:default": ["libluajit-5.1.a"],
}),
targets = [],
)

configure_make(
name = "moonjit",
configure_command = "build.py",
configure_env_vars = select({
env = select({
# This shouldn't be needed! See
# https://github.com/envoyproxy/envoy/issues/6084
# TODO(htuch): Remove when #6084 is fixed
Expand All @@ -96,13 +98,12 @@ configure_make(
"//conditions:default": {},
}),
lib_source = "@com_github_moonjit_moonjit//:all",
make_commands = [],
out_include_dir = "include/moonjit-2.2",
static_libraries = ["libluajit-5.1.a"],
out_static_libs = ["libluajit-5.1.a"],
tags = ["skip_on_windows"],
)

envoy_cmake_external(
envoy_cmake(
name = "libsxg",
cache_entries = {
"CMAKE_BUILD_TYPE": "Release",
Expand All @@ -115,12 +116,12 @@ envoy_cmake_external(
"CMAKE_TRY_COMPILE_TARGET_TYPE": "STATIC_LIBRARY",
},
lib_source = "@com_github_google_libsxg//:all",
static_libraries = ["libsxg.a"],
out_static_libs = ["libsxg.a"],
tags = ["skip_on_windows"],
deps = ["@boringssl//:ssl"],
)

envoy_cmake_external(
envoy_cmake(
name = "ares",
cache_entries = {
"CARES_BUILD_TOOLS": "no",
Expand All @@ -135,17 +136,17 @@ envoy_cmake_external(
"//bazel:apple": ["-lresolv"],
"//conditions:default": [],
}),
postfix_script = select({
"//bazel:windows_x86_64": "cp -L $EXT_BUILD_ROOT/external/com_github_c_ares_c_ares/src/lib/ares_nameser.h $INSTALLDIR/include/ares_nameser.h && cp -L $EXT_BUILD_ROOT/external/com_github_c_ares_c_ares/include/ares_dns.h $INSTALLDIR/include/ares_dns.h",
"//conditions:default": "cp -L $EXT_BUILD_ROOT/external/com_github_c_ares_c_ares/include/ares_dns.h $INSTALLDIR/include/ares_dns.h",
}),
static_libraries = select({
out_static_libs = select({
"//bazel:windows_x86_64": ["cares.lib"],
"//conditions:default": ["libcares.a"],
}),
postfix_script = select({
"//bazel:windows_x86_64": "cp -L $EXT_BUILD_ROOT/external/com_github_c_ares_c_ares/src/lib/ares_nameser.h $INSTALLDIR/include/ares_nameser.h && cp -L $EXT_BUILD_ROOT/external/com_github_c_ares_c_ares/include/ares_dns.h $INSTALLDIR/include/ares_dns.h",
"//conditions:default": "rm -f $INSTALLDIR/include/ares_dns.h && cp -L $EXT_BUILD_ROOT/external/com_github_c_ares_c_ares/include/ares_dns.h $INSTALLDIR/include/ares_dns.h",
}),
)

envoy_cmake_external(
envoy_cmake(
name = "curl",
cache_entries = {
"BUILD_CURL_EXE": "off",
Expand Down Expand Up @@ -186,7 +187,7 @@ envoy_cmake_external(
defines = ["CURL_STATICLIB"],
generate_crosstool_file = True,
lib_source = "@com_github_curl//:all",
static_libraries = select({
out_static_libs = select({
"//bazel:windows_x86_64": ["libcurl.lib"],
"//conditions:default": ["libcurl.a"],
}),
Expand All @@ -198,7 +199,7 @@ envoy_cmake_external(
],
)

envoy_cmake_external(
envoy_cmake(
name = "event",
cache_entries = {
"EVENT__DISABLE_OPENSSL": "on",
Expand All @@ -215,7 +216,7 @@ envoy_cmake_external(
"_GNU_SOURCE": "on",
},
lib_source = "@com_github_libevent_libevent//:all",
static_libraries = select({
out_static_libs = select({
# macOS organization of libevent is different from Windows/Linux.
# Including libevent_core is a requirement on those platforms, but
# results in duplicate symbols when built on macOS.
Expand All @@ -236,7 +237,7 @@ envoy_cmake_external(
}),
)

envoy_cmake_external(
envoy_cmake(
name = "llvm",
cache_entries = {
# Disable both: BUILD and INCLUDE, since some of the INCLUDE
Expand Down Expand Up @@ -267,15 +268,15 @@ envoy_cmake_external(
# using -l:libstdc++.a.
"CMAKE_CXX_FLAGS": "-lstdc++",
},
env_vars = {
env = {
# Workaround for the -DDEBUG flag added in fastbuild on macOS,
# which conflicts with DEBUG macro used in LLVM.
"CFLAGS": "-UDEBUG",
"CXXFLAGS": "-UDEBUG",
"ASMFLAGS": "-UDEBUG",
},
lib_source = "@org_llvm_llvm//:all",
static_libraries = select({
out_static_libs = select({
"//conditions:default": [
# Order from llvm-config --libnames asmparser core debuginfodwarf
# engine lto mcparser mirparser orcjit passes runtimedyld
Expand Down Expand Up @@ -336,7 +337,7 @@ envoy_cmake_external(
alwayslink = True,
)

envoy_cmake_external(
envoy_cmake(
name = "nghttp2",
cache_entries = {
"ENABLE_LIB_ONLY": "on",
Expand All @@ -349,13 +350,13 @@ envoy_cmake_external(
debug_cache_entries = {"ENABLE_DEBUG": "on"},
defines = ["NGHTTP2_STATICLIB"],
lib_source = "@com_github_nghttp2_nghttp2//:all",
static_libraries = select({
out_static_libs = select({
"//bazel:windows_x86_64": ["nghttp2.lib"],
"//conditions:default": ["libnghttp2.a"],
}),
)

envoy_cmake_external(
envoy_cmake(
name = "wamr",
cache_entries = {
"LLVM_DIR": "$EXT_BUILD_DEPS/copy_llvm/llvm/lib/cmake/llvm",
Expand All @@ -368,14 +369,13 @@ envoy_cmake_external(
"WAMR_BUILD_TAIL_CALL": "1",
},
lib_source = "@com_github_wamr//:all",
static_libraries = ["libvmlib.a"],
out_static_libs = ["libvmlib.a"],
tags = ["skip_on_windows"],
deps = [":llvm"],
)

envoy_cmake_external(
envoy_cmake(
name = "wavm",
binaries = ["wavm"],
cache_entries = {
"LLVM_DIR": "$EXT_BUILD_DEPS/copy_llvm/llvm/lib/cmake/llvm",
"WAVM_ENABLE_STATIC_LINKING": "on",
Expand All @@ -385,15 +385,16 @@ envoy_cmake_external(
# using -l:libstdc++.a.
"CMAKE_CXX_FLAGS": "-lstdc++ -Wno-unused-command-line-argument",
},
env_vars = {
env = {
# Workaround for the -DDEBUG flag added in fastbuild on macOS,
# which conflicts with DEBUG macro used in LLVM.
"CFLAGS": "-UDEBUG",
"CXXFLAGS": "-UDEBUG",
"ASMFLAGS": "-UDEBUG",
},
lib_source = "@com_github_wavm_wavm//:all",
static_libraries = select({
out_binaries = ["wavm"],
out_static_libs = select({
"//conditions:default": [
"libWAVM.a",
"libWAVMUnwind.a",
Expand All @@ -403,7 +404,7 @@ envoy_cmake_external(
deps = [":llvm"],
)

envoy_cmake_external(
envoy_cmake(
name = "zlib",
cache_entries = {
"CMAKE_CXX_COMPILER_FORCED": "on",
Expand Down Expand Up @@ -436,7 +437,7 @@ envoy_cmake_external(
"//bazel:zlib_ng": "@com_github_zlib_ng_zlib_ng//:all",
"//conditions:default": "@net_zlib//:all",
}),
static_libraries = select({
out_static_libs = select({
"//bazel:windows_x86_64": ["zlib.lib"],
"//conditions:default": ["libz.a"],
}),
Expand Down
8 changes: 4 additions & 4 deletions bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -664,12 +664,12 @@ REPOSITORY_LOCATIONS_SPEC = dict(
project_name = "Rules for using foreign build systems in Bazel",
project_desc = "Rules for using foreign build systems in Bazel",
project_url = "https://github.com/bazelbuild/rules_foreign_cc",
version = "d54c78ab86b40770ee19f0949db9d74a831ab9f0",
sha256 = "e7446144277c9578141821fc91c55a61df7ae01bda890902f7286f5fd2f6ae46",
version = "6c0c2af3d599f4c23117a5e65e811ebab75bb151",
sha256 = "8a438371fa742bbbae8b6d995905280053098c5aac28cd434240cd75bc2415a5",
strip_prefix = "rules_foreign_cc-{version}",
urls = ["https://github.com/bazelbuild/rules_foreign_cc/archive/{version}.tar.gz"],
release_date = "2020-10-26",
use_category = ["build"],
release_date = "2021-09-22",
use_category = ["build", "dataplane_core", "controlplane"],
),
rules_python = dict(
project_name = "Python rules for Bazel",
Expand Down