From 7cebb0ecc30863dc88a847ed28affbaf5df53ed8 Mon Sep 17 00:00:00 2001 From: Harvey Tuch Date: Fri, 7 Apr 2017 14:07:41 -0400 Subject: [PATCH 1/7] bazel: similar build flags to cmake for corresponding build types (#415). Bazel has 3 compilation modes out-of-the-box {fastbuild, opt, dbg}, see https://bazel.build/versions/master/docs/bazel-user-manual.html#flag--compilation_mode. The cmake build flags for normal/debug/server_only/asan/coverage are at https://github.com/lyft/envoy/issues/415#issuecomment-292592703. Below are the relevant flags (ignoring -include etc.) from the various builds. Lines that begin with * are those that include additional flags we're injecting. fastbuild: -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++0x' -frandom-seed=... -fPIC *-DBAZEL_BRINGUP -Wall -Wextra -Werror -Wnon-virtual-dtor -Woverloaded-virtual *-Wold-style-cast '-std=c++0x' -includeprecompiled/precompiled.h -DDEBUG -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' dbg: -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g '-std=c++0x' -frandom-seed=... -fPIC *-DBAZEL_BRINGUP -Wall -Wextra -Werror -Wnon-virtual-dtor *-Woverloaded-virtual -Wold-style-cast '-std=c++0x' -includeprecompiled/precompiled.h -ggdb3 -DDEBUG -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' opt: -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG -ffunction-sections -fdata-sections '-std=c++0x' -frandom-seed=... *-DBAZEL_BRINGUP -Wall -Wextra -Werror -Wnon-virtual-dtor *-Woverloaded-virtual -Wold-style-cast '-std=c++0x' -includeprecompiled/precompiled.h -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' This PR requires #716 to merge, since #716 provides some important changes to how the headers are exported from the 3rd party deps to allow -Wextra and -Wold-style-cast to work. I've verified that we now have a 100% static envoy-static build, which ldd tells me is not a dynamic binary. % bazel build -c opt //source/exe:envoy-static.stripped Target //source/exe:envoy-static.stripped up-to-date: bazel-bin/source/exe/envoy-static.stripped % ldd bazel-bin/source/exe/envoy-static.stripped not a dynamic executable % ls -lh bazel-bin/source/exe/envoy-static.stripped -r-xr-xr-x 1 htuch eng 8.1M Apr 7 15:46 bazel-bin/source/exe/envoy-static.stripped --- bazel/BUILD | 16 ++++++++++++++++ bazel/envoy_build_system.bzl | 20 ++++++++++---------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/bazel/BUILD b/bazel/BUILD index e69de29bb2d1..12d283506483 100644 --- a/bazel/BUILD +++ b/bazel/BUILD @@ -0,0 +1,16 @@ +package(default_visibility = ["//visibility:public"]) + +config_setting( + name = "opt_build", + values = {"compilation_mode": "opt"} +) + +config_setting( + name = "fastbuild_build", + values = {"compilation_mode": "fastbuild"} +) + +config_setting( + name = "dbg_build", + values = {"compilation_mode": "dbg"} +) diff --git a/bazel/envoy_build_system.bzl b/bazel/envoy_build_system.bzl index 6057d86abb83..70b395c66e2a 100644 --- a/bazel/envoy_build_system.bzl +++ b/bazel/envoy_build_system.bzl @@ -3,22 +3,19 @@ load("@protobuf_git//:protobuf.bzl", "cc_proto_library") ENVOY_COPTS = [ # TODO(htuch): Remove this when Bazel bringup is done. "-DBAZEL_BRINGUP", - "-fno-omit-frame-pointer", - # TODO(htuch): Clang wants -ferror-limit, should support both. Commented out for now. - # "-fmax-errors=3", "-Wall", - # TODO(htuch): Figure out why protobuf-3.2.0 causes the CI build to fail - # with this but not the developer-local build. - #"-Wextra", + "-Wextra", "-Werror", "-Wnon-virtual-dtor", "-Woverloaded-virtual", - # TODO(htuch): Figure out how to use this in the presence of headers in - # openssl/tclap which use old style casts. - # "-Wold-style-cast", + "-Wold-style-cast", "-std=c++0x", "-includeprecompiled/precompiled.h", -] +] + select({ + "//bazel:opt_build": [], + "//bazel:fastbuild_build": ["-DDEBUG"], + "//bazel:dbg_build": ["-ggdb3", "-DDEBUG"], +}) # References to Envoy external dependencies should be wrapped with this function. def envoy_external_dep_path(dep): @@ -71,6 +68,9 @@ def envoy_cc_binary(name, linkopts = [ "-pthread", "-lrt", + "-static", + "-static-libstdc++", + "-static-libgcc", ], linkstatic = 1, visibility = visibility, From 2423d5fe1348fefacf047369e5e0e7adedeca73f Mon Sep 17 00:00:00 2001 From: Harvey Tuch Date: Fri, 7 Apr 2017 15:56:51 -0400 Subject: [PATCH 2/7] fix_format --- bazel/BUILD | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bazel/BUILD b/bazel/BUILD index 12d283506483..7ea694a9450f 100644 --- a/bazel/BUILD +++ b/bazel/BUILD @@ -2,15 +2,15 @@ package(default_visibility = ["//visibility:public"]) config_setting( name = "opt_build", - values = {"compilation_mode": "opt"} + values = {"compilation_mode": "opt"}, ) config_setting( name = "fastbuild_build", - values = {"compilation_mode": "fastbuild"} + values = {"compilation_mode": "fastbuild"}, ) config_setting( name = "dbg_build", - values = {"compilation_mode": "dbg"} + values = {"compilation_mode": "dbg"}, ) From 63a3b1c1201e0ce6e1aa28101afd7b8268c3c0bc Mon Sep 17 00:00:00 2001 From: Harvey Tuch Date: Fri, 7 Apr 2017 16:03:42 -0400 Subject: [PATCH 3/7] Don't statically link system libraries. --- bazel/envoy_build_system.bzl | 1 - 1 file changed, 1 deletion(-) diff --git a/bazel/envoy_build_system.bzl b/bazel/envoy_build_system.bzl index 70b395c66e2a..9047285828b3 100644 --- a/bazel/envoy_build_system.bzl +++ b/bazel/envoy_build_system.bzl @@ -68,7 +68,6 @@ def envoy_cc_binary(name, linkopts = [ "-pthread", "-lrt", - "-static", "-static-libstdc++", "-static-libgcc", ], From b55e52485ad9cdae7d8617d40511414202cd8e51 Mon Sep 17 00:00:00 2001 From: Harvey Tuch Date: Tue, 11 Apr 2017 16:52:54 -0400 Subject: [PATCH 4/7] Bump hash for CI image. --- ci/ci_steps.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/ci_steps.sh b/ci/ci_steps.sh index c66e2ca42009..d1803d3e0ae7 100755 --- a/ci/ci_steps.sh +++ b/ci/ci_steps.sh @@ -1,5 +1,5 @@ #!/bin/bash -ENVOY_BUILD_SHA=b05ce8efcc0ba7957ad6724da83b1ae2abee4600 +ENVOY_BUILD_SHA=3d878d55e05a554514305f26101bd6ad15a4a602 # Script that lists all the steps take by the CI system when doing Envoy builds. set -e From b28d32e5e402b0b69cb8f42562ff71d70ac997d4 Mon Sep 17 00:00:00 2001 From: Harvey Tuch Date: Mon, 17 Apr 2017 09:34:31 -0400 Subject: [PATCH 5/7] Remove DEBUG for fastbuild/dbg in favor of NDEBUG on opt. --- bazel/envoy_build_system.bzl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bazel/envoy_build_system.bzl b/bazel/envoy_build_system.bzl index db7d2443c6e1..29109afe8536 100644 --- a/bazel/envoy_build_system.bzl +++ b/bazel/envoy_build_system.bzl @@ -12,9 +12,9 @@ ENVOY_COPTS = [ "-std=c++0x", "-includeprecompiled/precompiled.h", ] + select({ - "//bazel:opt_build": [], - "//bazel:fastbuild_build": ["-DDEBUG"], - "//bazel:dbg_build": ["-ggdb3", "-DDEBUG"], + "//bazel:opt_build": [], # Bazel adds an implicit -DNDEBUG. + "//bazel:fastbuild_build": [], + "//bazel:dbg_build": ["-ggdb3"], }) # References to Envoy external dependencies should be wrapped with this function. From 619dd3c41a30af24645f7e4def56c7781ba7ef67 Mon Sep 17 00:00:00 2001 From: Harvey Tuch Date: Mon, 17 Apr 2017 09:44:50 -0400 Subject: [PATCH 6/7] s/strip_include_prefix/includes/g in ci/prebuilt/BUILD to avoid -Wextra etc. applying to external dep headers. --- ci/prebuilt/BUILD | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/ci/prebuilt/BUILD b/ci/prebuilt/BUILD index 52a61c12877d..1fae694e0967 100644 --- a/ci/prebuilt/BUILD +++ b/ci/prebuilt/BUILD @@ -4,21 +4,21 @@ cc_library( name = "ares", srcs = ["thirdparty_build/lib/libcares.a"], hdrs = glob(["thirdparty_build/include/ares*.h"]), - strip_include_prefix = "thirdparty_build/include", + includes = ["thirdparty_build/include"], ) cc_library( name = "crypto", srcs = ["thirdparty_build/lib/libcrypto.a"], hdrs = glob(["thirdparty_build/include/openssl/**/*.h"]), - strip_include_prefix = "thirdparty_build/include", + includes = ["thirdparty_build/include"], ) cc_library( name = "event", srcs = ["thirdparty_build/lib/libevent.a"], hdrs = glob(["thirdparty_build/include/event2/**/*.h"]), - strip_include_prefix = "thirdparty_build/include", + includes = ["thirdparty_build/include"], ) cc_library( @@ -37,14 +37,14 @@ cc_library( "thirdparty_build/include/gmock/**/*.h", "thirdparty_build/include/gtest/**/*.h", ]), - strip_include_prefix = "thirdparty_build/include", + includes = ["thirdparty_build/include"], ) cc_library( name = "http_parser", srcs = ["thirdparty_build/lib/libhttp_parser.a"], hdrs = glob(["thirdparty_build/include/http_parser.h"]), - strip_include_prefix = "thirdparty_build/include", + includes = ["thirdparty_build/include"], ) cc_library( @@ -57,7 +57,7 @@ cc_library( "thirdparty_build/include/collector.pb.h", "thirdparty_build/include/lightstep_carrier.pb.h", ], - strip_include_prefix = "thirdparty_build/include", + includes = ["thirdparty_build/include"], deps = [":protobuf"], ) @@ -65,14 +65,14 @@ cc_library( name = "nghttp2", srcs = ["thirdparty_build/lib/libnghttp2.a"], hdrs = glob(["thirdparty_build/include/nghttp2/**/*.h"]), - strip_include_prefix = "thirdparty_build/include", + includes = ["thirdparty_build/include"], ) cc_library( name = "protobuf", srcs = glob(["thirdparty_build/lib/libproto*.a"]), hdrs = glob(["thirdparty_build/include/google/protobuf/**/*.h"]), - strip_include_prefix = "thirdparty_build/include", + includes = ["thirdparty_build/include"], ) filegroup( @@ -83,7 +83,7 @@ filegroup( cc_library( name = "rapidjson", hdrs = glob(["thirdparty/rapidjson-1.1.0/include/**/*.h"]), - strip_include_prefix = "thirdparty/rapidjson-1.1.0/include", + includes = ["thirdparty/rapidjson-1.1.0/include"], ) cc_library( @@ -92,7 +92,7 @@ cc_library( "thirdparty/spdlog-0.11.0/include/**/*.cc", "thirdparty/spdlog-0.11.0/include/**/*.h", ]), - strip_include_prefix = "thirdparty/spdlog-0.11.0/include", + includes = ["thirdparty/spdlog-0.11.0/include"], ) cc_library( @@ -104,5 +104,5 @@ cc_library( cc_library( name = "tclap", hdrs = glob(["thirdparty/tclap-1.2.1/include/**/*.h"]), - strip_include_prefix = "thirdparty/tclap-1.2.1/include", + includes = ["thirdparty/tclap-1.2.1/include"], ) From e4baffec4f1d3f5d3db1d1053729a040e8c0d8e4 Mon Sep 17 00:00:00 2001 From: Harvey Tuch Date: Mon, 17 Apr 2017 10:24:58 -0400 Subject: [PATCH 7/7] Add --define debug_symbols=yes support. --- bazel/BUILD | 5 +++++ bazel/envoy_build_system.bzl | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/bazel/BUILD b/bazel/BUILD index 404c85cb74a9..8b682d020d17 100644 --- a/bazel/BUILD +++ b/bazel/BUILD @@ -16,3 +16,8 @@ config_setting( name = "dbg_build", values = {"compilation_mode": "dbg"}, ) + +config_setting( + name = "debug_symbols", + values = {"define": "debug_symbols=yes"}, +) diff --git a/bazel/envoy_build_system.bzl b/bazel/envoy_build_system.bzl index 29109afe8536..52326a78a275 100644 --- a/bazel/envoy_build_system.bzl +++ b/bazel/envoy_build_system.bzl @@ -12,9 +12,14 @@ ENVOY_COPTS = [ "-std=c++0x", "-includeprecompiled/precompiled.h", ] + select({ - "//bazel:opt_build": [], # Bazel adds an implicit -DNDEBUG. + # Bazel adds an implicit -DNDEBUG for opt. + "//bazel:opt_build": [], "//bazel:fastbuild_build": [], "//bazel:dbg_build": ["-ggdb3"], +}) + select({ + # Allow debug symbols to be added to opt/fastbuild as well. + "//bazel:debug_symbols": ["-ggdb3"], + "//conditions:default": [], }) # References to Envoy external dependencies should be wrapped with this function.