diff --git a/bazel/EXTERNAL_DEPS.md b/bazel/EXTERNAL_DEPS.md index 34fc92b21f123..9820ff4cf993d 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_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. diff --git a/bazel/dependency_imports.bzl b/bazel/dependency_imports.bzl index 7c806b08c98a6..aab2cf5337fa1 100644 --- a/bazel/dependency_imports.bzl +++ b/bazel/dependency_imports.bzl @@ -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") @@ -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() diff --git a/bazel/envoy_build_system.bzl b/bazel/envoy_build_system.bzl index a0463ab770d04..5c4a4f4186fe8 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//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( @@ -87,15 +87,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", @@ -123,22 +120,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 ) diff --git a/bazel/foreign_cc/BUILD b/bazel/foreign_cc/BUILD index b24046ea99c57..152a6b3ea2301 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_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 @@ -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 @@ -40,7 +42,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 @@ -50,18 +52,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 @@ -70,13 +72,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 = "ares", cache_entries = { "CARES_BUILD_TOOLS": "no", @@ -91,17 +92,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/nameser.h $INSTALLDIR/include/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/nameser.h $INSTALLDIR/include/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", @@ -142,7 +143,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"], }), @@ -154,7 +155,7 @@ envoy_cmake_external( ], ) -envoy_cmake_external( +envoy_cmake( name = "event", cache_entries = { "EVENT__DISABLE_OPENSSL": "on", @@ -171,7 +172,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. @@ -192,7 +193,7 @@ envoy_cmake_external( }), ) -envoy_cmake_external( +envoy_cmake( name = "llvm", cache_entries = { # Disable both: BUILD and INCLUDE, since some of the INCLUDE @@ -223,7 +224,7 @@ 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", @@ -231,7 +232,7 @@ envoy_cmake_external( "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 @@ -292,7 +293,7 @@ envoy_cmake_external( alwayslink = True, ) -envoy_cmake_external( +envoy_cmake( name = "nghttp2", cache_entries = { "ENABLE_LIB_ONLY": "on", @@ -305,13 +306,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", @@ -324,14 +325,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", @@ -341,7 +341,7 @@ 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", @@ -349,7 +349,8 @@ envoy_cmake_external( "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", @@ -359,7 +360,7 @@ envoy_cmake_external( deps = [":llvm"], ) -envoy_cmake_external( +envoy_cmake( name = "zlib", cache_entries = { "CMAKE_CXX_COMPILER_FORCED": "on", @@ -392,7 +393,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"], }), diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index a4b339cc7951a..5725cf8d39b7c 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 = "d54c78ab86b40770ee19f0949db9d74a831ab9f0", - sha256 = "e7446144277c9578141821fc91c55a61df7ae01bda890902f7286f5fd2f6ae46", + version = "b51f25ee6289f72031ae203c5c6ad917fbb3d5d1", + sha256 = "313cb2516b3cc041901351da5043414763ac69206ca573ecc3a936978bb11e5b", 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-07-22", + use_category = ["build", "dataplane_core", "controlplane"], ), rules_python = dict( project_name = "Python rules for Bazel",