Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bazel: similar build flags to cmake for corresponding build types (#4… #720

Merged
merged 10 commits into from
Apr 17, 2017

Conversation

htuch
Copy link
Member

@htuch htuch commented Apr 7, 2017

…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

  • 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

…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
@mattklein123
Copy link
Member

ldd bazel-bin/source/exe/envoy-static.stripped
not a dynamic executable

That seems not right, or at least not what I'm used to seeing.

mklein@localhost:~/Source/envoy-private$ ldd build_local/envoy/source/exe/envoy
	linux-vdso.so.1 =>  (0x00007ffe86975000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f81f5b05000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f81f58fd000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f81f55f3000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f81f522a000)
	/lib64/ld-linux-x86-64.so.2 (0x00005582f81a7000)

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).

@htuch
Copy link
Member Author

htuch commented Apr 7, 2017

Yes, I statically linked everything. I'll switch back to what you had before.

@mattklein123
Copy link
Member

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).

@htuch
Copy link
Member Author

htuch commented Apr 11, 2017

Waiting for input on bazelbuild/bazel#2805 for the --build-id link issue.

@@ -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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this default in bazel?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep.

"-std=c++0x",
"-includeprecompiled/precompiled.h",
]
] + select({
"//bazel:opt_build": [],
Copy link
Member

@mattklein123 mattklein123 Apr 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-DNDEBUG? Still need debug symbols?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed it's not used, switching to NDEBUG only.

@htuch
Copy link
Member Author

htuch commented Apr 14, 2017

The --build-id fix is in #767, so we can ship this one once it's approved and tests pass.

@mattklein123
Copy link
Member

What's preventing this from passing tests? build image upgrade?

@htuch
Copy link
Member Author

htuch commented Apr 17, 2017

It wasn't building as the headers included from external deps were subject to the -Wold-style-cast -Wextra treatment. I've changed how they get included so that they are now treated as "system" headers, by using includes rather than strip_include_prefix to reference them in ci/prebuild/BUILD. Will push after validating on all Bazel flows and build types.

@mattklein123 mattklein123 merged commit 7bce1eb into envoyproxy:master Apr 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants