Skip to content

Commit

Permalink
build: remove cc_configure and cc_wrapper (#7555)
Browse files Browse the repository at this point in the history
Use BAZEL_LINKLIBS to statically link libstdc++ and libc++, get rid of cc_wrapper. Requires Bazel >= 0.28. Additional compiler options which was in cc_wrapeer moved into envoy_copts with select.

Side effect: static linking libstdc++ applies to all binaries built with the toolchain, so tests are now statically linked with libstdc++.

Risk Level: Med, affecting depending projects
Testing: CI

Signed-off-by: Lizan Zhou <lizan@tetrate.io>
  • Loading branch information
lizan authored and htuch committed Jul 16, 2019
1 parent 79c165f commit 14dd85d
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 248 deletions.
6 changes: 6 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ startup --host_jvm_args=-Xmx512m
build --workspace_status_command=bazel/get_workspace_status
build --experimental_remap_main_repo
build --host_force_python=PY2
build --action_env=BAZEL_LINKLIBS=-l%:libstdc++.a
build --action_env=BAZEL_LINKOPTS=-lm:-static-libgcc

# Basic ASAN/UBSAN that works for gcc
build:asan --action_env=BAZEL_LINKLIBS=
build:asan --action_env=BAZEL_LINKOPTS=-lstdc++:-lm
build:asan --define ENVOY_CONFIG_ASAN=1
build:asan --copt -fsanitize=address,undefined
build:asan --linkopt -fsanitize=address,undefined
Expand Down Expand Up @@ -60,6 +64,8 @@ build:clang-msan --copt -fsanitize-memory-track-origins=2
build:libc++ --action_env=CC
build:libc++ --action_env=CXX
build:libc++ --action_env=CXXFLAGS=-stdlib=libc++
build:libc++ --action_env=BAZEL_CXXOPTS=-stdlib=libc++
build:libc++ --action_env=BAZEL_LINKLIBS=-l%:libc++.a:-l%:libc++abi.a:-lm
build:libc++ --action_env=PATH
build:libc++ --host_linkopt=-fuse-ld=lld
build:libc++ --define force_libcpp=enabled
Expand Down
3 changes: 0 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ load("//bazel:api_repositories.bzl", "envoy_api_dependencies")
envoy_api_dependencies()

load("//bazel:repositories.bzl", "GO_VERSION", "envoy_dependencies")
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("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()
Expand Down
14 changes: 14 additions & 0 deletions bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ config_setting(
values = {"define": "ENVOY_CONFIG_COVERAGE=1"},
)

config_setting(
name = "clang_build",
flag_values = {
"@bazel_tools//tools/cpp:compiler": "clang",
},
)

config_setting(
name = "gcc_build",
flag_values = {
"@bazel_tools//tools/cpp:compiler": "gcc",
},
)

config_setting(
name = "disable_tcmalloc",
values = {"define": "tcmalloc=disabled"},
Expand Down
79 changes: 0 additions & 79 deletions bazel/cc_configure.bzl

This file was deleted.

128 changes: 0 additions & 128 deletions bazel/cc_wrapper.py

This file was deleted.

38 changes: 18 additions & 20 deletions bazel/envoy_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ load(
":envoy_internal.bzl",
"envoy_copts",
"envoy_external_dep_path",
"envoy_static_link_libstdcpp_linkopts",
"tcmalloc_external_dep",
)

Expand Down Expand Up @@ -50,25 +49,24 @@ def _envoy_select_exported_symbols(xs):
# Compute the final linkopts based on various options.
def _envoy_linkopts():
return select({
# The macOS system library transitively links common libraries (e.g., pthread).
"@envoy//bazel:apple": [
# See note here: https://luajit.org/install.html
"-pagezero_size 10000",
"-image_base 100000000",
],
"@envoy//bazel:windows_x86_64": [
"-DEFAULTLIB:advapi32.lib",
"-DEFAULTLIB:ws2_32.lib",
"-WX",
],
"//conditions:default": [
"-pthread",
"-lrt",
"-ldl",
"-Wl,--hash-style=gnu",
],
}) + envoy_static_link_libstdcpp_linkopts() + \
_envoy_select_exported_symbols(["-Wl,-E"])
# The macOS system library transitively links common libraries (e.g., pthread).
"@envoy//bazel:apple": [
# See note here: https://luajit.org/install.html
"-pagezero_size 10000",
"-image_base 100000000",
],
"@envoy//bazel:windows_x86_64": [
"-DEFAULTLIB:advapi32.lib",
"-DEFAULTLIB:ws2_32.lib",
"-WX",
],
"//conditions:default": [
"-pthread",
"-lrt",
"-ldl",
"-Wl,--hash-style=gnu",
],
}) + _envoy_select_exported_symbols(["-Wl,-E"])

def _envoy_stamped_deps():
return select({
Expand Down
10 changes: 4 additions & 6 deletions bazel/envoy_internal.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def envoy_copts(repository, test = False):
repository + "//bazel:windows_opt_build": [],
repository + "//bazel:windows_fastbuild_build": [],
repository + "//bazel:windows_dbg_build": [],
}) + select({
repository + "//bazel:clang_build": ["-fno-limit-debug-info", "-Wgnu-conditional-omitted-operand"],
repository + "//bazel:gcc_build": ["-Wno-maybe-uninitialized"],
"//conditions:default": [],
}) + select({
repository + "//bazel:disable_tcmalloc": ["-DABSL_MALLOC_HOOK_MMAP_DISABLE"],
"//conditions:default": ["-DTCMALLOC"],
Expand Down Expand Up @@ -82,12 +86,6 @@ def envoy_select_force_libcpp(if_libcpp, default = None):
"//conditions:default": default or [],
})

def envoy_static_link_libstdcpp_linkopts():
return envoy_select_force_libcpp(
["-stdlib=libc++", "-l:libc++.a", "-l:libc++abi.a", "-static-libgcc"],
["-static-libstdc++", "-static-libgcc"],
)

# Dependencies on tcmalloc_and_profiler should be wrapped with this function.
def tcmalloc_external_dep(repository):
return select({
Expand Down
3 changes: 1 addition & 2 deletions bazel/envoy_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ load(
"envoy_external_dep_path",
"envoy_linkstatic",
"envoy_select_force_libcpp",
"envoy_static_link_libstdcpp_linkopts",
"tcmalloc_external_dep",
)

Expand Down Expand Up @@ -205,7 +204,7 @@ def envoy_cc_test_binary(
envoy_cc_binary(
name,
testonly = 1,
linkopts = _envoy_test_linkopts() + envoy_static_link_libstdcpp_linkopts(),
linkopts = _envoy_test_linkopts(),
**kargs
)

Expand Down
6 changes: 0 additions & 6 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load(":genrule_repository.bzl", "genrule_repository")
load("@envoy_api//bazel:envoy_http_archive.bzl", "envoy_http_archive")
load(":repository_locations.bzl", "REPOSITORY_LOCATIONS")
load(
"@bazel_tools//tools/cpp:windows_cc_configure.bzl",
"find_vc_path",
"setup_vc_env_vars",
)
load("@bazel_tools//tools/cpp:lib_cc_configure.bzl", "get_env_var")
load("@envoy_api//bazel:repositories.bzl", "api_dependencies")

# dict of {build recipe name: longform extension name,}
Expand Down
3 changes: 0 additions & 3 deletions ci/WORKSPACE.filter.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ load("@envoy//bazel:api_repositories.bzl", "envoy_api_dependencies")
envoy_api_dependencies()

load("@envoy//bazel:repositories.bzl", "envoy_dependencies", "GO_VERSION")
load("@envoy//bazel:cc_configure.bzl", "cc_configure")

envoy_dependencies()

# 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("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
go_rules_dependencies()
go_register_toolchains(go_version = GO_VERSION)
Loading

0 comments on commit 14dd85d

Please sign in to comment.