diff --git a/bazel/EXTERNAL_DEPS.md b/bazel/EXTERNAL_DEPS.md index 9820ff4cf993d..34fc92b21f123 100644 --- a/bazel/EXTERNAL_DEPS.md +++ b/bazel/EXTERNAL_DEPS.md @@ -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()` in `bazel/foreign_cc/BUILD`, +For repositories built by `envoy_cmake_external()` 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. diff --git a/bazel/dependency_imports.bzl b/bazel/dependency_imports.bzl index aab2cf5337fa1..7c806b08c98a6 100644 --- a/bazel/dependency_imports.bzl +++ b/bazel/dependency_imports.bzl @@ -1,4 +1,4 @@ -load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies") +load("@rules_foreign_cc//:workspace_definitions.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") @@ -14,8 +14,7 @@ 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): - # TODO: allow building of tools for easier onboarding - rules_foreign_cc_dependencies(register_default_tools = False, register_built_tools = False) + rules_foreign_cc_dependencies() go_rules_dependencies() go_register_toolchains(go_version) rbe_toolchains_config() diff --git a/bazel/envoy_build_system.bzl b/bazel/envoy_build_system.bzl index c407afff7e0dc..4d671ab9562fa 100644 --- a/bazel/envoy_build_system.bzl +++ b/bazel/envoy_build_system.bzl @@ -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//foreign_cc:cmake.bzl", "cmake") +load("@rules_foreign_cc//tools/build_defs:cmake.bzl", "cmake_external") load(":envoy_binary.bzl", _envoy_cc_binary = "envoy_cc_binary") load(":envoy_internal.bzl", "envoy_external_dep_path") load( @@ -91,12 +91,15 @@ 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( +def envoy_cmake_external( 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", @@ -124,23 +127,22 @@ def envoy_cmake( else: pf = postfix_script - cmake( + cmake_external( name = name, cache_entries = select({ "@envoy//bazel:dbg_build": cache_entries_debug, "//conditions:default": cache_entries, }), - generate_args = ["-GNinja"], - targets = ["", "install"], - # TODO: Remove install target and make this work - install = False, + cmake_options = cmake_options, # 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 ) diff --git a/bazel/foreign_cc/BUILD b/bazel/foreign_cc/BUILD index 6628a61f8274f..0a831d81e2665 100644 --- a/bazel/foreign_cc/BUILD +++ b/bazel/foreign_cc/BUILD @@ -1,6 +1,6 @@ load("@rules_cc//cc:defs.bzl", "cc_library") -load("//bazel:envoy_build_system.bzl", "envoy_cmake", "envoy_package") -load("@rules_foreign_cc//foreign_cc:configure.bzl", "configure_make") +load("//bazel:envoy_build_system.bzl", "envoy_cmake_external", "envoy_package") +load("@rules_foreign_cc//tools/build_defs:configure.bzl", "configure_make") licenses(["notice"]) # Apache 2 @@ -20,14 +20,12 @@ configure_make( }), lib_source = "@com_github_gperftools_gperftools//:all", linkopts = ["-lpthread"], - out_static_libs = select({ + make_commands = ["make install-libLTLIBRARIES install-perftoolsincludeHEADERS"], + static_libraries = 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 @@ -42,7 +40,7 @@ cc_library( configure_make( name = "luajit", configure_command = "build.py", - env = select({ + configure_env_vars = select({ # This shouldn't be needed! See # https://github.com/envoyproxy/envoy/issues/6084 # TODO(htuch): Remove when #6084 is fixed @@ -52,18 +50,18 @@ configure_make( "//conditions:default": {}, }), lib_source = "@com_github_luajit_luajit//:all", + make_commands = [], out_include_dir = "include/luajit-2.1", - out_static_libs = select({ + static_libraries = select({ "//bazel:windows_x86_64": ["lua51.lib"], "//conditions:default": ["libluajit-5.1.a"], }), - targets = [], ) configure_make( name = "moonjit", configure_command = "build.py", - env = select({ + configure_env_vars = select({ # This shouldn't be needed! See # https://github.com/envoyproxy/envoy/issues/6084 # TODO(htuch): Remove when #6084 is fixed @@ -72,12 +70,13 @@ configure_make( "//conditions:default": {}, }), lib_source = "@com_github_moonjit_moonjit//:all", + make_commands = [], out_include_dir = "include/moonjit-2.2", - out_static_libs = ["libluajit-5.1.a"], + static_libraries = ["libluajit-5.1.a"], tags = ["skip_on_windows"], ) -envoy_cmake( +envoy_cmake_external( name = "ares", cache_entries = { "CARES_BUILD_TOOLS": "no", @@ -92,17 +91,17 @@ envoy_cmake( "//bazel:apple": ["-lresolv"], "//conditions:default": [], }), - 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", + "//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({ + "//bazel:windows_x86_64": ["cares.lib"], + "//conditions:default": ["libcares.a"], }), ) -envoy_cmake( +envoy_cmake_external( name = "curl", cache_entries = { "BUILD_CURL_EXE": "off", @@ -143,7 +142,7 @@ envoy_cmake( defines = ["CURL_STATICLIB"], generate_crosstool_file = True, lib_source = "@com_github_curl//:all", - out_static_libs = select({ + static_libraries = select({ "//bazel:windows_x86_64": ["libcurl.lib"], "//conditions:default": ["libcurl.a"], }), @@ -155,7 +154,7 @@ envoy_cmake( ], ) -envoy_cmake( +envoy_cmake_external( name = "event", cache_entries = { "EVENT__DISABLE_OPENSSL": "on", @@ -172,7 +171,7 @@ envoy_cmake( "_GNU_SOURCE": "on", }, lib_source = "@com_github_libevent_libevent//:all", - out_static_libs = select({ + static_libraries = 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. @@ -193,7 +192,7 @@ envoy_cmake( }), ) -envoy_cmake( +envoy_cmake_external( name = "llvm", cache_entries = { # Disable both: BUILD and INCLUDE, since some of the INCLUDE @@ -224,7 +223,7 @@ envoy_cmake( # using -l:libstdc++.a. "CMAKE_CXX_FLAGS": "-lstdc++", }, - env = { + env_vars = { # Workaround for the -DDEBUG flag added in fastbuild on macOS, # which conflicts with DEBUG macro used in LLVM. "CFLAGS": "-UDEBUG", @@ -232,7 +231,7 @@ envoy_cmake( "ASMFLAGS": "-UDEBUG", }, lib_source = "@org_llvm_llvm//:all", - out_static_libs = select({ + static_libraries = select({ "//conditions:default": [ # Order from llvm-config --libnames asmparser core debuginfodwarf # engine lto mcparser mirparser orcjit passes runtimedyld @@ -293,7 +292,7 @@ envoy_cmake( alwayslink = True, ) -envoy_cmake( +envoy_cmake_external( name = "nghttp2", cache_entries = { "ENABLE_LIB_ONLY": "on", @@ -306,13 +305,13 @@ envoy_cmake( debug_cache_entries = {"ENABLE_DEBUG": "on"}, defines = ["NGHTTP2_STATICLIB"], lib_source = "@com_github_nghttp2_nghttp2//:all", - out_static_libs = select({ + static_libraries = select({ "//bazel:windows_x86_64": ["nghttp2.lib"], "//conditions:default": ["libnghttp2.a"], }), ) -envoy_cmake( +envoy_cmake_external( name = "wamr", cache_entries = { "LLVM_DIR": "$EXT_BUILD_DEPS/copy_llvm/llvm/lib/cmake/llvm", @@ -325,13 +324,14 @@ envoy_cmake( "WAMR_BUILD_TAIL_CALL": "1", }, lib_source = "@com_github_wamr//:all", - out_static_libs = ["libvmlib.a"], + static_libraries = ["libvmlib.a"], tags = ["skip_on_windows"], deps = [":llvm"], ) -envoy_cmake( +envoy_cmake_external( name = "wavm", + binaries = ["wavm"], cache_entries = { "LLVM_DIR": "$EXT_BUILD_DEPS/copy_llvm/llvm/lib/cmake/llvm", "WAVM_ENABLE_STATIC_LINKING": "on", @@ -341,7 +341,7 @@ envoy_cmake( # using -l:libstdc++.a. "CMAKE_CXX_FLAGS": "-lstdc++ -Wno-unused-command-line-argument", }, - env = { + env_vars = { # Workaround for the -DDEBUG flag added in fastbuild on macOS, # which conflicts with DEBUG macro used in LLVM. "CFLAGS": "-UDEBUG", @@ -349,8 +349,7 @@ envoy_cmake( "ASMFLAGS": "-UDEBUG", }, lib_source = "@com_github_wavm_wavm//:all", - out_binaries = ["wavm"], - out_static_libs = select({ + static_libraries = select({ "//conditions:default": [ "libWAVM.a", "libWAVMUnwind.a", @@ -360,7 +359,7 @@ envoy_cmake( deps = [":llvm"], ) -envoy_cmake( +envoy_cmake_external( name = "zlib", cache_entries = { "CMAKE_CXX_COMPILER_FORCED": "on", @@ -393,7 +392,7 @@ envoy_cmake( "//bazel:zlib_ng": "@com_github_zlib_ng_zlib_ng//:all", "//conditions:default": "@net_zlib//:all", }), - out_static_libs = select({ + static_libraries = select({ "//bazel:windows_x86_64": ["zlib.lib"], "//conditions:default": ["libz.a"], }), diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 8030bdca677ad..ce780b1112bda 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -651,12 +651,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 = "da8952e27c46659866b455de58f5eb3a86185507", - sha256 = "5d1e34fc0f4ab4af0e595ee4d9a03f4127701d95c1d521296bf892b8aff903a2", + version = "d54c78ab86b40770ee19f0949db9d74a831ab9f0", + sha256 = "e7446144277c9578141821fc91c55a61df7ae01bda890902f7286f5fd2f6ae46", strip_prefix = "rules_foreign_cc-{version}", urls = ["https://github.com/bazelbuild/rules_foreign_cc/archive/{version}.tar.gz"], - release_date = "2021-08-21", - use_category = ["build", "dataplane_core", "controlplane"], + release_date = "2020-10-26", + use_category = ["build"], ), rules_python = dict( project_name = "Python rules for Bazel",