bazel: similar build flags to cmake for corresponding build types (#4…#720
bazel: similar build flags to cmake for corresponding build types (#4…#720mattklein123 merged 10 commits intoenvoyproxy:masterfrom
Conversation
…voyproxy#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 envoyproxy#415 (comment). 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 envoyproxy#716 to merge, since envoyproxy#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
That seems not right, or at least not what I'm used to seeing. Are you somehow statically linking everything? I've had a lot of issues with full static linking and would prefer we still dynamically link to system libraries (or at least have that option). |
|
Yes, I statically linked everything. I'll switch back to what you had before. |
|
I dropped a note into the build GH issue, but FYI we also need to link in build ID. (This change doesn't need to cover that but since we were discussing parity here I thought i would mention it). |
|
Waiting for input on bazelbuild/bazel#2805 for the |
| ENVOY_COPTS = [ | ||
| # TODO(htuch): Remove this when Bazel bringup is done. | ||
| "-DBAZEL_BRINGUP", | ||
| "-fno-omit-frame-pointer", |
| "-includeprecompiled/precompiled.h", | ||
| ] | ||
| ] + select({ | ||
| "//bazel:opt_build": [], |
There was a problem hiding this comment.
-DNDEBUG? Still need debug symbols?
There was a problem hiding this comment.
Bazel automatically sets NDEBUG in opt, see the output in the above commit messages. We're now actually in a strange situation where Bazel is setting NDEBUG in opt and we set DEBUG in fastbuild/dbg. Shouldn't we just have one define indicating debug and use the negated logic where necessary?
There was a problem hiding this comment.
I think DEBUG is just habit from previous jobs. I don't think we use it anywhere and I agree it's silly. Let's just kill it. Can you grep for it though just to make sure we don't use it anywhere?
There was a problem hiding this comment.
Confirmed it's not used, switching to NDEBUG only.
|
The |
|
What's preventing this from passing tests? build image upgrade? |
|
It wasn't building as the headers included from external deps were subject to the |
…ra etc. applying to external dep headers.
…15).
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
#415 (comment).
Below are the relevant flags (ignoring -include etc.) from the various builds. Lines that begin with
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